p2ps.imp.rendezvous
Class RendezvousConnectionManager

java.lang.Object
  extended byp2ps.imp.rendezvous.PeerConnectionManager
      extended byp2ps.imp.rendezvous.RendezvousConnectionManager
All Implemented Interfaces:
ConnectionListener, ConnectionManager, DiscoveryListener, EndpointMessageListener, MessageListener

public class RendezvousConnectionManager
extends PeerConnectionManager
implements MessageListener, DiscoveryListener, EndpointMessageListener

A manager class for a rendezvous endpoint. This class accepts/declines rendezvous connections to ensure the desired connectivity is maintained.

Version:
$Revision: 295 $
Author:
Ian Wang

Field Summary
static int MAX_PEER_CONNECTIONS
           
static int MAX_RENDEZVOUS_CONNECTIONS
           
static java.lang.String RENDEZVOUS_SERVICE
           
 
Fields inherited from class p2ps.imp.rendezvous.PeerConnectionManager
MAX_CONNECTIONS, PEER, RENDEZVOUS, rendezvousconnect
 
Constructor Summary
RendezvousConnectionManager(Peer peer)
          Construct a rendezvous connection manager.
RendezvousConnectionManager(Peer peer, java.net.URI[] localuri)
          Construct a rendezvous connection manager with the specified local uri endpoints.
 
Method Summary
 void connectionAccepted(java.lang.String peerid, RendezvousConnection connection)
          Called when a rendezvous connection is accepted
 void connectionDeclined(java.lang.String peerid, RendezvousConnection connection)
          Called when a rendezvous connection is declined
 void connectionFailed(java.lang.String peerid, RendezvousConnection connection)
          Called when a rendezvous connection fails
 void dataMessageReceived(DataMessageEvent event)
          Called when the endpoint receives a data message
 void dispose()
          Dispose the connection manager
protected  void forwardCache(RendezvousConnection connect)
          Forwards the local cache to the specified rendezvous (but only non-queries)
 int getCurrentRendezvousConnections()
           
 RendezvousAdvertisement getRendezvousAdvertisement()
           
 int getRequiredRendezvousConnections()
           
protected  void handleAdvert(Advertisement advert, OutputPipe replypipe)
          Handles an advert by adding it to the local cache.
 void init()
          Initializes the connection manager
protected  boolean isAcceptPeerConnection()
           
protected  boolean isAcceptRendezvousConnection()
           
 boolean isRendezvousConnectionRequired()
           
 void messageReceived(MessageReceivedEvent event)
          Called when a message is received by the pipe
 
Methods inherited from class p2ps.imp.rendezvous.PeerConnectionManager
advertDiscovered, forwardAdvert, getConnectedRendezvous, initConnection, initNewConnection, send
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface p2ps.discovery.DiscoveryListener
advertDiscovered
 

Field Detail

MAX_RENDEZVOUS_CONNECTIONS

public static int MAX_RENDEZVOUS_CONNECTIONS

MAX_PEER_CONNECTIONS

public static int MAX_PEER_CONNECTIONS

RENDEZVOUS_SERVICE

public static final java.lang.String RENDEZVOUS_SERVICE
See Also:
Constant Field Values
Constructor Detail

RendezvousConnectionManager

public RendezvousConnectionManager(Peer peer)
                            throws UnknownSchemeException,
                                   java.io.IOException
Construct a rendezvous connection manager.


RendezvousConnectionManager

public RendezvousConnectionManager(Peer peer,
                                   java.net.URI[] localuri)
                            throws UnknownSchemeException,
                                   java.io.IOException
Construct a rendezvous connection manager with the specified local uri endpoints. If localuri null/empty the default uri are used.

Method Detail

init

public void init()
          throws java.io.IOException
Initializes the connection manager

Specified by:
init in interface ConnectionManager
Overrides:
init in class PeerConnectionManager
Throws:
java.io.IOException

getRendezvousAdvertisement

public RendezvousAdvertisement getRendezvousAdvertisement()
Specified by:
getRendezvousAdvertisement in interface ConnectionManager
Overrides:
getRendezvousAdvertisement in class PeerConnectionManager
Returns:
an advert for the rendezvous service, or null if not a rendezvous

isRendezvousConnectionRequired

public boolean isRendezvousConnectionRequired()
Specified by:
isRendezvousConnectionRequired in interface ConnectionManager
Overrides:
isRendezvousConnectionRequired in class PeerConnectionManager
Returns:
true if a connection should be initialized to the discovered advert

getRequiredRendezvousConnections

public int getRequiredRendezvousConnections()
Specified by:
getRequiredRendezvousConnections in interface ConnectionManager
Overrides:
getRequiredRendezvousConnections in class PeerConnectionManager
Returns:
the desired connectivity

getCurrentRendezvousConnections

public int getCurrentRendezvousConnections()
Specified by:
getCurrentRendezvousConnections in interface ConnectionManager
Overrides:
getCurrentRendezvousConnections in class PeerConnectionManager
Returns:
the desired connectivity

isAcceptPeerConnection

protected boolean isAcceptPeerConnection()
Returns:
true if peer connections should be accepted

isAcceptRendezvousConnection

protected boolean isAcceptRendezvousConnection()
Returns:
true if rendezvous connections should be accepted

handleAdvert

protected void handleAdvert(Advertisement advert,
                            OutputPipe replypipe)
                     throws java.io.IOException
Handles an advert by adding it to the local cache. If the advert is a query then any relevant adverts returned to the querying peer.

Overrides:
handleAdvert in class PeerConnectionManager
Throws:
java.io.IOException

forwardCache

protected void forwardCache(RendezvousConnection connect)
Forwards the local cache to the specified rendezvous (but only non-queries)

Overrides:
forwardCache in class PeerConnectionManager

messageReceived

public void messageReceived(MessageReceivedEvent event)
Called when a message is received by the pipe

Specified by:
messageReceived in interface MessageListener

dataMessageReceived

public void dataMessageReceived(DataMessageEvent event)
Called when the endpoint receives a data message

Specified by:
dataMessageReceived in interface EndpointMessageListener

connectionAccepted

public void connectionAccepted(java.lang.String peerid,
                               RendezvousConnection connection)
Called when a rendezvous connection is accepted

Specified by:
connectionAccepted in interface ConnectionListener
Overrides:
connectionAccepted in class PeerConnectionManager

connectionDeclined

public void connectionDeclined(java.lang.String peerid,
                               RendezvousConnection connection)
Called when a rendezvous connection is declined

Specified by:
connectionDeclined in interface ConnectionListener
Overrides:
connectionDeclined in class PeerConnectionManager

connectionFailed

public void connectionFailed(java.lang.String peerid,
                             RendezvousConnection connection)
Called when a rendezvous connection fails

Specified by:
connectionFailed in interface ConnectionListener
Overrides:
connectionFailed in class PeerConnectionManager

dispose

public void dispose()
Description copied from interface: ConnectionManager
Dispose the connection manager

Specified by:
dispose in interface ConnectionManager
Overrides:
dispose in class PeerConnectionManager