Package org.apache.activemq.jms.pool
Class PooledConnection
- java.lang.Object
-
- org.apache.activemq.jms.pool.PooledConnection
-
- All Implemented Interfaces:
AutoCloseable,javax.jms.Connection,javax.jms.QueueConnection,javax.jms.TopicConnection
public class PooledConnection extends Object implements javax.jms.TopicConnection, javax.jms.QueueConnection
Represents a proxyConnectionwhich is-aTopicConnectionandQueueConnectionwhich is pooled and onclose()will return its reference to the ConnectionPool backing it. NOTE this implementation is only intended for use when sending messages. It does not deal with pooling of consumers; for that look at a library like Jencks such as in this example
-
-
Field Summary
Fields Modifier and Type Field Description protected ConnectionPoolpool
-
Constructor Summary
Constructors Constructor Description PooledConnection(ConnectionPool pool)Creates a new PooledConnection instance that uses the given ConnectionPool to create and manage its resources.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidassertNotClosed()protected voidcleanupAllLoanedSessions()The PooledSession tracks all Sessions that it created and now we close them.protected voidcleanupConnectionTemporaryDestinations()Remove all of the temporary destinations created for this connection.voidclose()javax.jms.ConnectionConsumercreateConnectionConsumer(javax.jms.Destination destination, String selector, javax.jms.ServerSessionPool serverSessionPool, int maxMessages)javax.jms.ConnectionConsumercreateConnectionConsumer(javax.jms.Queue queue, String selector, javax.jms.ServerSessionPool serverSessionPool, int maxMessages)javax.jms.ConnectionConsumercreateConnectionConsumer(javax.jms.Topic topic, String s, javax.jms.ServerSessionPool serverSessionPool, int maxMessages)javax.jms.ConnectionConsumercreateDurableConnectionConsumer(javax.jms.Topic topic, String selector, String s1, javax.jms.ServerSessionPool serverSessionPool, int i)javax.jms.QueueSessioncreateQueueSession(boolean transacted, int ackMode)javax.jms.SessioncreateSession()Creates aSessionobject.javax.jms.SessioncreateSession(boolean transacted, int ackMode)javax.jms.SessioncreateSession(int sessionMode)Creates aSessionobject.protected javax.jms.SessioncreateSession(SessionKey key)javax.jms.ConnectionConsumercreateSharedConnectionConsumer(javax.jms.Topic topic, String subscriptionName, String messageSelector, javax.jms.ServerSessionPool sessionPool, int maxMessages)javax.jms.ConnectionConsumercreateSharedDurableConnectionConsumer(javax.jms.Topic topic, String subscriptionName, String messageSelector, javax.jms.ServerSessionPool sessionPool, int maxMessages)javax.jms.TopicSessioncreateTopicSession(boolean transacted, int ackMode)StringgetClientID()javax.jms.ConnectiongetConnection()javax.jms.ExceptionListenergetExceptionListener()javax.jms.ConnectionMetaDatagetMetaData()intgetNumActiveSessions()intgetNumSessions()intgetNumtIdleSessions()PooledConnectionnewInstance()Factory method to create a new instance.voidonSessionClosed(PooledSession session)voidonTemporaryQueueCreate(javax.jms.TemporaryQueue tempQueue)voidonTemporaryTopicCreate(javax.jms.TemporaryTopic tempTopic)voidsetClientID(String clientID)voidsetExceptionListener(javax.jms.ExceptionListener exceptionListener)voidstart()voidstop()StringtoString()
-
-
-
Field Detail
-
pool
protected ConnectionPool pool
-
-
Constructor Detail
-
PooledConnection
public PooledConnection(ConnectionPool pool)
Creates a new PooledConnection instance that uses the given ConnectionPool to create and manage its resources. The ConnectionPool instance can be shared amongst many PooledConnection instances.- Parameters:
pool- The connection and pool manager backing this proxy connection object.
-
-
Method Detail
-
newInstance
public PooledConnection newInstance()
Factory method to create a new instance.
-
close
public void close() throws javax.jms.JMSException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfacejavax.jms.Connection- Throws:
javax.jms.JMSException
-
start
public void start() throws javax.jms.JMSException- Specified by:
startin interfacejavax.jms.Connection- Throws:
javax.jms.JMSException
-
stop
public void stop() throws javax.jms.JMSException- Specified by:
stopin interfacejavax.jms.Connection- Throws:
javax.jms.JMSException
-
createConnectionConsumer
public javax.jms.ConnectionConsumer createConnectionConsumer(javax.jms.Destination destination, String selector, javax.jms.ServerSessionPool serverSessionPool, int maxMessages) throws javax.jms.JMSException- Specified by:
createConnectionConsumerin interfacejavax.jms.Connection- Throws:
javax.jms.JMSException
-
createConnectionConsumer
public javax.jms.ConnectionConsumer createConnectionConsumer(javax.jms.Topic topic, String s, javax.jms.ServerSessionPool serverSessionPool, int maxMessages) throws javax.jms.JMSException- Specified by:
createConnectionConsumerin interfacejavax.jms.TopicConnection- Throws:
javax.jms.JMSException
-
createDurableConnectionConsumer
public javax.jms.ConnectionConsumer createDurableConnectionConsumer(javax.jms.Topic topic, String selector, String s1, javax.jms.ServerSessionPool serverSessionPool, int i) throws javax.jms.JMSException- Specified by:
createDurableConnectionConsumerin interfacejavax.jms.Connection- Specified by:
createDurableConnectionConsumerin interfacejavax.jms.TopicConnection- Throws:
javax.jms.JMSException
-
getClientID
public String getClientID() throws javax.jms.JMSException
- Specified by:
getClientIDin interfacejavax.jms.Connection- Throws:
javax.jms.JMSException
-
getExceptionListener
public javax.jms.ExceptionListener getExceptionListener() throws javax.jms.JMSException- Specified by:
getExceptionListenerin interfacejavax.jms.Connection- Throws:
javax.jms.JMSException
-
getMetaData
public javax.jms.ConnectionMetaData getMetaData() throws javax.jms.JMSException- Specified by:
getMetaDatain interfacejavax.jms.Connection- Throws:
javax.jms.JMSException
-
setExceptionListener
public void setExceptionListener(javax.jms.ExceptionListener exceptionListener) throws javax.jms.JMSException- Specified by:
setExceptionListenerin interfacejavax.jms.Connection- Throws:
javax.jms.JMSException
-
setClientID
public void setClientID(String clientID) throws javax.jms.JMSException
- Specified by:
setClientIDin interfacejavax.jms.Connection- Throws:
javax.jms.JMSException
-
createConnectionConsumer
public javax.jms.ConnectionConsumer createConnectionConsumer(javax.jms.Queue queue, String selector, javax.jms.ServerSessionPool serverSessionPool, int maxMessages) throws javax.jms.JMSException- Specified by:
createConnectionConsumerin interfacejavax.jms.QueueConnection- Throws:
javax.jms.JMSException
-
createQueueSession
public javax.jms.QueueSession createQueueSession(boolean transacted, int ackMode) throws javax.jms.JMSException- Specified by:
createQueueSessionin interfacejavax.jms.QueueConnection- Throws:
javax.jms.JMSException
-
createTopicSession
public javax.jms.TopicSession createTopicSession(boolean transacted, int ackMode) throws javax.jms.JMSException- Specified by:
createTopicSessionin interfacejavax.jms.TopicConnection- Throws:
javax.jms.JMSException
-
createSession
public javax.jms.Session createSession() throws javax.jms.JMSExceptionCreates aSessionobject.- Specified by:
createSessionin interfacejavax.jms.Connection- Throws:
javax.jms.JMSException- if theConnectionobject fails to create a session due to some internal error or lack of support for the specific transaction and acknowledgement mode.- Since:
- 2.0
-
createSession
public javax.jms.Session createSession(int sessionMode) throws javax.jms.JMSExceptionCreates aSessionobject.- Specified by:
createSessionin interfacejavax.jms.Connection- Parameters:
acknowledgeMode- indicates whether the consumer or the client will acknowledge any messages it receives; ignored if the session is transacted. Legal values areSession.AUTO_ACKNOWLEDGE,Session.CLIENT_ACKNOWLEDGE, andSession.DUPS_OK_ACKNOWLEDGE.- Returns:
- a newly created session
- Throws:
javax.jms.JMSException- if theConnectionobject fails to create a session due to some internal error or lack of support for the specific transaction and acknowledgement mode.- Since:
- 2.0
- See Also:
Session.AUTO_ACKNOWLEDGE,Session.CLIENT_ACKNOWLEDGE,Session.DUPS_OK_ACKNOWLEDGE
-
createSession
public javax.jms.Session createSession(boolean transacted, int ackMode) throws javax.jms.JMSException- Specified by:
createSessionin interfacejavax.jms.Connection- Throws:
javax.jms.JMSException
-
createSharedConnectionConsumer
public javax.jms.ConnectionConsumer createSharedConnectionConsumer(javax.jms.Topic topic, String subscriptionName, String messageSelector, javax.jms.ServerSessionPool sessionPool, int maxMessages) throws javax.jms.JMSException- Specified by:
createSharedConnectionConsumerin interfacejavax.jms.Connection- Throws:
javax.jms.JMSException- Since:
- 2.0
- See Also:
ConnectionConsumer
-
createSharedDurableConnectionConsumer
public javax.jms.ConnectionConsumer createSharedDurableConnectionConsumer(javax.jms.Topic topic, String subscriptionName, String messageSelector, javax.jms.ServerSessionPool sessionPool, int maxMessages) throws javax.jms.JMSException- Specified by:
createSharedDurableConnectionConsumerin interfacejavax.jms.Connection- Throws:
javax.jms.JMSException- Since:
- 2.0
- See Also:
ConnectionConsumer
-
onTemporaryQueueCreate
public void onTemporaryQueueCreate(javax.jms.TemporaryQueue tempQueue)
-
onTemporaryTopicCreate
public void onTemporaryTopicCreate(javax.jms.TemporaryTopic tempTopic)
-
onSessionClosed
public void onSessionClosed(PooledSession session)
-
getConnection
public javax.jms.Connection getConnection() throws javax.jms.JMSException- Throws:
javax.jms.JMSException
-
assertNotClosed
protected void assertNotClosed() throws javax.jms.IllegalStateException- Throws:
javax.jms.IllegalStateException
-
createSession
protected javax.jms.Session createSession(SessionKey key) throws javax.jms.JMSException
- Throws:
javax.jms.JMSException
-
cleanupConnectionTemporaryDestinations
protected void cleanupConnectionTemporaryDestinations()
Remove all of the temporary destinations created for this connection. This is important since the underlying connection may be reused over a long period of time, accumulating all of the temporary destinations from each use. However, from the perspective of the lifecycle from the client's view, close() closes the connection and, therefore, deletes all of the temporary destinations created.
-
cleanupAllLoanedSessions
protected void cleanupAllLoanedSessions()
The PooledSession tracks all Sessions that it created and now we close them. Closing the PooledSession will return the internal Session to the Pool of Session after cleaning up all the resources that the Session had allocated for this PooledConnection.
-
getNumSessions
public int getNumSessions()
- Returns:
- the total number of Pooled session including idle sessions that are not currently loaned out to any client.
-
getNumActiveSessions
public int getNumActiveSessions()
- Returns:
- the number of Sessions that are currently checked out of this Connection's session pool.
-
getNumtIdleSessions
public int getNumtIdleSessions()
- Returns:
- the number of Sessions that are idle in this Connection's sessions pool.
-
-