net.jini.discovery
Class LookupDiscovery

java.lang.Object
  |
  +--net.jini.discovery.LookupDiscovery

public final class LookupDiscovery
extends java.lang.Object

This class allows one to find instances of the lookup service that are nearby on the network, using group names. It provides a simple unified front end to the multicast request and announcement protocols.

See Also:
ServiceRegistrar, DiscoveryListener, DiscoveryEvent, DiscoveryPermission

Field Summary
static java.lang.String[] ALL_GROUPS
          Attempt to discover all reachable lookup services.
static java.lang.String[] NO_GROUPS
          Do nothing (halt discovery temporarily).
 
Constructor Summary
LookupDiscovery(java.lang.String[] groups)
          Construct a new lookup discovery object, set to discover the given set of groups.
 
Method Summary
 void addDiscoveryListener(DiscoveryListener l)
          Register a listener as interested in receiving DiscoveryEvent notifications.
 void addGroups(java.lang.String[] newGroups)
          Add a set of groups to the set to be discovered.
 void discard(ServiceRegistrar reg)
          Discard a registrar from the set of registrars already discovered.
 void finalize()
           
 java.lang.String[] getGroups()
          Return the set of group names this LookupDiscovery instance is trying to discover.
 void removeDiscoveryListener(DiscoveryListener l)
          Indicate that a listener is no longer interested in receiving DiscoveryEvent notifications.
 void removeGroups(java.lang.String[] oldGroups)
          Remove a set of groups from the set to be discovered.
 void setGroups(java.lang.String[] newGroups)
          Change the set of groups to be discovered to correspond to the given set.
 void terminate()
          Terminate the discovery process.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_GROUPS

public static final java.lang.String[] NO_GROUPS
Do nothing (halt discovery temporarily).
See Also:
LookupDiscovery(java.lang.String[]), setGroups(java.lang.String[])

ALL_GROUPS

public static final java.lang.String[] ALL_GROUPS
Attempt to discover all reachable lookup services.
See Also:
LookupDiscovery(java.lang.String[]), setGroups(java.lang.String[])
Constructor Detail

LookupDiscovery

public LookupDiscovery(java.lang.String[] groups)
                throws java.io.IOException
Construct a new lookup discovery object, set to discover the given set of groups. The set is represented as an array of strings. This array may be empty, which is taken as the empty set, and discovery is not performed. The reference passed in may be null, which is taken as no set, and in which case discovery of all reachable lookup services is performed. Otherwise, the array contains the names of groups to discover. The caller must have DiscoveryPermission for each group (or for all groups, if the array is null).
Parameters:
groups - the set of group names to discover (null for no set, empty for no discovery)
Throws:
java.io.IOException - an error occurred in starting discovery
See Also:
NO_GROUPS, ALL_GROUPS, setGroups(java.lang.String[]), DiscoveryPermission
Method Detail

addDiscoveryListener

public void addDiscoveryListener(DiscoveryListener l)
Register a listener as interested in receiving DiscoveryEvent notifications.
Parameters:
l - the listener to register
See Also:
DiscoveryEvent

removeDiscoveryListener

public void removeDiscoveryListener(DiscoveryListener l)
Indicate that a listener is no longer interested in receiving DiscoveryEvent notifications.
Parameters:
l - the listener to unregister

discard

public void discard(ServiceRegistrar reg)
Discard a registrar from the set of registrars already discovered. This does not prevent that registrar from being rediscovered; it is intended to be used to clear unreachable entries from the set.

If the registrar has been discovered using this LookupDiscovery object, each listener registered with this object will have its discarded method called with the given registrar as parameter.

Parameters:
reg - the registrar to discard
See Also:
DiscoveryListener.discarded(net.jini.discovery.DiscoveryEvent)

getGroups

public java.lang.String[] getGroups()
Return the set of group names this LookupDiscovery instance is trying to discover. If this method returns the empty array, that value is guaranteed to be referentially equal to LookupDiscovery.NO_GROUPS.
Returns:
the set of groups to be discovered (null for all, empty for no discovery)
See Also:
NO_GROUPS, ALL_GROUPS

setGroups

public void setGroups(java.lang.String[] newGroups)
               throws java.io.IOException
Change the set of groups to be discovered to correspond to the given set. The set is represented as an array of strings. This array may be empty, which is taken as the empty set, and discovery is not performed. The reference passed in may be null, which is taken as no set, and in which case discovery of all reachable lookup services is performed. Otherwise, the array contains the names of groups to discover. The caller must have DiscoveryPermission for each group (or for all groups, if the array is null).
Parameters:
newGroups - the new set of groups to discover (null for all, empty array for no discovery)
Throws:
java.io.IOException - an error occurred when starting multicast discovery
java.lang.IllegalStateException - this method was called after the terminate method was called
See Also:
LookupDiscovery(java.lang.String[]), ALL_GROUPS, NO_GROUPS, DiscoveryPermission

addGroups

public void addGroups(java.lang.String[] newGroups)
               throws java.io.IOException
Add a set of groups to the set to be discovered. The caller must have DiscoveryPermission for each group.
Parameters:
newGroups - the groups to add
Throws:
java.io.IOException - the multicast request protocol failed to start
java.lang.IllegalStateException - this method was called after the terminate method was called
UnsupportedOperationException - there is no set of groups to add to
See Also:
DiscoveryPermission

removeGroups

public void removeGroups(java.lang.String[] oldGroups)
Remove a set of groups from the set to be discovered.
Parameters:
oldGroups - groups to remove
Throws:
java.lang.IllegalStateException - this method was called after the terminate method was called
UnsupportedOperationException - there is no set of groups from which to remove

terminate

public void terminate()
Terminate the discovery process.

finalize

public void finalize()
Overrides:
finalize in class java.lang.Object


Copyright © 1999 Sun Microsystems, Inc. All rights reserved