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
}