Project JXTA

net.jxta.impl.discovery
Class DiscoveryService

java.lang.Object
  |
  +--net.jxta.impl.discovery.DiscoveryService

public class DiscoveryService
extends java.lang.Object
implements net.jxta.discovery.Discovery, net.jxta.resolver.QueryHandler

DiscoveryService Service provides a mechanism to discover peers within a " Network Peer Group" DiscoveryService is limited to the Network Peer Group region set. jxtaDiscovery also provides a way to connect directly to another peer given a Address and request other peer advertisements, this method is particularly useful in the case of a portal where new relationships may be established, or in the case of connecting to a predetermined peer (perhaps described in address book, or through an invitation)

Since:
1.0

Inner Class Summary
protected  class DiscoveryService.PendingQuery
           
protected  class DiscoveryService.Requester
           
 
Field Summary
protected  Cm cm
           
 
Fields inherited from interface net.jxta.discovery.Discovery
ADV, DEFAULT_EXPIRATION, DEFAULT_LIFETIME, GROUP, PEER
 
Constructor Summary
DiscoveryService()
          Default constructor
 
Method Summary
 void addDiscoveryListener(net.jxta.discovery.DiscoveryListener listener)
          Add a discovery listener
 void flushAdvertisements(java.lang.String id, int type)
          flush cached peer Advertisements.
 net.jxta.document.Advertisement getAdvertisement()
          Returns the advertisement for that service.
 net.jxta.peergroup.PeerGroup getGroup()
          Returns the group to which this service is attached.
 net.jxta.service.Service getInterface()
          Service objects are not manipulated directly to protect usage of the service.
 java.util.Enumeration getLocalAdvertisements(int type, java.lang.String attribute, java.lang.String value)
          Retrieve Stored Advertisements based on the type it returns an enum Advertisement for PEER, and GROUP returns an enum of Advertisement for ADV
 int getRemoteAdvertisements(java.lang.String peer, int type, java.lang.String attribute, java.lang.String value, int threshold)
          Discover peers within a region set by the endpoint
 void init(net.jxta.peergroup.PeerGroup pg, net.jxta.document.Advertisement sadv)
          init is called by PeerGroup to init the Service with endpoint etc.
protected  int next(int bits)
           
 net.jxta.protocol.ResolverResponseMsg processQuery(net.jxta.protocol.ResolverQueryMsg query)
          Handler API method
 void publish(net.jxta.document.Advertisement adv, int type)
          Publish an advertisement This provides a way to advertise Peer/Group Advertisement within the current group.
 void publish(net.jxta.document.Advertisement adv, int type, long timeoutForMe, long timeoutForOthers)
          Publish an advertisement This provides a way to advertise Peer/Group Advertisement within the current group.
 void pushResponse(net.jxta.protocol.ResolverResponseMsg response)
          deal with incoming responses for discovery
 void remotePublish(net.jxta.document.Advertisement adv, int type)
           
 void remotePublish(net.jxta.document.Advertisement adv, int type, long timeout)
           
 boolean removeDiscoveryListener(net.jxta.discovery.DiscoveryListener listener)
          remove a discovery listener
 int startApp(java.lang.String[] arg)
          Supply arguments and starts this service if it hadn't started by itself.
 void stopApp()
          Ask this service to stop.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cm

protected Cm cm
Constructor Detail

DiscoveryService

public DiscoveryService()
Default constructor
Method Detail

startApp

public int startApp(java.lang.String[] arg)
Supply arguments and starts this service if it hadn't started by itself. Currently this service starts by itself and does not expect arguments.
Parameters:
arg - A table of strings arguments.
Returns:
int status indication.

stopApp

public void stopApp()
Ask this service to stop. This request is currently ignored.

getInterface

public net.jxta.service.Service getInterface()
Service objects are not manipulated directly to protect usage of the service. A Service interface is returned to access the service methods.
Returns:
Service public interface of the service
Since:
JXTA 1.0

getAdvertisement

public net.jxta.document.Advertisement getAdvertisement()
Returns the advertisement for that service.
Returns:
Advertisement the advertisement.
Since:
JXTA 1.0

init

public void init(net.jxta.peergroup.PeerGroup pg,
                 net.jxta.document.Advertisement sadv)
          throws net.jxta.exception.PeerGroupException
init is called by PeerGroup to init the Service with endpoint etc.
Parameters:
pg - Peer Group
Throws:
net.jxta.exception.PeerGroupException - throw any exception thrown during obtaining Service

getRemoteAdvertisements

public int getRemoteAdvertisements(java.lang.String peer,
                                   int type,
                                   java.lang.String attribute,
                                   java.lang.String value,
                                   int threshold)
Discover peers within a region set by the endpoint
Specified by:
getRemoteAdvertisements in interface net.jxta.discovery.Discovery
Parameters:
address - Address of a peer, or portal to connect to, if address is null then getPeerAdv "discover" in the region of the group
Returns:
query ID for this discovery query
See Also:
net.jxta.endpoint.Address

getLocalAdvertisements

public java.util.Enumeration getLocalAdvertisements(int type,
                                                    java.lang.String attribute,
                                                    java.lang.String value)
                                             throws java.io.IOException
Retrieve Stored Advertisements based on the type it returns an enum Advertisement for PEER, and GROUP returns an enum of Advertisement for ADV
Specified by:
getLocalAdvertisements in interface net.jxta.discovery.Discovery
Returns:
Enumeration of stored Advertisement
Since:
JXTA 1.0

flushAdvertisements

public void flushAdvertisements(java.lang.String id,
                                int type)
                         throws java.io.IOException
flush cached peer Advertisements.
Specified by:
flushAdvertisements in interface net.jxta.discovery.Discovery

publish

public void publish(net.jxta.document.Advertisement adv,
                    int type)
             throws java.io.IOException
Publish an advertisement This provides a way to advertise Peer/Group Advertisement within the current group. same as above, provided as a convenience
Specified by:
publish in interface net.jxta.discovery.Discovery
Parameters:
doc - StructuredDocument to publish

publish

public void publish(net.jxta.document.Advertisement adv,
                    int type,
                    long timeoutForMe,
                    long timeoutForOthers)
             throws java.io.IOException
Publish an advertisement This provides a way to advertise Peer/Group Advertisement within the current group. same as above, provided as a convenience
Specified by:
publish in interface net.jxta.discovery.Discovery
Parameters:
doc - StructuredDocument to publish
timeout - Time to live

remotePublish

public void remotePublish(net.jxta.document.Advertisement adv,
                          int type)
Specified by:
remotePublish in interface net.jxta.discovery.Discovery

remotePublish

public void remotePublish(net.jxta.document.Advertisement adv,
                          int type,
                          long timeout)
Specified by:
remotePublish in interface net.jxta.discovery.Discovery

getGroup

public net.jxta.peergroup.PeerGroup getGroup()
Returns the group to which this service is attached.
Returns:
PeerGroup the group

pushResponse

public void pushResponse(net.jxta.protocol.ResolverResponseMsg response)
deal with incoming responses for discovery
Specified by:
pushResponse in interface net.jxta.resolver.QueryHandler
Parameters:
response -  

processQuery

public net.jxta.protocol.ResolverResponseMsg processQuery(net.jxta.protocol.ResolverQueryMsg query)
                                                   throws net.jxta.exception.NoResponseException,
                                                          net.jxta.exception.DiscardQueryException,
                                                          java.io.IOException,
                                                          net.jxta.exception.ResendQueryException
Handler API method
Specified by:
processQuery in interface net.jxta.resolver.QueryHandler
Parameters:
query - GenericResolverMsg
Returns:
ResolverResponseMsg response
Throws:
net.jxta.exception.NoResponseException - if no Responses were received

next

protected int next(int bits)

addDiscoveryListener

public void addDiscoveryListener(net.jxta.discovery.DiscoveryListener listener)
Add a discovery listener
Specified by:
addDiscoveryListener in interface net.jxta.discovery.Discovery
Parameters:
DiscoveryListener - listener to receive discovery events

removeDiscoveryListener

public boolean removeDiscoveryListener(net.jxta.discovery.DiscoveryListener listener)
remove a discovery listener
Specified by:
removeDiscoveryListener in interface net.jxta.discovery.Discovery
Parameters:
DiscoveryListener - listener to remove
Returns:
true if the argument was a component of this vector; false otherwise

Project JXTA