Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
DEPARTMENT OF COMPUTER SCIENCE CONCORDIA UNIVERSITY J i n i Java Intelligence Network Infrastructure by Emil Vassev A Technical Article May 2003 Jini – a technical article by Emil Vassev Table of content 1. What is Jini? ................................................................................................................................................3 2. Jini Architecture ..........................................................................................................................................3 3. Jini service ...................................................................................................................................................4 4. How the services communicate each other? ................................................................................................5 5. RPC and RMI ..............................................................................................................................................5 6. Lookup Service............................................................................................................................................5 7. Discovery, Join and Lookup Protocols........................................................................................................5 7.1. Discovery Process.................................................................................................................................6 7.2. Join Process ..........................................................................................................................................7 7.3. Discovery/Join Process.........................................................................................................................8 7.4. Lookup Process - Finding a Service (by Client) ...................................................................................8 7.5. Service Invocation ................................................................................................................................9 8. Programming Models ..................................................................................................................................9 8.1. Distributed Leasing...............................................................................................................................9 8.2. Distributed Transactions.....................................................................................................................10 8.3. Distributed Events ..............................................................................................................................10 9. Code Examples..........................................................................................................................................10 9.1. Discovery............................................................................................................................................10 9.2. Join .....................................................................................................................................................10 9.3. Lookup................................................................................................................................................11 9. References .................................................................................................................................................12 May 2003 page 2 Jini – a technical article by Emil Vassev 1. What is Jini? Jini is a new distributed computing technology developed by Sun Microsystems. Jini network technology is an open architecture for handling resource components within a network. A resource component here can either mean hardware or software. Generally components are referred as services. A Jini system consists of the following parts: • A set of components that provides an infrastructure for federating (grouping) services in a distributed system; • A programming model that supports and encourages the production of reliable distributed services; • Services that can be made part of a federated Jini system and which offer functionality to any other member of the federation. Jini systems provide mechanisms for service construction, lookup, communication, and use in a distributed system. The crucial requirement for Jini is a network, which is based on TCP/IP. Each component (service) must be uniquely addressable in terms of a valid IP address. Generally, Jini is not restricted to TCP/IP, and that’s why Jini is said to be independent of on-the-wire protocol. But it is currently only available for TCP/IP, due to the use of a Java Virtual Machine (JVM). The architecture of a single Jini system is targeted to the workgroup. 2. Jini Architecture Jini uses couple of internal protocols to perform the registration and use of the Jini enabled devices (Palm Pilot, Cell Phone etc.) or software applications as Jini Services. The registration process is performed by Jini Discovery Service. When a device is plugged into the Jini network the pair discover-join protocols allows a devices/software application to register itself in the network. After being registered, the device places its descriptive information (a copy of its representative object) in a Lookup service. This service contains information about all other registered services in the network. The clients may use the services by calling the Lookup service for discovering the registered services. The devices should embed the necessary Jini (Java) code in order to be plugged into a Jini system. This process is the core of the Jini system. It can be referred to the Discovery-Join-Lookup protocols. May 2003 page 3 Jini – a technical article by Emil Vassev Jini Service Jini Service JINI Lookup Discovery Join JAVA Device Client Soft App Fig.2.1. Jini Architecture 3. Jini service The service is a key concept within the Jini architecture. The Jini’s service is an entity that can be used by a person, a program, or another service. A Jini system consists of services that can be collected together for the performance of a particular task. Jini Service Computation Storage Communication channel Software filter Hardware device Another user Fig.3.1. Jini Services Examples of services: • Devices - printers, displays, or disks; • Software - applications or utilities; • Information - databases and files; • Users of the system. Jini enables services in the network federation. These services use Jini’s infrastructure to make calls to each other, to discover each other, and to announce their presence to other services and users. Services appear programmatically as objects written in Java programming language. A service has an interface that defines the operations that can be requested of that service. May 2003 page 4 Jini – a technical article by Emil Vassev 4. How the services communicate each other? Services in a Jini system communicate each other by using a service protocol, which is a set of interfaces written in the Java programming language. The set of such protocols is open ended. The base Jini system defines a small number of such protocols, which define critical service interactions. 5. RPC and RMI Communication between services can be accomplished by using Java Remote Method Invocation (RMI). RMI is a Java extension to the traditional Remote Procedure Call (RPC) mechanisms. The main idea of RPC is that the user (programmer) calls a procedure or method on a network machine in the same way as a procedure on the local machine. RMI is the Java RPC standard – it uses pure Java interfaces. RMI is quite identical to RPC. The main disadvantage of RMI is that it only works on Java objects. In difference to RPC, RMI allows not only data to be passed from object to object around the network but full objects, including code. RMI provides mechanisms to find, activate, and garbage collect object groups. Also RMI provides built-in security mechanism – preserves the safety of Java runtime. 6. Lookup Service Jini manages and handles different available services by using Lookup Service (LUS). LUS finds and resolves the services. It is the central bootstrapping mechanism for the system and provides the major point of contact between the system and users of the system. Objects in a lookup service may include other lookup services - this provides hierarchical lookup. The Lookup Service is keeping a list of registered services and their capabilities. A client is allowed to inquire LUS for a service with its specific capabilities. A Jini’s Lookup Service implements the following functionality: • Acts as a repository of available services; • Stores service proxies; • Clients download service proxies on demand. A service is added to a lookup service by a pair of protocols called discovery and join. By using the discovery protocol, the service locates an appropriate lookup service, and then it joins it - by using the join protocol. 7. Discovery, Join and Lookup Protocols Jini uses a trio of protocols called discovery, join, and lookup to manage the services in a Jini system. A pair of these protocols—discovery/join—occurs when a device is plugged in. Discovery occurs when a service is looking for a lookup service with which May 2003 page 5 Jini – a technical article by Emil Vassev to register. Join occurs when a service has located a lookup service and wishes to join it. Lookup occurs when a client or user needs to locate and invoke a service described by its interface type (written in Java). Jini Java package provides APIs for these protocols. 7.1. Discovery Process The Jini Discovery Process is a process of finding lookup services. Both Jini services and clients use discovery protocol. It exposes two discovery models: • Multicast discovery for LAN (see Fig.7.1.1.); • Unicast discovery for WAN. LUS Network Service LUS LUS Fig.7.1.1. Discovery Multicast Protocol Scenario (see Fig.7.1.2.): The service provider or service client broadcasts a message all around the network (Internet or LAN), which identifies the service. The message should be delivered to all the lookup services within the net. LUS Proxy Proxy Service Proxy Service Service Client Service Provider Jini Service Fig.7.1.2. Discovery Process for a client – “Service provider seeks a lookup service” May 2003 page 6 Jini – a technical article by Emil Vassev 7.2. Join Process The Jini Join Process is a process of registering a Jini’s service to all of the Lookup Services. A special Proxy Service (see Fig.7.2.1.) acts as a signature for the service to be joined. This Proxy Service consists of service object and service attributes. This service object contains the Java programming language interface for the service including the methods that users and applications will invoke to execute the service, along with any other descriptive attributes: • GUI; • On-the-wire-protocol implementation; • Functionality - methods. Service LUS Jini Proxy Service Service Proxy Service Proxy Proxy Service Proxy Service Service Fig.7.2.1. Proxy Service Scenario (see Fig.7.2.2.): The Jini service registers its Proxy Service with a Lookup Service. The new Jini’s service with its capabilities is exposed by the Lookup Service to the World (the net). LUS Proxy Proxy Service Proxy Service Service Client Service Provider Jini Service Fig.7.2.2. Join Process – “A service provider registers its Proxy Service with the Lookup Service” May 2003 page 7 Jini – a technical article by Emil Vassev 7.3. Discovery/Join Process Discovery/Join is the process of adding a service to a Jini system. Scenario: First, the service provider performs a service Discovery Process (see Fig.7.1.2.). Then, the service provider performs a Join Process (see Fig.7.2.2.). 7.4. Lookup Process - Finding a Service (by Client) To perform this process the clients must be able to find a lookup service, however, a client may delegate the task of finding a lookup service to a third party. The service is now ready to be looked up and used (see Fig.7.4.). Service Scenario: First, the Client looks for the Lookup Services by performing Discovery protocol. The Client locates the desired Jini’s service by type - Java Interface. Next, the Proxy Service object moves from service to client (through LUS). The code needed to use service is dynamically loaded on demand. Service Proxy Jini Client LUS Proxy Proxy Service Proxy Service Service Client Proxy Service Service Provider Jini Service Fig.7.4. Lookup Process Proxy Jini May 2003 page 8 Jini – a technical article by Emil Vassev 7.5. Service Invocation The client invokes the service and interact with it trough the Proxy Service (service object). LUS Proxy Proxy Service Proxy Service Service Client Proxy Service Service Provider Jini Service Fig.7.5. Service Invocation Proxy 8. Programming Models 8.1. Distributed Leasing Access to many of the services in the Jini system environment is lease based. A lease is a grant of guaranteed access over a time period. Each lease is negotiated between the user of the service and the provider of the service as part of the service protocol: • A service is requested for some period; • Access is granted for some period. Leases are either exclusive or non-exclusive. Exclusive leases insure that no one else may take a lease on the resource during the period of the lease. Non-exclusive leases allow multiple users to share a resource. The leases can be: • Cancelled (explicit cleanup); • Renewed (explicit extension); • Allowed to expire (implicit cleanup); • Obtained and manipulated by third parties. May 2003 page 9 Jini – a technical article by Emil Vassev 8.2. Distributed Transactions A series of operations, either within a single service or spread among multiple services, can be wrapped in a transaction. The Jini Transaction interfaces supply a service protocol needed to coordinate a two-phase commit. The Jini transaction model: • Designed for distributed coordination; • Standard two-phase commit; • Lightweight, object oriented; • Compared to Transaction Monitor; • Each participant is responsible for upholding ACID properties (Atomic, Consistency, Isolation, Durability). 8.3. Distributed Events The Jini architecture supports distributed events. An object may allow other objects to register interest in events in the object and receive a notification of the occurrence of such an event. This enables distributed event-driven programming. 9. Code Examples 9.1. Discovery LUS uses RMI to send an object to the Jini service provider. LookupLocator lookup = new LookupLocator (“jinni://localhost”); ServiceRegistrar registrar = lookup.getRegistrar (); 9.2. Join ServiceItem (ServiceID id, Object service, Entry [] attrSets); • id – universal unique identifier (UUID) for registered services (128-bit value). Service IDs are intended to be generated only by the lookup services, not by clients; • service – the object implementing the actual Jini Service; • attrSets – service’s attributes. May 2003 page 10 Jini – a technical article by Emil Vassev ServiceItem serviceItem = new ServiceItem (null, myServer, attr); Registrar.register (serviceItem, Lease.FOREVER); 9.3. Lookup Entry [] aeAttributes = new Entry [1]; AeAttributes [0] = new Name (“Hello World”); ServiceTemplate template = new ServiceTemplate (null, null, aeAttributes); myServerInterface = (MyServerInterface) registrar.lookup(template); May 2003 page 11 Jini – a technical article by Emil Vassev 9. References [1] “Jini Architectural Overview” - 1999 Sun Microsystems, Inc.—Printed in the United States of America. 901 San Antonio Road, Palo Alto, California 94303 U.S.A [2] “Jini Network Technology - An Executive Overview” - 2001 Sun Microsystems, Inc [3] “Jini Network Technology Runtime Environment (“Djinn”)” – 2003, Sang Shin Java™ Technology Evangelist; [email protected] [4] “RMI (Remote Method Invocation)” – 2003, Sang Shin Java™ Technology Evangelist; [email protected] [5] “Java remote method invocation – distributed computing for Java” – 2003 Sun Microsystems, Inc.; Technical article, java.sun.com May 2003 page 12