net.tomp2p.connection
Class ConnectionReservation

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

public class ConnectionReservation
extends Object

The connection pool limits the connection used in the application. If too many connections are open, the application has to wait until a connection is closed.

Author:
Thomas Bocek

Constructor Summary
ConnectionReservation(org.jboss.netty.channel.ChannelFactory tcpClientChannelFactory, org.jboss.netty.channel.ChannelFactory udpChannelFactory, ConnectionConfigurationBean configuration, MessageLogger messageLoggerFilter, Statistics statistics)
           
 
Method Summary
 void release(ChannelCreator channelCreator)
          Release a channelcreator.
 void release(ChannelCreator channelCreator, int permits)
          Release a channelcreator.
 ChannelCreator reserve(int permits)
          Reserves connections.
 ChannelCreator reserve(int permits, boolean keepAliveAndReuse)
          Reserves connections.
 void shutdown()
          Close all open connections and prevent creating new ones.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionReservation

public ConnectionReservation(org.jboss.netty.channel.ChannelFactory tcpClientChannelFactory,
                             org.jboss.netty.channel.ChannelFactory udpChannelFactory,
                             ConnectionConfigurationBean configuration,
                             MessageLogger messageLoggerFilter,
                             Statistics statistics)
Method Detail

reserve

public ChannelCreator reserve(int permits)
Reserves connections. If a reservation of 5 connection is made, then 5 parallel connections can be made. Until the connections are released, the connections can be closed and reopened. The reservation reserves connections that are created and released immediately.

Parameters:
permits - The number of connections to be reserved
Returns:
The channel creator object that can be used to create the channels. Returns null if something went wrong (shutdown, interrupt)

reserve

public ChannelCreator reserve(int permits,
                              boolean keepAliveAndReuse)
Reserves connections. If a reservation of 5 connection is made, then 5 parallel connections can be made. Until the connections are released, the connections can be closed and reopened.

Parameters:
permits - The number of connections to be reserved
keepAliveAndReuse - If the connection should stay open (TCP) for later reuse.
Returns:
The channel creator object that can be used to create the channels. Returns null if something went wrong (shutdown, interrupt)

release

public void release(ChannelCreator channelCreator,
                    int permits)
Release a channelcreator. The permits will be returned so that they can be used again.

Parameters:
channelCreator - The channelcreator that is not used anymore (or at least partially)
permits - The number of permits to release

release

public void release(ChannelCreator channelCreator)
Release a channelcreator. The permits will be returned so that they can be used again.

Parameters:
channelCreator. - The channelcreator that is not used anymore

shutdown

public void shutdown()
Close all open connections and prevent creating new ones.



Copyright © 2011. All Rights Reserved.