Package org.apache.activemq.jms.pool
Class PooledConnection
- java.lang.Object
-
- org.apache.activemq.jms.pool.PooledConnection
-
- All Implemented Interfaces:
AutoCloseable,Connection,QueueConnection,TopicConnection
public class PooledConnection extends Object implements TopicConnection, 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
-
-
-
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 JMSException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceConnection- Throws:
JMSException
-
start
public void start() throws JMSException- Specified by:
startin interfaceConnection- Throws:
JMSException
-
stop
public void stop() throws JMSException- Specified by:
stopin interfaceConnection- Throws:
JMSException
-
createConnectionConsumer
public ConnectionConsumer createConnectionConsumer(Destination destination, String selector, ServerSessionPool serverSessionPool, int maxMessages) throws JMSException
- Specified by:
createConnectionConsumerin interfaceConnection- Throws:
JMSException
-
createConnectionConsumer
public ConnectionConsumer createConnectionConsumer(Topic topic, String s, ServerSessionPool serverSessionPool, int maxMessages) throws JMSException
- Specified by:
createConnectionConsumerin interfaceTopicConnection- Throws:
JMSException
-
createDurableConnectionConsumer
public ConnectionConsumer createDurableConnectionConsumer(Topic topic, String selector, String s1, ServerSessionPool serverSessionPool, int i) throws JMSException
- Specified by:
createDurableConnectionConsumerin interfaceConnection- Specified by:
createDurableConnectionConsumerin interfaceTopicConnection- Throws:
JMSException
-
getClientID
public String getClientID() throws JMSException
- Specified by:
getClientIDin interfaceConnection- Throws:
JMSException
-
getExceptionListener
public ExceptionListener getExceptionListener() throws JMSException
- Specified by:
getExceptionListenerin interfaceConnection- Throws:
JMSException
-
getMetaData
public ConnectionMetaData getMetaData() throws JMSException
- Specified by:
getMetaDatain interfaceConnection- Throws:
JMSException
-
setExceptionListener
public void setExceptionListener(ExceptionListener exceptionListener) throws JMSException
- Specified by:
setExceptionListenerin interfaceConnection- Throws:
JMSException
-
setClientID
public void setClientID(String clientID) throws JMSException
- Specified by:
setClientIDin interfaceConnection- Throws:
JMSException
-
createConnectionConsumer
public ConnectionConsumer createConnectionConsumer(Queue queue, String selector, ServerSessionPool serverSessionPool, int maxMessages) throws JMSException
- Specified by:
createConnectionConsumerin interfaceQueueConnection- Throws:
JMSException
-
createQueueSession
public QueueSession createQueueSession(boolean transacted, int ackMode) throws JMSException
- Specified by:
createQueueSessionin interfaceQueueConnection- Throws:
JMSException
-
createTopicSession
public TopicSession createTopicSession(boolean transacted, int ackMode) throws JMSException
- Specified by:
createTopicSessionin interfaceTopicConnection- Throws:
JMSException
-
createSession
public Session createSession() throws JMSException
Creates aSessionobject.- Specified by:
createSessionin interfaceConnection- Throws:
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 Session createSession(int sessionMode) throws JMSException
Creates aSessionobject.- Specified by:
createSessionin interfaceConnection- 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:
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 Session createSession(boolean transacted, int ackMode) throws JMSException
- Specified by:
createSessionin interfaceConnection- Throws:
JMSException
-
createSharedConnectionConsumer
public ConnectionConsumer createSharedConnectionConsumer(Topic topic, String subscriptionName, String messageSelector, ServerSessionPool sessionPool, int maxMessages) throws JMSException
- Specified by:
createSharedConnectionConsumerin interfaceConnection- Throws:
JMSException- Since:
- 2.0
- See Also:
ConnectionConsumer
-
createSharedDurableConnectionConsumer
public ConnectionConsumer createSharedDurableConnectionConsumer(Topic topic, String subscriptionName, String messageSelector, ServerSessionPool sessionPool, int maxMessages) throws JMSException
- Specified by:
createSharedDurableConnectionConsumerin interfaceConnection- Throws:
JMSException- Since:
- 2.0
- See Also:
ConnectionConsumer
-
onTemporaryQueueCreate
public void onTemporaryQueueCreate(TemporaryQueue tempQueue)
-
onTemporaryTopicCreate
public void onTemporaryTopicCreate(TemporaryTopic tempTopic)
-
onSessionClosed
public void onSessionClosed(PooledSession session)
-
getConnection
public Connection getConnection() throws JMSException
- Throws:
JMSException
-
assertNotClosed
protected void assertNotClosed() throws IllegalStateException- Throws:
IllegalStateException
-
createSession
protected Session createSession(SessionKey key) throws JMSException
- Throws:
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.
-
-