org.apache.cxf.transport.jms
Class JMSSessionFactory

java.lang.Object
  extended by org.apache.cxf.transport.jms.JMSSessionFactory

public class JMSSessionFactory
extends java.lang.Object

This class encapsulates the creation and pooling logic for JMS Sessions. The usage patterns for sessions, producers & consumers are as follows ...

client-side: an invoking thread requires relatively short-term exclusive use of a session, an unidentified producer to send the request message, and in the point-to-point domain a consumer for the temporary ReplyTo destination to synchronously receive the reply if the operation is twoway (in the pub-sub domain only oneway operations are supported, so a there is never a requirement for a reply destination)

server-side receive: each port based on requires relatively long-term exclusive use of a session, a consumer with a MessageListener for the JMS destination specified for the port, and an unidentified producer to send the request message

server-side send: each dispatch of a twoway request requires relatively short-term exclusive use of a session and an indentified producer (but not a consumer) - note that the session used for the recieve side cannot be re-used for the send, as MessageListener usage precludes any synchronous sends or receives on that session

So on the client-side, pooling of sessions is bound up with pooling of temporary reply destinations, whereas on the server receive side the benefit of pooling is marginal as the session is required from the point at which the port was activated until the Bus is shutdown The server send side resembles the client side, except that a consumer for the temporary destination is never required. Hence different pooling strategies make sense ...

client-side: a SoftReference-based cache of send/receive sessions is maintained containing an aggregate of a session, indentified producer, temporary reply destination & consumer for same

server-side receive: as sessions cannot be usefully recycled, they are simply created on demand and closed when no longer required

server-side send: a SoftReference-based cache of send-only sessions is maintained containing an aggregate of a session and an indentified producer

In a pure client or pure server, only a single cache is ever populated. Where client and server logic is co-located, a client session retrieval for a twoway invocation checks the reply-capable cache first and then the send-only cache - if a session is available in the later then its used after a tempory destination is created before being recycled back into the reply-capable cache. A server send side retrieval or client retrieval for a oneway invocation checks the send-only cache first and then the reply-capable cache - if a session is available in the later then its used and the tempory destination is ignored. So in the co-located case, sessions migrate from the send-only cache to the reply-capable cache as necessary.

Author:
Eoghan Glynn

Constructor Summary
JMSSessionFactory(javax.jms.Connection connection, javax.jms.Destination replyDestination, javax.naming.Context context, JMSTransport tbb, ServerBehaviorPolicyType runtimePolicy)
          Constructor.
 
Method Summary
 PooledSession get(boolean replyCapable)
           
 PooledSession get(javax.jms.Destination destination)
          Retrieve a new
 PooledSession get(javax.jms.Destination replyDest, boolean replyCapable)
          Retrieve a new or cached Session.
protected  javax.jms.Connection getConnection()
           
 javax.jms.Queue getQueueFromInitialContext(java.lang.String queueName)
           
 void recycle(PooledSession pooledSession)
          Return a Session to the pool
 void shutdown()
          Shutdown the session factory.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JMSSessionFactory

public JMSSessionFactory(javax.jms.Connection connection,
                         javax.jms.Destination replyDestination,
                         javax.naming.Context context,
                         JMSTransport tbb,
                         ServerBehaviorPolicyType runtimePolicy)
Constructor.

Parameters:
connection - the shared {Queue|Topic}Connection
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getConnection

protected javax.jms.Connection getConnection()

getQueueFromInitialContext

public javax.jms.Queue getQueueFromInitialContext(java.lang.String queueName)
                                           throws javax.naming.NamingException
Throws:
javax.naming.NamingException

get

public PooledSession get(boolean replyCapable)
                  throws javax.jms.JMSException
Throws:
javax.jms.JMSException

get

public PooledSession get(javax.jms.Destination replyDest,
                         boolean replyCapable)
                  throws javax.jms.JMSException
Retrieve a new or cached Session.

Parameters:
replyDest - Destination name if coming from wsa:Header
replyCapable - true iff the session is to be used to receive replies (implies client side twoway invocation )
Returns:
a new or cached Session
Throws:
javax.jms.JMSException

get

public PooledSession get(javax.jms.Destination destination)
                  throws javax.jms.JMSException
Retrieve a new

Parameters:
destination - the target JMS queue or topic (non-null implies server receive side)
Returns:
a new or cached Session
Throws:
javax.jms.JMSException

recycle

public void recycle(PooledSession pooledSession)
Return a Session to the pool

Parameters:
pooled_session - the session to recycle

shutdown

public void shutdown()
Shutdown the session factory.



Apache CXF