p2ps.imp.discovery
Class DiscoveryServiceImp

java.lang.Object
  extended byp2ps.imp.discovery.DiscoveryServiceImp
All Implemented Interfaces:
DiscoveryService, DiscoveryServiceInterface, MessageListener

public class DiscoveryServiceImp
extends java.lang.Object
implements DiscoveryService, DiscoveryServiceInterface, MessageListener

An implementation of the discovery service interface.

Version:
$Revision: 295 $
Author:
Ian Wang

Field Summary
 
Fields inherited from interface p2ps.discovery.DiscoveryService
DEFAULT_LIFETIME, DISCOVERY_SERVICE
 
Constructor Summary
DiscoveryServiceImp(Peer peer)
          Constructs a new discovery service for the specified peer.
 
Method Summary
 void addDiscoveryListener(DiscoveryListener listener)
          Adds a listener to be notified when an advert is discovered/published
 void connectionReceived(ConnectionReceivedEvent event)
          Called when a connection is received by an input pipe.
 Advertisement[] getLocalAdvertisements()
           
 java.net.URI[] getReplyURIs()
           
 void init()
          Initialises the discovery service
 void messageReceived(MessageReceivedEvent event)
          Handles a broadcast advert or a query reply
 void notifyListeners(Advertisement advert)
          Notify all the discovery listeners that an advert has been discovered
 void publish(Advertisement advert)
          Publishes an advert using the discovery pipe.
 void publish(Advertisement advert, long lifetime)
          Publishes an advertisement/query using the discovery pipe, with the specified lifetime.
 void removeDiscoveryListener(DiscoveryListener listener)
          Removes a listener from being notified when an advert is discovered/published
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DiscoveryServiceImp

public DiscoveryServiceImp(Peer peer)
Constructs a new discovery service for the specified peer.

Method Detail

init

public void init()
          throws InitializationException,
                 java.io.IOException
Initialises the discovery service

Specified by:
init in interface DiscoveryService
Throws:
InitializationException
java.io.IOException

addDiscoveryListener

public void addDiscoveryListener(DiscoveryListener listener)
Adds a listener to be notified when an advert is discovered/published

Specified by:
addDiscoveryListener in interface DiscoveryService

removeDiscoveryListener

public void removeDiscoveryListener(DiscoveryListener listener)
Removes a listener from being notified when an advert is discovered/published

Specified by:
removeDiscoveryListener in interface DiscoveryService

getReplyURIs

public java.net.URI[] getReplyURIs()
Specified by:
getReplyURIs in interface DiscoveryServiceInterface
Returns:
the URI of the discovery service reply pipe.

getLocalAdvertisements

public Advertisement[] getLocalAdvertisements()
Specified by:
getLocalAdvertisements in interface DiscoveryServiceInterface
Returns:
all the advertisements in the local cache

publish

public void publish(Advertisement advert)
             throws java.io.IOException
Publishes an advert using the discovery pipe.

Specified by:
publish in interface DiscoveryService
Parameters:
advert - the advert/query being published
Throws:
java.io.IOException

publish

public void publish(Advertisement advert,
                    long lifetime)
             throws java.io.IOException
Publishes an advertisement/query using the discovery pipe, with the specified lifetime.

Specified by:
publish in interface DiscoveryService
Parameters:
advert - the advert/query being published
lifetime - the lifetime for the advert in milliseconds
Throws:
java.io.IOException

connectionReceived

public void connectionReceived(ConnectionReceivedEvent event)
Called when a connection is received by an input pipe. Note that this event is only reported by endpoint implementations that received explicit connections.


messageReceived

public void messageReceived(MessageReceivedEvent event)
Handles a broadcast advert or a query reply

Specified by:
messageReceived in interface MessageListener

notifyListeners

public void notifyListeners(Advertisement advert)
Notify all the discovery listeners that an advert has been discovered

Specified by:
notifyListeners in interface DiscoveryServiceInterface