1 / 19

Sun’s Jini Lab 1

Sun’s Jini Lab 1. Jini Overview / Main components The lookup service. Summary. What is Jini Overview of Jini Lookup service Services Clients The lookup service Discovery of lookup service Unicast discovery Multicast discovery Starting the lookup service. What is Jini.

darius
Download Presentation

Sun’s Jini Lab 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Sun’s JiniLab 1 Jini Overview / Main components The lookup service

  2. Summary • What is Jini • Overview of Jini • Lookup service • Services • Clients • The lookup service • Discovery of lookup service • Unicast discovery • Multicast discovery • Starting the lookup service

  3. What is Jini • Jini is a technology that enables the building of distributed systems. • A Jini system consists of a number of entities providing their services (hardware or software services) and a number of clients using these services. A service provider can be a client of some other services and vice versa. • Jini at the implementation level is a set of Java APIs that provide the mechanisms to publish, find and using services.

  4. Jini Overview • Three entities are involved in a Jini system: • the lookup service • the service provider and • the client • Lookup Service A service provided by Jini that enables: • Service providers to register services • Clients to locate (and use) services It also provides an event notification mechanism that a client can use in order to be informed when interested services are registered to lookup service

  5. Jini Overview (2) • Service providers • Implement their own services • Discover a lookup service • Register their services to lookup service • Administer their services (release registration of their services) • Clients • Discover a lookup service • Search lookup service for interested services using a service template • Download proxies of services through lookup service • Directly communicate with discovered services through the downloaded proxies

  6. How Jini Works

  7. The Lookup Service • The lookup service implements the ServiceRegistrar interface • The ServiceRegistrar interface includes methods to : • Register new services • Search for services • Register for notification for a certain event

  8. The Lookup Service (2) public interface ServiceRegistrar { ServiceRegistration register(ServiceItem item, long leaseDuration) throws RemoteException; Object lookup(ServiceTemplate tmpl) throws RemoteException; ServiceMatches lookup(ServiceTemplate tmpl, int maxMatches) throws RemoteException; EventRegistration notify(ServiceTemplate tmpl, int transitions, RemoteEventListener listener, MarshalledObject handback, long leaseDuration) throws RemoteException;

  9. The Lookup Service (3) • Maintains a collection of service items • Assigns 128 bit ID to each new service • For each registered service, the lookup service creates and stores an instance of the ServiceItem class public class ServiceItem implements Serializable { public ServiceID serviceID; public Object service; public Entry[] attributeSets; public ServiceItem (ServiceID serviceID, Object service, Entry[] attributeSets) {...} }

  10. Discovery of Lookup Service • Jini supports two mechanisms for discovering a lookup service • Unicast Discovery • Multicast Discovery • Unicast Discovery • Used by service providers and clients • Used to obtain a reference (handle) to the lookup service • In order to use unicast discovery we must know the host name and port information or URL of the machine that the lookup service is running LookupLocator lookupLocator = new LookupLocator(JiniURL); ServiceRegistrar registrar = lookupLocator.getRegistrar();

  11. Discovery of Lookup Service (2) • Multicast Discovery • Used by clients and service providers • Location of Lookup service is not known • Consists of 2 protocols • Multicast Request • Multicast Listener

  12. Discovery of Lookup Service (3) class LookupDiscoveryExample implements DiscoveryListener { LookupDiscovery discovery; ServiceRegistrar[] registrars; LookupDiscoveryExample () { try { discovery=new LookupDiscovery(LookupDiscovery.ALL_GROUPS); discovery.addDiscoveryListener (this); System.out.println("Searching for lookup service..."); }catch (Exception e){ System.out.println ("LookupDiscoveryExample(): " + e); } }

  13. Discovery of Lookup Service (4) public void discovered (DiscoveryEvent evt) { registrars = evt.getRegistrars (); System.out.println ("Lookup services found..."); for (i = 0; i < registrars.length; i++){ System.out.println("registrar="+registrars[i]); } } public void discarded (DiscoveryEvent evt){ registrars = evt.getRegistrars (); System.out.println ("Discarded lookup services:"); for (i = 0; i < registrars.length; i++){ System.out.println ("registrar=" + registrars[i]);} } }

  14. Starting Lookup service • Before starting the lookup service we have to start an HTTP server and the RMI Activation Daemon (rmid). • The HTTP server will be used by service providers and service clients in order to download the proxy classes of the lookup service. • The RMI Activation Daemon is used by lookup service to register itself. This happens because lookup service is an activation process which means that the rmid will start it only when it is requested by some other program. Starting an http server: • You can start any http server. However, for your convenience, jini comes with a simple http server. The http server is implemented by the classes included in the %JINI_HOME%lib\tools.jar. • In order to start the jini http server type: java –jar %JINI_HOME%\lib\tools.jar -port 8081 -dir %JINI_HOME%\lib -verbose

  15. Starting Lookup service (2) • -jar defines the jar to be executed • -port defines the port that the http server listens to(if you don´t define this argument, the server will start on port 8080 by default) • -dir defines the root directory of http server • -verbose tells http server to display details on screen about the requests it receives (this will help us in debugging) Starting the RMID: • In order to start the RMI Activation Daemon, type: rmid -J-Dsun.rmi.activation.execPolicy=none • When rmid starts it creates a log directory under the current directory. Each time you start the rmid remove previously created log directories.

  16. Starting Lookup service (3) Starting lookup service • In order to start the lookup service type: java -Djava.security.policy= %JINI_HOME%\example\lookup\policy.all -jar %JINI_HOME%\lib\reggie.jar http://localhost:8081/reggie-dl.jar %JINI_HOME%\example\lookup\policy.all .\reggie_log public

  17. Starting Lookup service (4) • -Djava.security.policy specifies a security policy file. This policy file will control what the lookup service will be allowed to do on the machine running. Jini ships with two useful policy files, in examples\lookup, called policy and policy.all. Use policy.all file, since it eases development. Note: You should always pass in a fully-qualified path to the security policy file; not a relative one. • -jar specifies the jar package to be executed. Reggie.jar that is defined here is the package implementing the lookup service. • http://localhost:8081/reggie-dl.jar specifies the codebase. The codebase is a URL that tells clients of lookup service where the code they will need, in order to use the service, can be downloaded from. When clients download the serialized proxy object for the lookup service (via the Discovery mechanisms), they will need to be able to download the actual class files that implement this serialized proxy.

  18. Starting Lookup service (5) This is where the codebase comes in--it will be "attached" to the serialized objects, and will tell clients where the code can be downloaded from. • The next argument: %JINI_HOME%\example\lookup\policy.all defines a policy file (use the same as the security file above) • .\reggie_logdefines the location of a directory for holding logging information for lookup service. As lookup service runs, it will periodically save its state into this directory, so that it can recover it later if it is restarted. Here the directory defined is the “reggie_log” which is under the current directory.

  19. Starting Lookup service (5) Note: Each time you start lookup service, be sure that the log directory you define does not contain previously created log files. Otherwise, lookup service will try to recover its state from last execution. • The last argument public defines the groups that lookup service will join. These are simply the names of communities that the lookup service will support. By convention, every network should have a lookup service supporting the "public" Jini community. • You can download JINI v.1.2.1 from here. • Batch files including the above commands can be found here.

More Related