129.

previous chapter table of contents next chapter
  

LookupDiscoveryManager

An application (client or service) that wants to use a set of lookup services at fixed, known addresses, and also to use whatever lookup services it can find by multicast, can use the LookupDiscoveryManager utility class. Most of the methods of this class come from its interfaces:

 package net.jini.discovery; public class LookupDiscoveryManager implements DiscoveryManagement,                                                DiscoveryGroupManagement,                                                DiscoveryLocatorManagement {     public LookupDiscoveryManager(String[] groups,                                   LookupLocator[] locators,                                   DiscoveryListener listener)                                       throws IOException; } 

This class differs from LookupDiscovery and LookupLocatorDiscovery in that it insists on a DiscoveryListener in its constructor. Programs using this class can follow the same event model as the last example:

 package discoverymgt; import net.jini.discovery.LookupDiscoveryManager; import net.jini.discovery.DiscoveryGroupManagement; import net.jini.discovery.DiscoveryListener; import net.jini.discovery.DiscoveryEvent; import net.jini.core.lookup.ServiceRegistrar; import net.jini.core.discovery.LookupLocator; import java.net.MalformedURLException; import java.io.IOException; import java.rmi.RemoteException; /**  * AllcastRegister.java  */ public class AllcastRegister implements DiscoveryListener {     static public void main(String argv[]) {         new AllcastRegister();         // stay around long enough to receive replies         try {             Thread.currentThread().sleep(10000L);         } catch(java.lang.InterruptedException e) {             // do nothing         }     }     public AllcastRegister() {         LookupDiscoveryManager discover = null;         LookupLocator[] locators = null;         try {             locators = new LookupLocator[] {new LookupLocator("jini://localhost")};         } catch(MalformedURLException e) {             e.printStackTrace();             System.exit(1);         }         try {             discover = new _ LookupDiscoveryManager(DiscoveryGroupManagement.ALL_GROUPS,                                                   locators,                                                      this);         } catch(IOException e) {             System.err.println(e.toString());             e.printStackTrace();             System.exit(1);         }     }     public void discovered(DiscoveryEvent evt) {         ServiceRegistrar[] registrars = evt.getRegistrars();         for (int n = 0; n < registrars.length; n++) {             ServiceRegistrar registrar = registrars[n];             try {                 System.out.println("found a service locator at " +                                registrar.getLocator().getHost());             } catch(RemoteException e) {                 e.printStackTrace();                 continue;             }             // the code takes separate routes from here for client or service           }     }     public void discarded(DiscoveryEvent evt) {     } } // AllcastRegister 
  


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

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