Class ConnectionPool
- java.lang.Object
-
- org.objectweb.joram.client.jms.pool.ConnectionPool
-
public class ConnectionPool extends Object
Implements a pool of connection resulting of a unique ConnectionFactory object. Connections are sorted by identity.
-
-
Field Summary
Fields Modifier and Type Field Description private Map<ConnectionKey,LinkedList<PooledConnection>>cacheMap containing the lists of connections for each identity(package private) intmaxFreeConnectionsMaximum number of free connections for an identity in the pool
-
Constructor Summary
Constructors Constructor Description ConnectionPool(int maxFreeConnections)Creates a new pool of connections.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PooledConnectionalloc(String name, String password)Allocates a Connection for the specified identity.voidfree(PooledConnection cnx)Frees the specified connection, depending of the number of free connections in the pool this connection is closed or inserted in the pool.intgetMaxFreeConnections()Gets the maximum number of free connections for an identity in the pool.voidsetMaxFreeConnections(int maxFreeConnections)Returns the maximum number of free connections for an identity in the pool.
-
-
-
Field Detail
-
maxFreeConnections
int maxFreeConnections
Maximum number of free connections for an identity in the pool
-
cache
private Map<ConnectionKey,LinkedList<PooledConnection>> cache
Map containing the lists of connections for each identity
-
-
Method Detail
-
getMaxFreeConnections
public int getMaxFreeConnections()
Gets the maximum number of free connections for an identity in the pool.- Returns:
- the maxFreeConnections
-
setMaxFreeConnections
public void setMaxFreeConnections(int maxFreeConnections)
Returns the maximum number of free connections for an identity in the pool.- Parameters:
maxFreeConnections- the maxFreeConnections to set
-
alloc
public PooledConnection alloc(String name, String password)
Allocates a Connection for the specified identity.- Parameters:
name- name of user.password- password of user.- Returns:
- A connection for the specified identity.
-
free
public void free(PooledConnection cnx) throws JMSException
Frees the specified connection, depending of the number of free connections in the pool this connection is closed or inserted in the pool.- Parameters:
cnx- The connection to free.- Throws:
JMSException- an error occurs during the cleanup of the connection.
-
-