Package org.messaginghub.pooled.jms
Class JmsPoolConnection
- java.lang.Object
-
- org.messaginghub.pooled.jms.JmsPoolConnection
-
- All Implemented Interfaces:
AutoCloseable
,javax.jms.Connection
,javax.jms.QueueConnection
,javax.jms.TopicConnection
,JmsPoolSessionEventListener
public class JmsPoolConnection extends Object implements javax.jms.TopicConnection, javax.jms.QueueConnection, JmsPoolSessionEventListener, AutoCloseable
Represents a proxyConnection
which is-aTopicConnection
andQueueConnection
which 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.
-
-
Field Summary
Fields Modifier and Type Field Description protected PooledConnection
connection
-
Constructor Summary
Constructors Constructor Description JmsPoolConnection(PooledConnection 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 void
checkClosed()
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()
javax.jms.ConnectionConsumer
createConnectionConsumer(javax.jms.Destination destination, String selector, javax.jms.ServerSessionPool serverSessionPool, int maxMessages)
javax.jms.ConnectionConsumer
createConnectionConsumer(javax.jms.Queue queue, String selector, javax.jms.ServerSessionPool serverSessionPool, int maxMessages)
javax.jms.ConnectionConsumer
createConnectionConsumer(javax.jms.Topic topic, String s, javax.jms.ServerSessionPool serverSessionPool, int maxMessages)
javax.jms.ConnectionConsumer
createDurableConnectionConsumer(javax.jms.Topic topic, String selector, String s1, javax.jms.ServerSessionPool serverSessionPool, int i)
javax.jms.QueueSession
createQueueSession(boolean transacted, int ackMode)
javax.jms.Session
createSession()
javax.jms.Session
createSession(boolean transacted, int ackMode)
javax.jms.Session
createSession(int sessionMode)
javax.jms.ConnectionConsumer
createSharedConnectionConsumer(javax.jms.Topic topic, String subscriptionName, String selector, javax.jms.ServerSessionPool sessionPool, int maxMessages)
javax.jms.ConnectionConsumer
createSharedDurableConnectionConsumer(javax.jms.Topic topic, String subscriptionName, String selector, javax.jms.ServerSessionPool sessionPool, int maxMessages)
javax.jms.TopicSession
createTopicSession(boolean transacted, int ackMode)
String
getClientID()
javax.jms.Connection
getConnection()
javax.jms.ExceptionListener
getExceptionListener()
javax.jms.ConnectionMetaData
getMetaData()
int
getNumActiveSessions()
int
getNumSessions()
int
getNumtIdleSessions()
void
onSessionClosed(JmsPoolSession session)
Called when the PooledSession is closed.void
onTemporaryQueueCreate(javax.jms.TemporaryQueue tempQueue)
Called on successful creation of a new TemporaryQueue.void
onTemporaryTopicCreate(javax.jms.TemporaryTopic tempTopic)
Called on successful creation of a new TemporaryTopic.void
setClientID(String clientID)
void
setExceptionListener(javax.jms.ExceptionListener exceptionListener)
void
start()
void
stop()
String
toString()
-
-
-
Field Detail
-
connection
protected PooledConnection connection
-
-
Constructor Detail
-
JmsPoolConnection
public JmsPoolConnection(PooledConnection 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
-
close
public void close() throws javax.jms.JMSException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfacejavax.jms.Connection
- Throws:
javax.jms.JMSException
-
start
public void start() throws javax.jms.JMSException
- Specified by:
start
in interfacejavax.jms.Connection
- Throws:
javax.jms.JMSException
-
stop
public void stop() throws javax.jms.JMSException
- Specified by:
stop
in interfacejavax.jms.Connection
- Throws:
javax.jms.JMSException
-
getMetaData
public javax.jms.ConnectionMetaData getMetaData() throws javax.jms.JMSException
- Specified by:
getMetaData
in interfacejavax.jms.Connection
- Throws:
javax.jms.JMSException
-
getExceptionListener
public javax.jms.ExceptionListener getExceptionListener() throws javax.jms.JMSException
- Specified by:
getExceptionListener
in interfacejavax.jms.Connection
- Throws:
javax.jms.JMSException
-
setExceptionListener
public void setExceptionListener(javax.jms.ExceptionListener exceptionListener) throws javax.jms.JMSException
- Specified by:
setExceptionListener
in interfacejavax.jms.Connection
- Throws:
javax.jms.JMSException
-
getClientID
public String getClientID() throws javax.jms.JMSException
- Specified by:
getClientID
in interfacejavax.jms.Connection
- Throws:
javax.jms.JMSException
-
setClientID
public void setClientID(String clientID) throws javax.jms.JMSException
- Specified by:
setClientID
in 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:
createConnectionConsumer
in 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:
createConnectionConsumer
in 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:
createDurableConnectionConsumer
in interfacejavax.jms.Connection
- Specified by:
createDurableConnectionConsumer
in interfacejavax.jms.TopicConnection
- Throws:
javax.jms.JMSException
-
createSharedDurableConnectionConsumer
public javax.jms.ConnectionConsumer createSharedDurableConnectionConsumer(javax.jms.Topic topic, String subscriptionName, String selector, javax.jms.ServerSessionPool sessionPool, int maxMessages) throws javax.jms.JMSException
- Specified by:
createSharedDurableConnectionConsumer
in interfacejavax.jms.Connection
- Throws:
javax.jms.JMSException
-
createSharedConnectionConsumer
public javax.jms.ConnectionConsumer createSharedConnectionConsumer(javax.jms.Topic topic, String subscriptionName, String selector, javax.jms.ServerSessionPool sessionPool, int maxMessages) throws javax.jms.JMSException
- Specified by:
createSharedConnectionConsumer
in 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:
createConnectionConsumer
in interfacejavax.jms.QueueConnection
- Throws:
javax.jms.JMSException
-
createQueueSession
public javax.jms.QueueSession createQueueSession(boolean transacted, int ackMode) throws javax.jms.JMSException
- Specified by:
createQueueSession
in interfacejavax.jms.QueueConnection
- Throws:
javax.jms.JMSException
-
createTopicSession
public javax.jms.TopicSession createTopicSession(boolean transacted, int ackMode) throws javax.jms.JMSException
- Specified by:
createTopicSession
in interfacejavax.jms.TopicConnection
- Throws:
javax.jms.JMSException
-
createSession
public javax.jms.Session createSession() throws javax.jms.JMSException
- Specified by:
createSession
in interfacejavax.jms.Connection
- Throws:
javax.jms.JMSException
-
createSession
public javax.jms.Session createSession(int sessionMode) throws javax.jms.JMSException
- Specified by:
createSession
in interfacejavax.jms.Connection
- Throws:
javax.jms.JMSException
-
createSession
public javax.jms.Session createSession(boolean transacted, int ackMode) throws javax.jms.JMSException
- Specified by:
createSession
in interfacejavax.jms.Connection
- Throws:
javax.jms.JMSException
-
onTemporaryQueueCreate
public void onTemporaryQueueCreate(javax.jms.TemporaryQueue tempQueue)
Description copied from interface:JmsPoolSessionEventListener
Called on successful creation of a new TemporaryQueue.- Specified by:
onTemporaryQueueCreate
in interfaceJmsPoolSessionEventListener
- Parameters:
tempQueue
- The TemporaryQueue just created.
-
onTemporaryTopicCreate
public void onTemporaryTopicCreate(javax.jms.TemporaryTopic tempTopic)
Description copied from interface:JmsPoolSessionEventListener
Called on successful creation of a new TemporaryTopic.- Specified by:
onTemporaryTopicCreate
in interfaceJmsPoolSessionEventListener
- Parameters:
tempTopic
- The TemporaryTopic just created.
-
onSessionClosed
public void onSessionClosed(JmsPoolSession session)
Description copied from interface:JmsPoolSessionEventListener
Called when the PooledSession is closed.- Specified by:
onSessionClosed
in interfaceJmsPoolSessionEventListener
- Parameters:
session
- The PooledSession that has been closed.
-
getConnection
public javax.jms.Connection getConnection() 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() throws javax.jms.JMSException
- Returns:
- the total number of Pooled session including idle sessions that are not currently loaned out to any client.
- Throws:
javax.jms.JMSException
- if the connection has been closed.
-
getNumActiveSessions
public int getNumActiveSessions() throws javax.jms.JMSException
- Returns:
- the number of Sessions that are currently checked out of this Connection's session pool.
- Throws:
javax.jms.JMSException
- if the connection has been closed.
-
getNumtIdleSessions
public int getNumtIdleSessions() throws javax.jms.JMSException
- Returns:
- the number of Sessions that are idle in this Connection's sessions pool.
- Throws:
javax.jms.JMSException
- if the connection has been closed.
-
checkClosed
protected void checkClosed() throws javax.jms.IllegalStateException
- Throws:
javax.jms.IllegalStateException
-
-