Project JXTA

net.jxta.impl.discovery
Class DiscoveryServiceImpl

java.lang.Object
  extended by net.jxta.impl.discovery.DiscoveryServiceImpl
All Implemented Interfaces:
EventListener, DiscoveryService, Srdi.SrdiInterface, Module, RendezvousListener, QueryHandler, SrdiHandler, Service

public class DiscoveryServiceImpl
extends Object
implements DiscoveryService, QueryHandler, RendezvousListener, SrdiHandler, Srdi.SrdiInterface

This Discovery Service implementation provides a mechanism to discover peers within the horizon of the resolver service. The horizon is normally restricted to the group's boundaries but this is not an absolute requirement. Use of the Resolver service is not an absolute requirement either for a discovery service, but this is what this is part of the platform and default net peer group protocol set, which this code implements.

This implementation uses the standard JXTA Peer Discovery Protocol (PDP).

The DiscoveryService service also provides a way to obtain information from a specified peer and request other peer advertisements, this method is particularly useful in the case of a portal where new relationships may be established starting from a predetermined peer (perhaps described in address book, or through an invitation)

See Also:
DiscoveryService, DiscoveryQueryMsg, DiscoveryQuery, DiscoveryResponseMsg, DiscoveryResponse, ResolverService, JXTA Protocols Specification : Peer Discovery Protocol

Field Summary
protected  Cm cm
          The cache manager we're going to use to cache jxta advertisements
protected static String[] dirname
          adv types
 
Fields inherited from interface net.jxta.discovery.DiscoveryService
ADV, DEFAULT_EXPIRATION, DEFAULT_LIFETIME, GROUP, INFINITE_LIFETIME, NO_EXPIRATION, PEER
 
Fields inherited from interface net.jxta.platform.Module
START_AGAIN_PROGRESS, START_AGAIN_STALLED, START_OK
 
Constructor Summary
DiscoveryServiceImpl()
           
 
Method Summary
 void addDiscoveryListener(DiscoveryListener listener)
          
 void flushAdvertisement(Advertisement adv)
          
 void flushAdvertisements(String id, int type)
          
 long getAdvExpirationTime(Advertisement adv)
          
 long getAdvExpirationTime(ID id, int type)
          
 long getAdvLifeTime(Advertisement adv)
          
 long getAdvLifeTime(ID id, int type)
          
 Advertisement getImplAdvertisement()
          
 Service getInterface()
          
 Enumeration getLocalAdvertisements(int type, String attribute, String value)
          
 int getRemoteAdvertisements(String peer, int type, String attribute, String value, int threshold)
          
 int getRemoteAdvertisements(String peer, int type, String attribute, String value, int threshold, DiscoveryListener listener)
          
 void init(PeerGroup pg, ID assignedID, Advertisement impl)
          
 void messageSendFailed(PeerID peerid, OutgoingMessageEvent e)
          
 int processQuery(ResolverQueryMsg query)
          
 void processResponse(ResolverResponseMsg response)
          
 boolean processSrdi(ResolverSrdiMsg message)
          
 void publish(Advertisement adv)
          
 void publish(Advertisement adv, int type)
          
 void publish(Advertisement adv, int type, long lifetime, long expiration)
          
 void publish(Advertisement adv, long lifetime, long expiration)
          
 void pushEntries(boolean all)
          Pushe SRDI entries.
protected  void pushSrdi(ID peer, int type, boolean all)
          push srdi entries
 void remotePublish(Advertisement adv)
          
 void remotePublish(Advertisement adv, int type)
          
 void remotePublish(Advertisement adv, int type, long timeout)
          
 void remotePublish(Advertisement adv, long timeout)
          
 void remotePublish(String peerid, Advertisement adv)
          
 void remotePublish(String peerid, Advertisement adv, int type)
          
 void remotePublish(String peerid, Advertisement adv, int type, long timeout)
          
 void remotePublish(String peerid, Advertisement adv, long timeout)
          
 boolean removeDiscoveryListener(DiscoveryListener listener)
          
 void rendezvousEvent(RendezvousEvent event)
          
 int startApp(String[] arg)
          
 void stopApp()
           dettach from the resolver
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cm

protected Cm cm
The cache manager we're going to use to cache jxta advertisements


dirname

protected static final String[] dirname
adv types

Constructor Detail

DiscoveryServiceImpl

public DiscoveryServiceImpl()
Method Detail

getInterface

public Service getInterface()

Specified by:
getInterface in interface Service

getImplAdvertisement

public Advertisement getImplAdvertisement()

Specified by:
getImplAdvertisement in interface Service

getRemoteAdvertisements

public int getRemoteAdvertisements(String peer,
                                   int type,
                                   String attribute,
                                   String value,
                                   int threshold)

Specified by:
getRemoteAdvertisements in interface DiscoveryService

getRemoteAdvertisements

public int getRemoteAdvertisements(String peer,
                                   int type,
                                   String attribute,
                                   String value,
                                   int threshold,
                                   DiscoveryListener listener)

Specified by:
getRemoteAdvertisements in interface DiscoveryService

getLocalAdvertisements

public Enumeration getLocalAdvertisements(int type,
                                          String attribute,
                                          String value)
                                   throws IOException

Specified by:
getLocalAdvertisements in interface DiscoveryService
Throws:
IOException

init

public void init(PeerGroup pg,
                 ID assignedID,
                 Advertisement impl)
          throws PeerGroupException

Specified by:
init in interface Module
Throws:
PeerGroupException

startApp

public int startApp(String[] arg)

Specified by:
startApp in interface Module

stopApp

public void stopApp()
dettach from the resolver

Specified by:
stopApp in interface Module

flushAdvertisements

public void flushAdvertisements(String id,
                                int type)
                         throws IOException

Specified by:
flushAdvertisements in interface DiscoveryService
Throws:
IOException

flushAdvertisement

public void flushAdvertisement(Advertisement adv)
                        throws IOException

Specified by:
flushAdvertisement in interface DiscoveryService
Throws:
IOException

publish

public void publish(Advertisement adv,
                    int type)
             throws IOException

Specified by:
publish in interface DiscoveryService
Throws:
IOException

publish

public void publish(Advertisement adv)
             throws IOException

Specified by:
publish in interface DiscoveryService
Throws:
IOException

publish

public void publish(Advertisement adv,
                    long lifetime,
                    long expiration)
             throws IOException

Specified by:
publish in interface DiscoveryService
Throws:
IOException

publish

public void publish(Advertisement adv,
                    int type,
                    long lifetime,
                    long expiration)
             throws IOException

Specified by:
publish in interface DiscoveryService
Throws:
IOException

remotePublish

public void remotePublish(Advertisement adv,
                          int type)

Specified by:
remotePublish in interface DiscoveryService

remotePublish

public void remotePublish(Advertisement adv)

Specified by:
remotePublish in interface DiscoveryService

remotePublish

public void remotePublish(Advertisement adv,
                          int type,
                          long timeout)

Specified by:
remotePublish in interface DiscoveryService

remotePublish

public void remotePublish(Advertisement adv,
                          long timeout)

Specified by:
remotePublish in interface DiscoveryService

remotePublish

public void remotePublish(String peerid,
                          Advertisement adv,
                          int type)

Specified by:
remotePublish in interface DiscoveryService

remotePublish

public void remotePublish(String peerid,
                          Advertisement adv)

Specified by:
remotePublish in interface DiscoveryService

remotePublish

public void remotePublish(String peerid,
                          Advertisement adv,
                          long timeout)

Specified by:
remotePublish in interface DiscoveryService

processResponse

public void processResponse(ResolverResponseMsg response)

Specified by:
processResponse in interface QueryHandler

processQuery

public int processQuery(ResolverQueryMsg query)

Specified by:
processQuery in interface QueryHandler

addDiscoveryListener

public void addDiscoveryListener(DiscoveryListener listener)

Specified by:
addDiscoveryListener in interface DiscoveryService

removeDiscoveryListener

public boolean removeDiscoveryListener(DiscoveryListener listener)

Specified by:
removeDiscoveryListener in interface DiscoveryService

remotePublish

public void remotePublish(String peerid,
                          Advertisement adv,
                          int type,
                          long timeout)

Specified by:
remotePublish in interface DiscoveryService

getAdvExpirationTime

public long getAdvExpirationTime(ID id,
                                 int type)

Specified by:
getAdvExpirationTime in interface DiscoveryService

getAdvLifeTime

public long getAdvLifeTime(ID id,
                           int type)

Specified by:
getAdvLifeTime in interface DiscoveryService

getAdvExpirationTime

public long getAdvExpirationTime(Advertisement adv)

Specified by:
getAdvExpirationTime in interface DiscoveryService

getAdvLifeTime

public long getAdvLifeTime(Advertisement adv)

Specified by:
getAdvLifeTime in interface DiscoveryService

processSrdi

public boolean processSrdi(ResolverSrdiMsg message)

Specified by:
processSrdi in interface SrdiHandler

messageSendFailed

public void messageSendFailed(PeerID peerid,
                              OutgoingMessageEvent e)

Specified by:
messageSendFailed in interface SrdiHandler

pushEntries

public void pushEntries(boolean all)
Pushe SRDI entries.

Specified by:
pushEntries in interface Srdi.SrdiInterface
Parameters:
all - if true then push all entries otherwise just push those which have changed since the last push.

pushSrdi

protected void pushSrdi(ID peer,
                        int type,
                        boolean all)
push srdi entries

Parameters:
all - if true push all entries, otherwise just deltas

rendezvousEvent

public void rendezvousEvent(RendezvousEvent event)

Specified by:
rendezvousEvent in interface RendezvousListener

JXTA J2SE