p2ps.imp.rendezvous
Class PeerConnectionManager

java.lang.Object
  extended byp2ps.imp.rendezvous.PeerConnectionManager
All Implemented Interfaces:
ConnectionListener, ConnectionManager, DiscoveryListener
Direct Known Subclasses:
RendezvousConnectionManager

public class PeerConnectionManager
extends java.lang.Object
implements ConnectionManager, ConnectionListener, DiscoveryListener

A class for managing the connections between a standard peer and rendezvous peers. This class is responsible for creating new connections and ensuring the required connectivity is maintained.

Version:
$Revision: 295 $
Author:
Ian Wang

Field Summary
static int MAX_CONNECTIONS
           
static int PEER
           
static int RENDEZVOUS
           
protected  java.util.Hashtable rendezvousconnect
          a hashtable of rendezvous connection managers keyed by peer id
 
Constructor Summary
protected PeerConnectionManager(int type, Peer peer)
           
  PeerConnectionManager(Peer peer)
           
 
Method Summary
 void advertDiscovered(DiscoveryEvent event)
           
 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 dispose()
          Dispose the connection manager
protected  void forwardAdvert(Advertisement advert)
          Forwards an advertisement to all the rendezvous to which the peer is connected.
protected  void forwardCache(RendezvousConnection connect)
          Forwards the local cache to the specified rendezvous
 java.lang.String[] getConnectedRendezvous()
           
 int getCurrentRendezvousConnections()
           
 RendezvousAdvertisement getRendezvousAdvertisement()
           
 int getRequiredRendezvousConnections()
           
protected  void handleAdvert(Advertisement advert, OutputPipe replypipe)
          Handles an advert as required by the connection manager (e.g.
 void init()
          Initializes the connection manager
 void initConnection(RendezvousAdvertisement advert)
          Initializes a connection to the specified rendezvous
protected  void initNewConnection()
          Tries to establish a new rendezvous connections
 boolean isRendezvousConnectionRequired()
           
 void send(Advertisement advert)
          Send an advertisement to all the rendezvous to which the peer is connected.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PEER

public static final int PEER
See Also:
Constant Field Values

RENDEZVOUS

public static final int RENDEZVOUS
See Also:
Constant Field Values

MAX_CONNECTIONS

public static int MAX_CONNECTIONS

rendezvousconnect

protected java.util.Hashtable rendezvousconnect
a hashtable of rendezvous connection managers keyed by peer id

Constructor Detail

PeerConnectionManager

public PeerConnectionManager(Peer peer)
                      throws java.io.IOException

PeerConnectionManager

protected PeerConnectionManager(int type,
                                Peer peer)
                         throws java.io.IOException
Method Detail

init

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

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

getRendezvousAdvertisement

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

isRendezvousConnectionRequired

public boolean isRendezvousConnectionRequired()
Specified by:
isRendezvousConnectionRequired in interface ConnectionManager
Returns:
true if a new rendezvous connections are required

getRequiredRendezvousConnections

public int getRequiredRendezvousConnections()
Specified by:
getRequiredRendezvousConnections in interface ConnectionManager
Returns:
the desired rendezvous connectivity

getCurrentRendezvousConnections

public int getCurrentRendezvousConnections()
Specified by:
getCurrentRendezvousConnections in interface ConnectionManager
Returns:
the current rendezvous connectivity

getConnectedRendezvous

public java.lang.String[] getConnectedRendezvous()
Specified by:
getConnectedRendezvous in interface ConnectionManager
Returns:
the peer ids for all the connected rendezvous

initConnection

public void initConnection(RendezvousAdvertisement advert)
                    throws InitializationException,
                           java.io.IOException
Initializes a connection to the specified rendezvous

Specified by:
initConnection in interface ConnectionManager
Throws:
InitializationException
java.io.IOException

initNewConnection

protected void initNewConnection()
Tries to establish a new rendezvous connections


send

public void send(Advertisement advert)
          throws java.io.IOException
Send an advertisement to all the rendezvous to which the peer is connected.

Specified by:
send in interface ConnectionManager
Throws:
java.io.IOException

handleAdvert

protected void handleAdvert(Advertisement advert,
                            OutputPipe replypipe)
                     throws java.io.IOException
Handles an advert as required by the connection manager (e.g. add to local cache, answer queries etc.)

Throws:
java.io.IOException

forwardCache

protected void forwardCache(RendezvousConnection connect)
Forwards the local cache to the specified rendezvous


forwardAdvert

protected void forwardAdvert(Advertisement advert)
                      throws java.io.IOException
Forwards an advertisement to all the rendezvous to which the peer is connected.

Throws:
java.io.IOException

advertDiscovered

public void advertDiscovered(DiscoveryEvent event)
Specified by:
advertDiscovered in interface DiscoveryListener

connectionAccepted

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

Specified by:
connectionAccepted in interface ConnectionListener

connectionDeclined

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

Specified by:
connectionDeclined in interface ConnectionListener

connectionFailed

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

Specified by:
connectionFailed in interface ConnectionListener

dispose

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

Specified by:
dispose in interface ConnectionManager