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, ConnectionConfiguration configuration, MessageLogger messageLoggerFilter, Statistics statistics, Scheduler scheduler)
           
 
Method Summary
 Reservation getReservation()
           
 void release(ChannelCreator channelCreator)
          Release a channelcreator.
 void release(ChannelCreator channelCreator, int permits)
          Release a channelcreator.
 FutureChannelCreator reserve(int permits)
          Reserves connections.
 FutureChannelCreator reserve(int permits, boolean keepAliveAndReuse)
          Reserves connections.
 FutureChannelCreator reserve(int permits, boolean keepAliveAndReuse, String name)
          Reserves connections.
 FutureChannelCreator reserve(int permits, String name)
          Reserves connections.
 void setReservation(Reservation reservation)
           
 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,
                             ConnectionConfiguration configuration,
                             MessageLogger messageLoggerFilter,
                             Statistics statistics,
                             Scheduler scheduler)
Method Detail

reserve

public FutureChannelCreator 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 future channel creator object that can be used to create the channels. Returns null if something went wrong (shutdown, interrupt)

reserve

public FutureChannelCreator reserve(int permits,
                                    String name)
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
name - The name of the ChannelCreator, used for easier debugging
Returns:
The future channel creator object that can be used to create the channels. Returns null if something went wrong (shutdown, interrupt)

reserve

public FutureChannelCreator 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 future channel creator object that can be used to create the channels. Returns null if something went wrong (shutdown, interrupt)

reserve

public FutureChannelCreator reserve(int permits,
                                    boolean keepAliveAndReuse,
                                    String name)
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. Depending on the thread, this may block or not.

Parameters:
permits - The number of connections to be reserved
keepAliveAndReuse - If the connection should stay open (TCP) for later reuse.
name - The name of the ChannelCreator, used for easier debugging
Returns:
The future 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. This operations blocks until everything is finished


getReservation

public Reservation getReservation()

setReservation

public void setReservation(Reservation reservation)


Copyright © 2013. All Rights Reserved.