com.artima.place
Class MulticastDiscoveryLink

java.lang.Object
  |
  +--com.artima.place.MulticastDiscoveryLink
All Implemented Interfaces:
Link, ProgressEventGenerator, java.io.Serializable

public final class MulticastDiscoveryLink
extends java.lang.Object
implements Link, ProgressEventGenerator

A Link that performs queries in lookup services located via multicast discovery.

See Also:
Serialized Form

Constructor Summary
MulticastDiscoveryLink(net.jini.core.lookup.ServiceTemplate template)
          Construct a MulticastDiscoveryLink with the passed ServiceTemplate.
MulticastDiscoveryLink(java.lang.String[] groups, net.jini.core.lookup.ServiceTemplate template)
          Construct a MulticastDiscoveryLink with the passed groups String array and ServiceTemplate.
 
Method Summary
 void addProgressListener(ProgressListener listener)
          Adds the specified ProgressListener to receive progress events from this object.
 boolean equals(java.lang.Object o)
          Two MulticastDiscoveryLinks are equal if they produce the same Jini service item.
 java.lang.String[] getGroups()
          Returns the groups used by this link in performing multicast discovery when activated.
 net.jini.core.lookup.ServiceTemplate getServiceTemplate()
          Returns a duplicate of the ServiceTemplace used in lookups when this link is activated.
 void removeProgressListener(ProgressListener listener)
          Removes the specified ProgressListener so that it no longer receives progress events from this object.
 net.jini.core.lookup.ServiceItem retrieveService()
          Retrieve this service.
 void stopRetrieval()
          Requests a retrieval to stop.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MulticastDiscoveryLink

public MulticastDiscoveryLink(net.jini.core.lookup.ServiceTemplate template)
                       throws java.io.IOException,
                              java.lang.ClassNotFoundException
Construct a MulticastDiscoveryLink with the passed ServiceTemplate.

The activate method will perform multicast discovery of all reachable lookup services, and query each discovered lookup service with the passed ServiceTemplate.

Parameters:
template - the ServiceTemplate with which to peform lookups when this link is activated
Throws:
java.io.IOException - if an I/O error occurs when attempting to serialize or deserialize the ServiceTemplate.
java.lang.ClassNotFoundException - if a class can't be found when attempting deserialize the duplicate ServiceTemplate.

MulticastDiscoveryLink

public MulticastDiscoveryLink(java.lang.String[] groups,
                              net.jini.core.lookup.ServiceTemplate template)
                       throws java.io.IOException,
                              java.lang.ClassNotFoundException
Construct a MulticastDiscoveryLink with the passed groups String array and ServiceTemplate.

The activate method will perform multicast discovery, and query each discovered lookup service with the passed ServiceTemplate. Does multicast discovery and lookups. When this link is activated it will just keep trying until either a match is found or the user aborts. If multiple matches are found, a random match is returned.

Parameters:
groups - an array of String group names with which perform multicast discovery when this link is activated.
template - the ServiceTemplate with which to peform lookups when this link is activated
Method Detail

retrieveService

public net.jini.core.lookup.ServiceItem retrieveService()
                                                 throws java.rmi.RemoteException,
                                                        StoppedException
Retrieve this service. The activate method will return promptly, returning a LinkActivation object that enables clients to abort an activation. Invoking activate again while an activation is currently in progress just starts a new activation independent of the already running one.
Specified by:
retrieveService in interface Link
Returns:
the ServiceItem the retrieved service item
Throws:
RemoteException - to indicate a failure in retrieving the service
StoppedException - to indicate that the request was stopped

stopRetrieval

public void stopRetrieval()
Description copied from interface: Link
Requests a retrieval to stop. If the retrieval is still progressing, and has not previously succeeded, failed, or been stopped, then the retrieval will stop. Otherwise, invoking stopRetrival() has no effect. The stopRetrieval() method does not throw an exception to indicate the activation has already succeeded, failed, or been aborted, but returns normally in these cases.
Specified by:
stopRetrieval in interface Link

getServiceTemplate

public net.jini.core.lookup.ServiceTemplate getServiceTemplate()
                                                        throws java.io.IOException,
                                                               java.lang.ClassNotFoundException
Returns a duplicate of the ServiceTemplace used in lookups when this link is activated. The duplicate is created by serializing and then deserializing the actual ServiceTemplate.
Returns:
a duplicate of the ServiceTemplate used by this link when activated
Throws:
java.io.IOException - if an I/O error occurs when attempting to duplicate the ServiceTemplate.
java.lang.ClassNotFoundException - if a class can't be found when attempting deserialize the duplicate ServiceTemplate.

getGroups

public java.lang.String[] getGroups()
Returns the groups used by this link in performing multicast discovery when activated. A null return value indicates this link will attempt discovery of all reachable lookup services when activated.
Returns:
the groups used by this link in performing multiat discovery when activated

equals

public boolean equals(java.lang.Object o)
Two MulticastDiscoveryLinks are equal if they produce the same Jini service item. Therefore, two MulticastDiscoveryLink objects, must have semantically identical service templates, and identical sets of lookup groups.
Overrides:
equals in class java.lang.Object

addProgressListener

public void addProgressListener(ProgressListener listener)
Adds the specified ProgressListener to receive progress events from this object. If listener is null, no exception is thrown and no action is performed.
Specified by:
addProgressListener in interface ProgressEventGenerator
Parameters:
listener - the ProgressListener to add

removeProgressListener

public void removeProgressListener(ProgressListener listener)
Removes the specified ProgressListener so that it no longer receives progress events from this object. This method performs no function, nor does it throw an exception, if the listener specified by the argument was not previously added to this object. If listener is null, no exception is thrown and no action is performed.
Specified by:
removeProgressListener in interface ProgressEventGenerator
Parameters:
listener - the ProgressListener to remove