net.tomp2p.connection
Class PeerConnection

java.lang.Object
  extended by net.tomp2p.connection.PeerConnection

public class PeerConnection
extends Object

This is a handle for permanent connections. With this class the permanent connection can be reused or closed. The is only 1 connection allowed for a given destination. It is important that before Peer.shutdown, all permanent connections are closed. Otherwise shutdown will block forever and will wait until the permanent connection is closed.

Author:
Thomas Bocek

Constructor Summary
PeerConnection(PeerAddress destination, ConnectionReservation connectionReservation, ChannelCreator channelCreator, int idleTCPMillis)
           
 
Method Summary
 void aquireSingleConnection()
          Acquire one connection.
 void close()
          Closes and releases the connection from the reservation.
 ChannelCreator getChannelCreator()
           
 PeerAddress getDestination()
           
 int getIdleTCPMillis()
           
 boolean isClosed()
           
 void releaseSingleConnection()
          Releases one connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PeerConnection

public PeerConnection(PeerAddress destination,
                      ConnectionReservation connectionReservation,
                      ChannelCreator channelCreator,
                      int idleTCPMillis)
Method Detail

close

public void close()
Closes and releases the connection from the reservation. Closes the connection in the background.


getDestination

public PeerAddress getDestination()
Returns:
The destination of the permanent connection. There can only be one permanent connection to a destination.

getChannelCreator

public ChannelCreator getChannelCreator()
Returns:
The channel creator unless the connection is not closed. Otherwise it throws a Runtime Exception

isClosed

public boolean isClosed()
Returns:
True if this permanent connection has been closed.F

getIdleTCPMillis

public int getIdleTCPMillis()
Returns:
The number of milliseconds a connection is considered idle and will be closed.

aquireSingleConnection

public void aquireSingleConnection()
                            throws InterruptedException
Acquire one connection. Blocks until a connection becomes available.

Throws:
InterruptedException

releaseSingleConnection

public void releaseSingleConnection()
Releases one connection.



Copyright © 2013. All Rights Reserved.