previous chapter table of contents next chapter

Jini 1.0 JoinManager

A version of JoinManager was present in Jini 1.0. At that time it was in the com.sun package and not formal specification was given. Classes in the com.sun packages may be changed in later versions of Jini, or may even disappear completely. In moving from Jini 1.0 to Jini 1.1, the Joinmanager classes were specified and moved to a new package. This section describes the old version for those still using Jini 1.0. When possible, such users should switch to Jini 1.1

There are a number of possible constructors for JoinManager . This is the simplest:

 JoinManager(java.lang.Object obj,                      Entry[] attrSets,                      ServiceIDListener callback, LeaseRenewalManager leaseMgr) 

This constructor specifies the service to be manages and its entry attributes. The callback is a listener object that will have its serviceIDNotify() method called when a new locator is discovered . This is usually used to find the value of the ServiceID assigned by a lookup locator to a service. The callback argument can be null if the programmer has not interest in saving the ServiceID . The leaseMgr can also be set to null and will then be created as needed.

This constructor will initiate a search for service locators belonging to the group "public", which is defined by a group value of the empty string"". There is no constant for this, and the locators from Sun do not appear to belong to this group , so most applications will need to follow this up immediately with a call to search for locators belonging to any group:

 JoinManager joinMgr = new JoinManager(obj, null, null, null);          joinMgr.setGroups(LookupDiscovery.ALL_GROUPS); 

The second constuctor is a follows :

 JoinManager(Java.lang.object obj,                      Entry[] attrSets,                     java.lang.String[] groups,                      LookupLocator[] locators,                      ServiceIDLocator callback,                      LeaseRenewalManager leaseMgr) 

This constructor adds groups and locators , which allow multicast searches for locators belonging to certain groups, and also unicast lookups for known locators.

A multicast-only search for any groups would have both additional parameters set to null :

 JoinManager joinMgr = new JoinManager(obj, null,                                                LookupDiscovery.ALL_GROUPS,                                                null, null, null); 

On the other hand, a unicast lookup for a single known site would be done like this:

 LookupLocator[] locators = new LookupLocator[1];          locators[0] new LookupLocator("http://www.all_about_files.com");          JoinManager joinMgr = new JoinManager(obj, null,                                                LookupDiscovery.NO_GROUPS,                                                locators, null, null); 

(This code ignores exception handling.)

For example, uploading the complete service of the complete package could be done as follows:

 package joinmgr;          imoport complete.FileClassifierImpl;          import com.sun.jini.lookup.JoinManager;          import net.jini.core.lookup.ServiceID;          import com.sun.jini.lookup.ServiceIDListener;          import com.sun.jini.lease.LeaseRenewalManager;          import net.jini.discovery.LookupDiscovery;          /**           * FileClassifierServer1_0.java           */          public class FileClassifierServer1_0 implements ServiceIDListener{              public static void main(String argv[]) {                  new FileClassifierServer1_0();                  // stay around long enough to receive replies                  try {                      Thread.currentThread().sleep(1000000L);                  } catch(java.lang.InterruptedException e) {                      // do nothing                  }              }              public FileClassifierServer1_0() {                  JoinManager joinMgr = null;          try {              /* this is one way of doing it              joinMgr = new FileClassifierImpl(),                        null,                        this,                        new LeaseRenewalManager());              joinMgr.setGroups(null);              */              /* here is another */              joinMgr = new JoinManager(new FileClassifierImpl(),                                        null                                        LookupDiscovery.ALL_GROUPS,                                        null,                                        this,                                        new LeaseRenewalManager());          } catch(Exception e) {              e.printStackTrace();              System.exit(1);          }        }        public void serviceIDNotify(ServiceID serviceID) {            System.out.println("got service ID" + serviceID.toString());        }      } // FileClassifierServer1_0 

Getting Information From JoinManager

The JoinManager looks unhelpful in supplying information about the lookup locators it finds. However, this information is available by a slightly circuitious route. A service can register a ServiceIDListener to the JoinManager . This will be invoked whenever a new locator is found by its serviceIDNotify() method. A ServiceID is not particularly useful, so we just ignore it. However, within the serviceIDNotify() method we do know that a new service locator has been found, since that is the only occasion on which it is called.

The complete set of service locators can be found with the JoinManager 's getJoinSet() method, which returns as array of ServiceRegistrar objects. We have met this class before: its getLocator() method will return a LookupLocator , which has information such as the host in getHost() . These classes can be put togehter as follows:

 protected JoinManager joinmgr;                 ...          joinmgr = new JoinManager(service, null,                                    this, new LeaseManager());          ...          public  void serviceIDNotify(ServiceID serviceID){              ServiceRegistrar registers = joinmgr.getJoinSet();              for (int n = 0; < registrar.length; n++) {                  LookupLocator locator = registrars[n].getLocator();                  String hostName = locator.getHost();                  ...              }            } 

If you want to find out which is the latest locator to be found, you will have to cache the previous set and find which is new in the array returned. Each call to getJoinSet() will return a new array.


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