org.apache.commons.messenger
Class DefaultMessenger

java.lang.Object
  extended by org.apache.commons.messenger.MessengerSupport
      extended by org.apache.commons.messenger.DefaultMessenger
All Implemented Interfaces:
Messenger
Direct Known Subclasses:
XAMessenger

public class DefaultMessenger
extends MessengerSupport

DefaultMessenger is the default implementation of Messenger which uses a ThreadLocal variable to keep the JMS Session that should be used for a given calling thread.

Version:
$Revision: 155459 $
Author:
James Strachan

Constructor Summary
DefaultMessenger()
           
 
Method Summary
protected  MessengerSession borrowMessengerSession()
           
 javax.jms.Message call(javax.jms.Destination destination, javax.jms.Message message)
          Sends a message on the given destination and blocks until a response is returned
 javax.jms.Message call(javax.jms.Destination destination, javax.jms.Message message, long timeoutMillis)
          Sends a message on the given destination and blocks until a response is returned or the given timeout period expires
protected  void clearReplyToDestination()
          Clears the temporary destination used to receive reply-to messages which will lazily force a new destination and consumer to be created next time a call() method is invoked.
 void close()
          Closes the underlying JMS connection
protected  MessengerSession createMessengerSession()
          Factory method to create a new MessengerSession
 javax.jms.ServerSessionPool createServerSessionPool(javax.jms.MessageListener messageListener, int maxThreads)
          Creates a new ServerSessionPool implementation with a given maximum number of threads for use by a ConnectionConsumer
protected  SessionFactory createSessionFactory()
          Factory method to create a SessionFactory.
 javax.jms.Session getAsyncSession()
          Returns the underlying JMS session that this thread is using for this Messenger for asynchronous operation such as addMessageListener() operations
 javax.jms.Connection getConnection()
          Returns the underlying JMS connection that this Messenger is using
protected  MessengerSession getMessengerSession()
           
 javax.jms.Queue getQueue(javax.jms.QueueSession session, String subject)
           
protected  javax.jms.MessageConsumer getReplyToConsumer()
           
protected  javax.jms.Destination getReplyToDestination()
           
 javax.jms.Session getSession()
          Returns the underlying JMS session that this thread is using for synchronous operations such as send() and receive() for synchronous operation
 SessionFactory getSessionFactory()
          Returns the SessionFactory used to create new JMS sessions
 javax.jms.Topic getTopic(javax.jms.TopicSession session, String subject)
           
protected  boolean isTopic(javax.jms.Connection connection)
           
protected  boolean isTopic(javax.jms.ConnectionFactory factory)
           
protected  void returnMessengerSession(MessengerSession session)
           
 void setSessionFactory(SessionFactory sessionFactory)
          Sets the SessionFactory used to create new JMS sessions
 
Methods inherited from class org.apache.commons.messenger.MessengerSupport
addListener, addListener, borrowMessageConsumer, borrowMessageConsumer, commit, createBrowser, createBrowser, createBytesMessage, createConnectionConsumer, createConnectionConsumer, createConsumer, createConsumer, createMapMessage, createMessage, createMessageConsumer, createMessageConsumer, createMessageProducer, createObjectMessage, createObjectMessage, createStreamMessage, createTemporaryDestination, createTextMessage, createTextMessage, getDeliveryMode, getDeliveryMode, getDestination, getDisableMessageID, getDisableMessageTimestamp, getDurableName, getName, getPriority, getTimeToLive, isCacheProducers, isCacheRequestors, isDurable, isJndiDestinations, isNoLocal, receive, receive, receive, receive, receiveNoWait, receiveNoWait, removeListener, removeListener, returnMessageConsumer, rollback, run, send, send, setCacheProducers, setCacheRequestors, setDeliveryMode, setDeliveryMode, setDisableMessageID, setDisableMessageTimestamp, setDurable, setDurableName, setJndiDestinations, setName, setNoLocal, setPersistentDelivery, setPriority, setTimeToLive, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultMessenger

public DefaultMessenger()
Method Detail

getSessionFactory

public SessionFactory getSessionFactory()
                                 throws javax.jms.JMSException
Returns the SessionFactory used to create new JMS sessions

Throws:
javax.jms.JMSException

setSessionFactory

public void setSessionFactory(SessionFactory sessionFactory)
Sets the SessionFactory used to create new JMS sessions


getConnection

public javax.jms.Connection getConnection()
                                   throws javax.jms.JMSException
Description copied from interface: Messenger
Returns the underlying JMS connection that this Messenger is using

Specified by:
getConnection in interface Messenger
Specified by:
getConnection in class MessengerSupport
Throws:
javax.jms.JMSException

createServerSessionPool

public javax.jms.ServerSessionPool createServerSessionPool(javax.jms.MessageListener messageListener,
                                                           int maxThreads)
                                                    throws javax.jms.JMSException
Description copied from interface: Messenger
Creates a new ServerSessionPool implementation with a given maximum number of threads for use by a ConnectionConsumer

Throws:
javax.jms.JMSException

close

public void close()
           throws javax.jms.JMSException
Description copied from interface: Messenger
Closes the underlying JMS connection

Specified by:
close in interface Messenger
Overrides:
close in class MessengerSupport
Throws:
javax.jms.JMSException

getSession

public javax.jms.Session getSession()
                             throws javax.jms.JMSException
Description copied from interface: Messenger
Returns the underlying JMS session that this thread is using for synchronous operations such as send() and receive() for synchronous operation

Throws:
javax.jms.JMSException

getAsyncSession

public javax.jms.Session getAsyncSession()
                                  throws javax.jms.JMSException
Description copied from interface: Messenger
Returns the underlying JMS session that this thread is using for this Messenger for asynchronous operation such as addMessageListener() operations

Throws:
javax.jms.JMSException

call

public javax.jms.Message call(javax.jms.Destination destination,
                              javax.jms.Message message)
                       throws javax.jms.JMSException
Description copied from interface: Messenger
Sends a message on the given destination and blocks until a response is returned

Throws:
javax.jms.JMSException

call

public javax.jms.Message call(javax.jms.Destination destination,
                              javax.jms.Message message,
                              long timeoutMillis)
                       throws javax.jms.JMSException
Description copied from interface: Messenger
Sends a message on the given destination and blocks until a response is returned or the given timeout period expires

Throws:
javax.jms.JMSException

isTopic

protected boolean isTopic(javax.jms.Connection connection)
                   throws javax.jms.JMSException
Specified by:
isTopic in class MessengerSupport
Throws:
javax.jms.JMSException

isTopic

protected boolean isTopic(javax.jms.ConnectionFactory factory)
                   throws javax.jms.JMSException
Specified by:
isTopic in class MessengerSupport
Throws:
javax.jms.JMSException

getReplyToConsumer

protected javax.jms.MessageConsumer getReplyToConsumer()
                                                throws javax.jms.JMSException
Returns:
the MessageConsumer for this threads temporary destination which is cached for the duration of this process.
Throws:
javax.jms.JMSException

clearReplyToDestination

protected void clearReplyToDestination()
                                throws javax.jms.JMSException
Clears the temporary destination used to receive reply-to messages which will lazily force a new destination and consumer to be created next time a call() method is invoked.

Throws:
javax.jms.JMSException

getReplyToDestination

protected javax.jms.Destination getReplyToDestination()
                                               throws javax.jms.JMSException
Throws:
javax.jms.JMSException

getMessengerSession

protected MessengerSession getMessengerSession()
                                        throws javax.jms.JMSException
Throws:
javax.jms.JMSException

borrowMessengerSession

protected MessengerSession borrowMessengerSession()
                                           throws javax.jms.JMSException
Specified by:
borrowMessengerSession in class MessengerSupport
Throws:
javax.jms.JMSException

returnMessengerSession

protected void returnMessengerSession(MessengerSession session)
Specified by:
returnMessengerSession in class MessengerSupport

createMessengerSession

protected MessengerSession createMessengerSession()
                                           throws javax.jms.JMSException
Factory method to create a new MessengerSession

Throws:
javax.jms.JMSException

createSessionFactory

protected SessionFactory createSessionFactory()
                                       throws javax.jms.JMSException
Factory method to create a SessionFactory. Derived classes could override this method to create the SessionFactory from a well known place

Throws:
javax.jms.JMSException

getQueue

public javax.jms.Queue getQueue(javax.jms.QueueSession session,
                                String subject)
                         throws javax.jms.JMSException
Overrides:
getQueue in class MessengerSupport
Throws:
javax.jms.JMSException

getTopic

public javax.jms.Topic getTopic(javax.jms.TopicSession session,
                                String subject)
                         throws javax.jms.JMSException
Overrides:
getTopic in class MessengerSupport
Throws:
javax.jms.JMSException


Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.