previous chapter table of contents next chapter

Jini 1.1 JoinManager

A service needs to locate lookup services and register the service with them. Locating services can be done using the utility classes from Chapter 10. As each lookup service is discovered , it needs to be registered, and the lease needs to be maintained . The JoinManager class performs all of these tasks . There are two constructors:

 public class Joinmanager {               public Joinmanager (Object obj,                                   Entry[] attrSets,                                   ServiceIDListener callback,                                   DiscoveryManagement discoverMgr, LeaseRenewalManager leaseMgr)                       throws IOException;               public JoinManager(Object obj,                                  Entry[] attrSets,                                  ServiceID serviceID, DiscoveryManagement discoverMgr,                                  LeaseRenewalManager leaseMgr)                       throws IOException; } 

The First constructor is used when the service is new and does not have a service ID. A ServiceIDListener can be added to note and save the ID. The other parameters are for the service and its entry attributes, a DiscoveryManagment object to set groups and unicast locators (typically this will be done using a LookupDiscoveryManager ), and a lease renewal manager.

The following example used the JoinManager class to register a FileClassifierImpl. In the Chapter 9) the server implemented the DiscoveryListener interface in order to be informed when new lookup locators were discovered so that the service could be registered with each of them. If you use a join manager, there is no need for a DiscoveryListener, since the join manager adds itself as a listener and handles the registration with the lookup service.

 package joinmgr; import rmi.FileClassifierImpl; import net.jini.lookup.Joinmanager; import net.jini.core.lookup.ServiceID; import net.jini.discovery.LookupDiscovery; import net.jini.core.lookup.ServiceRegistrar; import java.rmi.RemoteException; import net.jini.lookup.ServiceIDListener; import net.jini.lease.LeaseRenewalManager; import net.jini.discovery.LookupDiscoveryManager; import net.jini.discovery.DiscoveryEvent; import net.jini.discovery.DiscoveryListener; /**  * FileClassifierServer.java  */ public class FileClassifierServer     implements ServiceIDListener {     public static void main(String argv[]) {         new FileClassifierServer();         // stay around forever         Object keepAlive = new Object();         synchronized(keepAlive) {             try {                 keepAlive.wait();             } catch(InterruptedException e) {                 // do nothing             }         }    }    public FileClassifierServer() {            JoinManager joinMgr = null;        try {            LookupDiscoveryManager mgr =                 new LookupDiscoveryManager(LookupDiscovery.ALL_GROUPS,                                           null /* unicast locators */,                                           null /* DiscoveryListener */);            joinmgr = new JoinManager(new FileClassifierImpl(), /* service */ new FileClassifierImpl(), /* service */                                      null /* attr sets */,                                      this /* ServiceIDListener*/,                                      mgr /* DiscoveryManagement */,                                      new LeaseRenewalManager());         } catch(Exception e) {             e.printStackTrace();             System.exit(1);         }      }      public void serviceIDNotify(ServiceID serviceID) {          // called as a ServiceIDListener          // Should save the ID to permanent storage          System.out.println("got service ID " + serviceID.toString());      } } // FileClassifierServer 

There are a number of other methods in JoinManager that allow you to modify the state of a service registration.


A Programmer[ap]s Guide to Jini Technology
A Programmer[ap]s Guide to Jini Technology
ISBN: 1893115801
Year: 2000
Pages: 189

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net