Project JXTA

net.jxta.impl.rendezvous
Class PeerConnection

java.lang.Object
  extended bynet.jxta.impl.rendezvous.PeerConnection
All Implemented Interfaces:
EventListener, OutgoingMessageEventListener
Direct Known Subclasses:
ClientConnection, RdvConnection

public abstract class PeerConnection
extends Object
implements OutgoingMessageEventListener

Manages a connection with a remote client or a rendezvous peer.


Field Summary
protected  Messenger cachedMessenger
          A cached messenger to be used for sending messages to the remote peer.
protected  boolean connected
          If true then we believe we are still connected to the remote peer.
protected  EndpointService endpoint
           
protected  PeerGroup group
           
protected  long leasedTil
          The absolute time in milliseconds at which we expect this connection to expire unless renewed.
protected  ID peerid
          ID of the remote peer.
protected  String peerName
          Cached name of the peer for display purposes.
 
Constructor Summary
PeerConnection(PeerGroup group, EndpointService endpoint, ID peerid)
          Constructor for the PeerConnection object
 
Method Summary
protected  void connect(long leaseDuration)
          Declare that we are connected for the specified amount of time.
 boolean equals(Object obj)
          

performs PeerID comparison

protected  void finalize()
          

Just in case the code that allocated an instance of this object forgot to do "close".

protected  Messenger getCachedMessenger()
          Deprecated. Prefered style is to pass the connection object around and use the sendMessage method rather than getting the messenger.
protected  Messenger getCachedMessenger(PeerAdvertisement padv)
          Return a messenger suitable for communicating to this peer.
 long getLeaseEnd()
          Time at which the lease will expire in absolute milliseconds.
 ID getPeerID()
          Get the peer id of the peer associated with this connection.
 String getPeerName()
          Get the peer name.
 int hashCode()
          
 boolean isConnected()
          Test if the connection is still active.
 void messageSendFailed(OutgoingMessageEvent event)
          
 void messageSendSucceeded(OutgoingMessageEvent event)
          
 boolean sendMessage(Message msg, String service, String param)
          Send a message to the remote peer.
 void setConnected(boolean isConnected)
          Set the connection state.
protected  void setLease(long leaseDuration)
          Set the lease duration in relative milliseconds.
protected  void setPeerName(String name)
          set the peer name.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

group

protected final PeerGroup group

endpoint

protected final EndpointService endpoint

peerid

protected final ID peerid
ID of the remote peer.


peerName

protected String peerName
Cached name of the peer for display purposes.


connected

protected volatile boolean connected
If true then we believe we are still connected to the remote peer.


leasedTil

protected long leasedTil
The absolute time in milliseconds at which we expect this connection to expire unless renewed.


cachedMessenger

protected Messenger cachedMessenger
A cached messenger to be used for sending messages to the remote peer.

Constructor Detail

PeerConnection

public PeerConnection(PeerGroup group,
                      EndpointService endpoint,
                      ID peerid)
Constructor for the PeerConnection object

Parameters:
group - group context
endpoint - the endpoint service to use for sending messages.
peerid - destination peerid
Method Detail

equals

public boolean equals(Object obj)

performs PeerID comparison


finalize

protected void finalize()
                 throws Throwable

Just in case the code that allocated an instance of this object forgot to do "close".

Throws:
Throwable

hashCode

public int hashCode()


toString

public String toString()


messageSendFailed

public void messageSendFailed(OutgoingMessageEvent event)

Specified by:
messageSendFailed in interface OutgoingMessageEventListener

messageSendSucceeded

public void messageSendSucceeded(OutgoingMessageEvent event)

Specified by:
messageSendSucceeded in interface OutgoingMessageEventListener

getPeerID

public ID getPeerID()
Get the peer id of the peer associated with this connection.

Returns:
The peer id of the connected peer.

getPeerName

public String getPeerName()
Get the peer name. If the symobolic name is available, use it, otherwise returns the peer id.

Returns:
The name of the connected peer.

setPeerName

protected void setPeerName(String name)
set the peer name.

Returns:
The peerName value

setLease

protected void setLease(long leaseDuration)
Set the lease duration in relative milliseconds.

Parameters:
leaseDuration - the lease duration in relative milliseconds.

getLeaseEnd

public long getLeaseEnd()
Time at which the lease will expire in absolute milliseconds.

Returns:
The lease value

connect

protected void connect(long leaseDuration)
Declare that we are connected for the specified amount of time.

Parameters:
leaseDuration - The duration of the lease in relative milliseconds.

isConnected

public boolean isConnected()
Test if the connection is still active.

Returns:
The connected value

setConnected

public void setConnected(boolean isConnected)
Set the connection state. This operation must be idempotent.

Parameters:
isConnected - The new connected state. Be very careful when setting true state without setting a new lease.

getCachedMessenger

protected Messenger getCachedMessenger()
Deprecated. Prefered style is to pass the connection object around and use the sendMessage method rather than getting the messenger.

Return a messenger suitable for communicating to this peer.


getCachedMessenger

protected Messenger getCachedMessenger(PeerAdvertisement padv)
Return a messenger suitable for communicating to this peer.

Parameters:
padv - A peer advertisement which will be used for route hints if a new messenger is needed.

sendMessage

public boolean sendMessage(Message msg,
                           String service,
                           String param)
Send a message to the remote peer.

Parameters:
msg - the message to send.
service - The destination service.
param - Parameters for the destination service.
Returns:
true if the message was queued to be sent, otherwise false. A true result does not mean that the destination peer will receive the message.

JXTA J2SE