org.apache.activemq.jms.pool
Class PooledConnection

java.lang.Object
  extended by org.apache.activemq.jms.pool.PooledConnection
All Implemented Interfaces:
Connection, QueueConnection, TopicConnection
Direct Known Subclasses:
PooledConnection

public class PooledConnection
extends Object
implements TopicConnection, QueueConnection

Represents a proxy Connection which is-a TopicConnection and QueueConnection which is pooled and on close() 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
protected  ConnectionPool pool
           
 
Constructor Summary
PooledConnection(ConnectionPool pool)
          Creates a new PooledConnection instance that uses the given ConnectionPool to create and manage its resources.
 
Method Summary
protected  void assertNotClosed()
           
protected  void cleanupAllLoanedSessions()
          The PooledSession tracks all Sessions that it created and now we close them.
protected  void cleanupConnectionTemporaryDestinations()
          Remove all of the temporary destinations created for this connection.
 void close()
           
 ConnectionConsumer createConnectionConsumer(Destination destination, String selector, ServerSessionPool serverSessionPool, int maxMessages)
           
 ConnectionConsumer createConnectionConsumer(Queue queue, String selector, ServerSessionPool serverSessionPool, int maxMessages)
           
 ConnectionConsumer createConnectionConsumer(Topic topic, String s, ServerSessionPool serverSessionPool, int maxMessages)
           
 ConnectionConsumer createDurableConnectionConsumer(Topic topic, String selector, String s1, ServerSessionPool serverSessionPool, int i)
           
 QueueSession createQueueSession(boolean transacted, int ackMode)
           
 Session createSession(boolean transacted, int ackMode)
           
protected  Session createSession(SessionKey key)
           
 TopicSession createTopicSession(boolean transacted, int ackMode)
           
 String getClientID()
           
 Connection getConnection()
           
 ExceptionListener getExceptionListener()
           
 ConnectionMetaData getMetaData()
           
 int getNumActiveSessions()
           
 int getNumSessions()
           
 int getNumtIdleSessions()
           
 PooledConnection newInstance()
          Factory method to create a new instance.
 void onSessionClosed(PooledSession session)
          Called when the PooledSession is closed.
 void onTemporaryQueueCreate(TemporaryQueue tempQueue)
          Called on successful creation of a new TemporaryQueue.
 void onTemporaryTopicCreate(TemporaryTopic tempTopic)
          Called on successful creation of a new TemporaryTopic.
 void setClientID(String clientID)
           
 void setExceptionListener(ExceptionListener exceptionListener)
           
 void start()
           
 void stop()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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:
close in interface Connection
Throws:
JMSException

start

public void start()
           throws JMSException
Specified by:
start in interface Connection
Throws:
JMSException

stop

public void stop()
          throws JMSException
Specified by:
stop in interface Connection
Throws:
JMSException

createConnectionConsumer

public ConnectionConsumer createConnectionConsumer(Destination destination,
                                                   String selector,
                                                   ServerSessionPool serverSessionPool,
                                                   int maxMessages)
                                            throws JMSException
Specified by:
createConnectionConsumer in interface Connection
Throws:
JMSException

createConnectionConsumer

public ConnectionConsumer createConnectionConsumer(Topic topic,
                                                   String s,
                                                   ServerSessionPool serverSessionPool,
                                                   int maxMessages)
                                            throws JMSException
Specified by:
createConnectionConsumer in interface TopicConnection
Throws:
JMSException

createDurableConnectionConsumer

public ConnectionConsumer createDurableConnectionConsumer(Topic topic,
                                                          String selector,
                                                          String s1,
                                                          ServerSessionPool serverSessionPool,
                                                          int i)
                                                   throws JMSException
Specified by:
createDurableConnectionConsumer in interface Connection
Specified by:
createDurableConnectionConsumer in interface TopicConnection
Throws:
JMSException

getClientID

public String getClientID()
                   throws JMSException
Specified by:
getClientID in interface Connection
Throws:
JMSException

getExceptionListener

public ExceptionListener getExceptionListener()
                                       throws JMSException
Specified by:
getExceptionListener in interface Connection
Throws:
JMSException

getMetaData

public ConnectionMetaData getMetaData()
                               throws JMSException
Specified by:
getMetaData in interface Connection
Throws:
JMSException

setExceptionListener

public void setExceptionListener(ExceptionListener exceptionListener)
                          throws JMSException
Specified by:
setExceptionListener in interface Connection
Throws:
JMSException

setClientID

public void setClientID(String clientID)
                 throws JMSException
Specified by:
setClientID in interface Connection
Throws:
JMSException

createConnectionConsumer

public ConnectionConsumer createConnectionConsumer(Queue queue,
                                                   String selector,
                                                   ServerSessionPool serverSessionPool,
                                                   int maxMessages)
                                            throws JMSException
Specified by:
createConnectionConsumer in interface QueueConnection
Throws:
JMSException

createQueueSession

public QueueSession createQueueSession(boolean transacted,
                                       int ackMode)
                                throws JMSException
Specified by:
createQueueSession in interface QueueConnection
Throws:
JMSException

createTopicSession

public TopicSession createTopicSession(boolean transacted,
                                       int ackMode)
                                throws JMSException
Specified by:
createTopicSession in interface TopicConnection
Throws:
JMSException

createSession

public Session createSession(boolean transacted,
                             int ackMode)
                      throws JMSException
Specified by:
createSession in interface Connection
Throws:
JMSException

onTemporaryQueueCreate

public void onTemporaryQueueCreate(TemporaryQueue tempQueue)
Called on successful creation of a new TemporaryQueue.

Parameters:
tempQueue - The TemporaryQueue just created.

onTemporaryTopicCreate

public void onTemporaryTopicCreate(TemporaryTopic tempTopic)
Called on successful creation of a new TemporaryTopic.

Parameters:
tempTopic - The TemporaryTopic just created.

onSessionClosed

public void onSessionClosed(PooledSession session)
Called when the PooledSession is closed.

Parameters:
session - The PooledSession that has been closed.

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

toString

public String toString()
Overrides:
toString in class Object

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.


Copyright © 2005–2013 The Apache Software Foundation. All rights reserved.