FileDocCategorySizeDatePackage
ServerListener.javaAPI DocExample3592Thu Mar 16 11:52:44 GMT 2000None

ServerListener

public class ServerListener extends Object implements DiscoveryListener

Fields Summary
private Hashtable
leases
private ServiceItem
item
private static final int
ltime
Constructors Summary
public ServerListener(Object object)

    // 15 Minutes

       
        item = new ServiceItem(null, object, null);
    
Methods Summary
public synchronized voiddiscarded(DiscoveryEvent dev)

        ServiceRegistrar[] lookup = dev.getRegistrars();
        for (int i = 0; i < lookup.length; i++) {
            if (leases.containsKey(lookup[i]) == true) {
                // Remove the registration. If the lookup service comes
                // back later, we'll re-register at that time.
                leases.remove(lookup[i]);
            }
        }
    
public synchronized voiddiscovered(DiscoveryEvent dev)

        ServiceRegistrar[] lookup = dev.getRegistrars();
        // For each discovered service, see if we're already registered.
        // If not, register
        for (int i = 0; i < lookup.length; i++) {
            if (leases.containsKey(lookup[i]) == false) {
                // Not already registered
                try {
                    // Register
                    ServiceRegistration ret = lookup[i].register (item, ltime);
                    // You must assign the serviceID based on what the
                    // lookup service returns
                    if (item.serviceID == null) {
                        item.serviceID = ret.getServiceID();
                    }
                    // Save this registration
                    // Note that we don't actually renew the leases yet
                    leases.put (lookup[i], ret);
                } catch (RemoteException ex) {
                    System.out.println("ServerListener error: " + ex);
                }
            }
            // else we were already registered in this service
        }