Package org.apache.activemq.jms.pool
Class ConnectionPool
- java.lang.Object
-
- org.apache.activemq.jms.pool.ConnectionPool
-
- All Implemented Interfaces:
ExceptionListener
- Direct Known Subclasses:
XaConnectionPool
public class ConnectionPool extends Object implements ExceptionListener
Holds a real JMS connection along with the session pools associated with it. Instances of this class are shared amongst one or more PooledConnection object and must track the session objects that are loaned out for cleanup on close as well as ensuring that the temporary destinations of the managed Connection are purged when all references to this ConnectionPool are released.
-
-
Field Summary
Fields Modifier and Type Field Description protected Connection
connection
-
Constructor Summary
Constructors Constructor Description ConnectionPool(Connection connection)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Session
createSession(boolean transacted, int ackMode)
void
decrementReferenceCount()
boolean
expiredCheck()
Determines if this Connection has expired.long
getBlockIfSessionPoolIsFullTimeout()
Returns the timeout to use for blocking creating new sessionsConnection
getConnection()
long
getExpiryTimeout()
int
getIdleTimeout()
int
getMaximumActiveSessionPerConnection()
int
getNumActiveSessions()
int
getNumIdleSessions()
int
getNumSessions()
void
incrementReferenceCount()
boolean
isBlockIfSessionPoolIsFull()
boolean
isReconnectOnException()
boolean
isUseAnonymousProducers()
protected Session
makeSession(SessionKey key)
void
onException(JMSException exception)
void
setBlockIfSessionPoolIsFull(boolean block)
Configure whether the createSession method should block when there are no more idle sessions and the pool already contains the maximum number of active sessions.void
setBlockIfSessionPoolIsFullTimeout(long blockIfSessionPoolIsFullTimeout)
Controls the behavior of the internal session pool.void
setExpiryTimeout(long expiryTimeout)
void
setHasExpired(boolean val)
void
setIdleTimeout(int idleTimeout)
void
setMaximumActiveSessionPerConnection(int maximumActiveSessionPerConnection)
void
setReconnectOnException(boolean reconnectOnException)
Controls weather the underlying connection should be reset (and renewed) on JMSExceptionvoid
setUseAnonymousProducers(boolean value)
void
start()
String
toString()
protected void
unWrap(Connection connection)
protected Connection
wrap(Connection connection)
-
-
-
Field Detail
-
connection
protected Connection connection
-
-
Constructor Detail
-
ConnectionPool
public ConnectionPool(Connection connection)
-
-
Method Detail
-
setHasExpired
public void setHasExpired(boolean val)
-
makeSession
protected Session makeSession(SessionKey key) throws JMSException
- Throws:
JMSException
-
wrap
protected Connection wrap(Connection connection)
-
unWrap
protected void unWrap(Connection connection)
-
start
public void start() throws JMSException
- Throws:
JMSException
-
getConnection
public Connection getConnection()
-
createSession
public Session createSession(boolean transacted, int ackMode) throws JMSException
- Throws:
JMSException
-
close
public void close()
-
incrementReferenceCount
public void incrementReferenceCount()
-
decrementReferenceCount
public void decrementReferenceCount()
-
expiredCheck
public boolean expiredCheck()
Determines if this Connection has expired. A ConnectionPool is considered expired when all references to it are released AND either the configured idleTimeout has elapsed OR the configured expiryTimeout has elapsed. Once a ConnectionPool is determined to have expired its underlying Connection is closed.- Returns:
- true if this connection has expired.
-
getIdleTimeout
public int getIdleTimeout()
-
setIdleTimeout
public void setIdleTimeout(int idleTimeout)
-
setExpiryTimeout
public void setExpiryTimeout(long expiryTimeout)
-
getExpiryTimeout
public long getExpiryTimeout()
-
getMaximumActiveSessionPerConnection
public int getMaximumActiveSessionPerConnection()
-
setMaximumActiveSessionPerConnection
public void setMaximumActiveSessionPerConnection(int maximumActiveSessionPerConnection)
-
isUseAnonymousProducers
public boolean isUseAnonymousProducers()
-
setUseAnonymousProducers
public void setUseAnonymousProducers(boolean value)
-
getNumSessions
public int getNumSessions()
- Returns:
- the total number of Pooled session including idle sessions that are not currently loaned out to any client.
-
getNumIdleSessions
public int getNumIdleSessions()
- Returns:
- the total number of Sessions that are in the Session pool but not loaned out.
-
getNumActiveSessions
public int getNumActiveSessions()
- Returns:
- the total number of Session's that have been loaned to PooledConnection instances.
-
setBlockIfSessionPoolIsFull
public void setBlockIfSessionPoolIsFull(boolean block)
Configure whether the createSession method should block when there are no more idle sessions and the pool already contains the maximum number of active sessions. If false the create method will fail and throw an exception.- Parameters:
block
- Indicates whether blocking should be used to wait for more space to create a session.
-
isBlockIfSessionPoolIsFull
public boolean isBlockIfSessionPoolIsFull()
-
getBlockIfSessionPoolIsFullTimeout
public long getBlockIfSessionPoolIsFullTimeout()
Returns the timeout to use for blocking creating new sessions- Returns:
- true if the pooled Connection createSession method will block when the limit is hit.
- See Also:
setBlockIfSessionPoolIsFull(boolean)
-
setBlockIfSessionPoolIsFullTimeout
public void setBlockIfSessionPoolIsFullTimeout(long blockIfSessionPoolIsFullTimeout)
Controls the behavior of the internal session pool. By default the call to Connection.getSession() will block if the session pool is full. This setting will affect how long it blocks and throws an exception after the timeout. The size of the session pool is controlled by the @see #maximumActive property. Whether or not the call to create session blocks is controlled by the @see #blockIfSessionPoolIsFull property- Parameters:
blockIfSessionPoolIsFullTimeout
- - if blockIfSessionPoolIsFullTimeout is true, then use this setting to configure how long to block before retry
-
isReconnectOnException
public boolean isReconnectOnException()
- Returns:
- true if the underlying connection will be renewed on JMSException, false otherwise
-
setReconnectOnException
public void setReconnectOnException(boolean reconnectOnException)
Controls weather the underlying connection should be reset (and renewed) on JMSException- Parameters:
reconnectOnException
- Boolean value that configures whether reconnect on exception should happen
-
onException
public void onException(JMSException exception)
- Specified by:
onException
in interfaceExceptionListener
-
-