org.apache.commons.messenger
Class MessengerSupport

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

public abstract class MessengerSupport
extends Object
implements Messenger

MessengerSupport is an abstract base class which implements most of the functionality of Messenger. Derivations need to specify the connection and session creation and the pooling strategy.

Version:
$Revision: 155459 $
Author:
James Strachan

Constructor Summary
MessengerSupport()
           
 
Method Summary
 void addListener(javax.jms.Destination destination, javax.jms.MessageListener listener)
          Adds a message listener on the given destination
 void addListener(javax.jms.Destination destination, String selector, javax.jms.MessageListener listener)
           
protected  javax.jms.MessageConsumer borrowMessageConsumer(MessengerSession messengerSession, javax.jms.Session session, javax.jms.Destination destination)
           
protected  javax.jms.MessageConsumer borrowMessageConsumer(MessengerSession messengerSession, javax.jms.Session session, javax.jms.Destination destination, String selector)
           
protected abstract  MessengerSession borrowMessengerSession()
           
 void close()
          Closes the underlying JMS connection
 void commit()
          Commits all messages done in this thread and releases any locks
 javax.jms.QueueBrowser createBrowser(javax.jms.Destination destination)
          Creates a browser on the given Queue
protected  javax.jms.QueueBrowser createBrowser(MessengerSession session, javax.jms.Destination destination)
           
 javax.jms.BytesMessage createBytesMessage()
           
 javax.jms.ConnectionConsumer createConnectionConsumer(javax.jms.Destination destination, javax.jms.ServerSessionPool sessionPool, int maxMessages)
          Creates a ConnectionConsumer which is useful if used inside an application server to associate multiple threads with consuming from a JMS destination
 javax.jms.ConnectionConsumer createConnectionConsumer(javax.jms.Destination destination, String selector, javax.jms.ServerSessionPool sessionPool, int maxMessages)
          Creates a ConnectionConsumer which is useful if used inside an application server to associate multiple threads with consuming from a JMS destination
 javax.jms.MessageConsumer createConsumer(javax.jms.Destination destination)
          Creates a MessageConsumer for the given JMS Desintation
 javax.jms.MessageConsumer createConsumer(javax.jms.Destination destination, String selector)
          Creates a MessageConsumer for the given JMS Desintation and JMS selector
 javax.jms.MapMessage createMapMessage()
           
 javax.jms.Message createMessage()
           
protected  javax.jms.MessageConsumer createMessageConsumer(MessengerSession messengerSession, javax.jms.Session session, javax.jms.Destination destination)
           
protected  javax.jms.MessageConsumer createMessageConsumer(MessengerSession messengerSession, javax.jms.Session session, javax.jms.Destination destination, String selector)
           
protected  javax.jms.MessageProducer createMessageProducer(MessengerSession messengerSession, javax.jms.Destination destination)
           
 javax.jms.ObjectMessage createObjectMessage()
           
 javax.jms.ObjectMessage createObjectMessage(Serializable object)
           
 javax.jms.StreamMessage createStreamMessage()
           
 javax.jms.Destination createTemporaryDestination()
          Returns a new temporary destination
 javax.jms.TextMessage createTextMessage()
           
 javax.jms.TextMessage createTextMessage(String text)
           
abstract  javax.jms.Connection getConnection()
          Returns the underlying JMS connection that this Messenger is using
 int getDeliveryMode()
          Returns the delivery mode used on messages sent via this Messenger
 int getDeliveryMode(javax.jms.Destination destination)
          Get the producer's default delivery mode.
 javax.jms.Destination getDestination(String subject)
          Returns the destination for the given subject name
 boolean getDisableMessageID(javax.jms.Destination destination)
          Get an indication of whether message IDs are disabled.
 boolean getDisableMessageTimestamp(javax.jms.Destination destination)
          Get an indication of whether message timestamps are disabled.
 String getDurableName()
           
 String getName()
          Gets the name that this Messenger is called in a MessengerManager
 int getPriority(javax.jms.Destination destination)
          Get the producer's default priority.
protected  javax.jms.Queue getQueue(javax.jms.QueueSession session, String subject)
           
 long getTimeToLive(javax.jms.Destination destination)
          Get the producer's default delivery mode.
protected  javax.jms.Topic getTopic(javax.jms.TopicSession session, String subject)
           
 boolean isCacheProducers()
          Gets whether MessageProducer instances should be cached or not, which defaults to true
 boolean isCacheRequestors()
          Gets whether we should cache the requestor object per thread?
 boolean isDurable()
          Gets whether topic subscribers are durable or not
 boolean isJndiDestinations()
          Getter for jndiDestinations
 boolean isNoLocal()
          Gets whether local messages are ignored when topic based subscription is used with a message selector
protected abstract  boolean isTopic(javax.jms.Connection connection)
           
protected abstract  boolean isTopic(javax.jms.ConnectionFactory factory)
           
 javax.jms.Message receive(javax.jms.Destination destination)
          Receives a message on the given destination, blocking until one is returned
 javax.jms.Message receive(javax.jms.Destination destination, long timeoutMillis)
          Receives a message on the given destination, blocking for the specified timeout
 javax.jms.Message receive(javax.jms.Destination destination, String selector)
          Receives a message on the given destination and message selector, blocking until one is returned
 javax.jms.Message receive(javax.jms.Destination destination, String selector, long timeoutMillis)
          Receives a message on the given destination and selector, blocking for the specified timeout
 javax.jms.Message receiveNoWait(javax.jms.Destination destination)
          Receives a message on the given destination without blocking or returns null
 javax.jms.Message receiveNoWait(javax.jms.Destination destination, String selector)
          Receives a message on the given destination and selector without blocking or returns null
 void removeListener(javax.jms.Destination destination, javax.jms.MessageListener listener)
           
 void removeListener(javax.jms.Destination destination, String selector, javax.jms.MessageListener listener)
           
protected  void returnMessageConsumer(javax.jms.MessageConsumer messageConsumer)
          Returns a message consumer back to the pool.
protected abstract  void returnMessengerSession(MessengerSession session)
           
 void rollback()
          Rolls back any messages done in this thread and releases any locks
 void run()
          Allows this current thread to be given to the JMS connection to process messages.
 void send(javax.jms.Destination destination, javax.jms.Message message)
          Sends a message on the given destination
 void send(javax.jms.Destination destination, javax.jms.Message message, int deliveryMode, int priority, long timeToLive)
          Extends the send capability to send by specifying additional options.
 void setCacheProducers(boolean cacheProducers)
          Sets whether MessageProducer instances should be cached or not, which defaults to true
 void setCacheRequestors(boolean cacheRequestors)
          Sets whether we should cache the requestor object per thread?
 void setDeliveryMode(javax.jms.Destination destination, int deliveryMode)
          Set the producer's default delivery mode.
 void setDeliveryMode(int deliveryMode)
          Sets the delivery mode used on messages sent via this Messenger
 void setDisableMessageID(javax.jms.Destination destination, boolean value)
          Set whether message IDs are disabled.
 void setDisableMessageTimestamp(javax.jms.Destination destination, boolean value)
          Set whether message timestamps are disabled.
 void setDurable(boolean durable)
          Sets whether topic subscribers are durable or not
 void setDurableName(String durableName)
          Sets the durable name used for durable topic based subscriptions
 void setJndiDestinations(boolean jndiDestinations)
          Setter for jndiDestinations
 void setName(String name)
          Sets the name that this Messenger is called in a MessengerManager
 void setNoLocal(boolean noLocal)
          Sets whether local messages are ignored when topic based subscription is used with a message selector
 void setPersistentDelivery(boolean persistentDelivery)
          Sets whether message delivery should be persistent or not
 void setPriority(javax.jms.Destination destination, int priority)
          Set the producer's default priority.
 void setTimeToLive(javax.jms.Destination destination, long timeToLive)
          Set the default length of time in milliseconds from its dispatch time that a produced message should be retained by the message system.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.commons.messenger.Messenger
call, call, createServerSessionPool, getAsyncSession, getSession, getSessionFactory
 

Constructor Detail

MessengerSupport

public MessengerSupport()
Method Detail

toString

public String toString()
Overrides:
toString in class Object

getDestination

public javax.jms.Destination getDestination(String subject)
                                     throws javax.jms.JMSException
Description copied from interface: Messenger
Returns the destination for the given subject name

Specified by:
getDestination in interface Messenger
Throws:
javax.jms.JMSException

createTemporaryDestination

public javax.jms.Destination createTemporaryDestination()
                                                 throws javax.jms.JMSException
Description copied from interface: Messenger
Returns a new temporary destination

Specified by:
createTemporaryDestination in interface Messenger
Throws:
javax.jms.JMSException

send

public void send(javax.jms.Destination destination,
                 javax.jms.Message message)
          throws javax.jms.JMSException
Description copied from interface: Messenger
Sends a message on the given destination

Specified by:
send in interface Messenger
Throws:
javax.jms.JMSException

receive

public javax.jms.Message receive(javax.jms.Destination destination)
                          throws javax.jms.JMSException
Description copied from interface: Messenger
Receives a message on the given destination, blocking until one is returned

Specified by:
receive in interface Messenger
Throws:
javax.jms.JMSException

receive

public javax.jms.Message receive(javax.jms.Destination destination,
                                 String selector)
                          throws javax.jms.JMSException
Description copied from interface: Messenger
Receives a message on the given destination and message selector, blocking until one is returned

Specified by:
receive in interface Messenger
Throws:
javax.jms.JMSException

receive

public javax.jms.Message receive(javax.jms.Destination destination,
                                 long timeoutMillis)
                          throws javax.jms.JMSException
Description copied from interface: Messenger
Receives a message on the given destination, blocking for the specified timeout

Specified by:
receive in interface Messenger
Throws:
javax.jms.JMSException

receive

public javax.jms.Message receive(javax.jms.Destination destination,
                                 String selector,
                                 long timeoutMillis)
                          throws javax.jms.JMSException
Description copied from interface: Messenger
Receives a message on the given destination and selector, blocking for the specified timeout

Specified by:
receive in interface Messenger
Throws:
javax.jms.JMSException

receiveNoWait

public javax.jms.Message receiveNoWait(javax.jms.Destination destination)
                                throws javax.jms.JMSException
Description copied from interface: Messenger
Receives a message on the given destination without blocking or returns null

Specified by:
receiveNoWait in interface Messenger
Throws:
javax.jms.JMSException

receiveNoWait

public javax.jms.Message receiveNoWait(javax.jms.Destination destination,
                                       String selector)
                                throws javax.jms.JMSException
Description copied from interface: Messenger
Receives a message on the given destination and selector without blocking or returns null

Specified by:
receiveNoWait in interface Messenger
Throws:
javax.jms.JMSException

createConsumer

public javax.jms.MessageConsumer createConsumer(javax.jms.Destination destination)
                                         throws javax.jms.JMSException
Description copied from interface: Messenger
Creates a MessageConsumer for the given JMS Desintation

Specified by:
createConsumer in interface Messenger
Throws:
javax.jms.JMSException

createConsumer

public javax.jms.MessageConsumer createConsumer(javax.jms.Destination destination,
                                                String selector)
                                         throws javax.jms.JMSException
Description copied from interface: Messenger
Creates a MessageConsumer for the given JMS Desintation and JMS selector

Specified by:
createConsumer in interface Messenger
Throws:
javax.jms.JMSException

run

public void run()
Description copied from interface: Messenger
Allows this current thread to be given to the JMS connection to process messages. This method can be useful for creating background processing threads

Specified by:
run in interface Messenger

createConnectionConsumer

public javax.jms.ConnectionConsumer createConnectionConsumer(javax.jms.Destination destination,
                                                             javax.jms.ServerSessionPool sessionPool,
                                                             int maxMessages)
                                                      throws javax.jms.JMSException
Description copied from interface: Messenger
Creates a ConnectionConsumer which is useful if used inside an application server to associate multiple threads with consuming from a JMS destination

Specified by:
createConnectionConsumer in interface Messenger
Throws:
javax.jms.JMSException

createConnectionConsumer

public javax.jms.ConnectionConsumer createConnectionConsumer(javax.jms.Destination destination,
                                                             String selector,
                                                             javax.jms.ServerSessionPool sessionPool,
                                                             int maxMessages)
                                                      throws javax.jms.JMSException
Description copied from interface: Messenger
Creates a ConnectionConsumer which is useful if used inside an application server to associate multiple threads with consuming from a JMS destination

Specified by:
createConnectionConsumer in interface Messenger
Throws:
javax.jms.JMSException

getConnection

public abstract 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
Throws:
javax.jms.JMSException

addListener

public void addListener(javax.jms.Destination destination,
                        javax.jms.MessageListener listener)
                 throws javax.jms.JMSException
Description copied from interface: Messenger
Adds a message listener on the given destination

Specified by:
addListener in interface Messenger
Throws:
javax.jms.JMSException

addListener

public void addListener(javax.jms.Destination destination,
                        String selector,
                        javax.jms.MessageListener listener)
                 throws javax.jms.JMSException
Specified by:
addListener in interface Messenger
Throws:
javax.jms.JMSException

removeListener

public void removeListener(javax.jms.Destination destination,
                           javax.jms.MessageListener listener)
                    throws javax.jms.JMSException
Specified by:
removeListener in interface Messenger
Throws:
javax.jms.JMSException

removeListener

public void removeListener(javax.jms.Destination destination,
                           String selector,
                           javax.jms.MessageListener listener)
                    throws javax.jms.JMSException
Specified by:
removeListener in interface Messenger
Throws:
javax.jms.JMSException

createBytesMessage

public javax.jms.BytesMessage createBytesMessage()
                                          throws javax.jms.JMSException
Specified by:
createBytesMessage in interface Messenger
Throws:
javax.jms.JMSException

createMapMessage

public javax.jms.MapMessage createMapMessage()
                                      throws javax.jms.JMSException
Specified by:
createMapMessage in interface Messenger
Throws:
javax.jms.JMSException

createMessage

public javax.jms.Message createMessage()
                                throws javax.jms.JMSException
Specified by:
createMessage in interface Messenger
Throws:
javax.jms.JMSException

createObjectMessage

public javax.jms.ObjectMessage createObjectMessage()
                                            throws javax.jms.JMSException
Specified by:
createObjectMessage in interface Messenger
Throws:
javax.jms.JMSException

createObjectMessage

public javax.jms.ObjectMessage createObjectMessage(Serializable object)
                                            throws javax.jms.JMSException
Specified by:
createObjectMessage in interface Messenger
Throws:
javax.jms.JMSException

createStreamMessage

public javax.jms.StreamMessage createStreamMessage()
                                            throws javax.jms.JMSException
Specified by:
createStreamMessage in interface Messenger
Throws:
javax.jms.JMSException

createTextMessage

public javax.jms.TextMessage createTextMessage()
                                        throws javax.jms.JMSException
Specified by:
createTextMessage in interface Messenger
Throws:
javax.jms.JMSException

createTextMessage

public javax.jms.TextMessage createTextMessage(String text)
                                        throws javax.jms.JMSException
Specified by:
createTextMessage in interface Messenger
Throws:
javax.jms.JMSException

commit

public void commit()
            throws javax.jms.JMSException
Description copied from interface: Messenger
Commits all messages done in this thread and releases any locks

Specified by:
commit in interface Messenger
Throws:
javax.jms.JMSException

rollback

public void rollback()
              throws javax.jms.JMSException
Description copied from interface: Messenger
Rolls back any messages done in this thread and releases any locks

Specified by:
rollback in interface Messenger
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
Throws:
javax.jms.JMSException

createBrowser

public javax.jms.QueueBrowser createBrowser(javax.jms.Destination destination)
                                     throws javax.jms.JMSException
Creates a browser on the given Queue

Specified by:
createBrowser in interface Messenger
Throws:
javax.jms.JMSException

getDeliveryMode

public int getDeliveryMode(javax.jms.Destination destination)
                    throws javax.jms.JMSException
Get the producer's default delivery mode.

Specified by:
getDeliveryMode in interface Messenger
Throws:
javax.jms.JMSException

setDeliveryMode

public void setDeliveryMode(javax.jms.Destination destination,
                            int deliveryMode)
                     throws javax.jms.JMSException
Set the producer's default delivery mode.

Specified by:
setDeliveryMode in interface Messenger
Throws:
javax.jms.JMSException

getPriority

public int getPriority(javax.jms.Destination destination)
                throws javax.jms.JMSException
Get the producer's default priority.

Specified by:
getPriority in interface Messenger
Throws:
javax.jms.JMSException

setPriority

public void setPriority(javax.jms.Destination destination,
                        int priority)
                 throws javax.jms.JMSException
Set the producer's default priority.

Specified by:
setPriority in interface Messenger
Throws:
javax.jms.JMSException

getTimeToLive

public long getTimeToLive(javax.jms.Destination destination)
                   throws javax.jms.JMSException
Get the producer's default delivery mode.

Specified by:
getTimeToLive in interface Messenger
Throws:
javax.jms.JMSException

setTimeToLive

public void setTimeToLive(javax.jms.Destination destination,
                          long timeToLive)
                   throws javax.jms.JMSException

Set the default length of time in milliseconds from its dispatch time that a produced message should be retained by the message system.

Specified by:
setTimeToLive in interface Messenger
Throws:
javax.jms.JMSException

getDisableMessageTimestamp

public boolean getDisableMessageTimestamp(javax.jms.Destination destination)
                                   throws javax.jms.JMSException
Get an indication of whether message timestamps are disabled.

Specified by:
getDisableMessageTimestamp in interface Messenger
Throws:
javax.jms.JMSException

setDisableMessageTimestamp

public void setDisableMessageTimestamp(javax.jms.Destination destination,
                                       boolean value)
                                throws javax.jms.JMSException
Set whether message timestamps are disabled.

Specified by:
setDisableMessageTimestamp in interface Messenger
Throws:
javax.jms.JMSException

send

public void send(javax.jms.Destination destination,
                 javax.jms.Message message,
                 int deliveryMode,
                 int priority,
                 long timeToLive)
          throws javax.jms.JMSException
Extends the send capability to send by specifying additional options.

Throws:
javax.jms.JMSException

getDisableMessageID

public boolean getDisableMessageID(javax.jms.Destination destination)
                            throws javax.jms.JMSException
Get an indication of whether message IDs are disabled.

Specified by:
getDisableMessageID in interface Messenger
Throws:
javax.jms.JMSException

setDisableMessageID

public void setDisableMessageID(javax.jms.Destination destination,
                                boolean value)
                         throws javax.jms.JMSException
Set whether message IDs are disabled.

Specified by:
setDisableMessageID in interface Messenger
Throws:
javax.jms.JMSException

getName

public String getName()
Gets the name that this Messenger is called in a MessengerManager

Specified by:
getName in interface Messenger

setName

public void setName(String name)
Sets the name that this Messenger is called in a MessengerManager


setJndiDestinations

public void setJndiDestinations(boolean jndiDestinations)
Setter for jndiDestinations


isJndiDestinations

public boolean isJndiDestinations()
Getter for jndiDestinations


isDurable

public boolean isDurable()
Gets whether topic subscribers are durable or not


setDurable

public void setDurable(boolean durable)
Sets whether topic subscribers are durable or not


isCacheRequestors

public boolean isCacheRequestors()
Gets whether we should cache the requestor object per thread?


setCacheRequestors

public void setCacheRequestors(boolean cacheRequestors)
Sets whether we should cache the requestor object per thread?


getDurableName

public String getDurableName()
Returns:
the durable name used for durable topic based subscriptions

setDurableName

public void setDurableName(String durableName)
Sets the durable name used for durable topic based subscriptions


isNoLocal

public boolean isNoLocal()
Gets whether local messages are ignored when topic based subscription is used with a message selector


setNoLocal

public void setNoLocal(boolean noLocal)
Sets whether local messages are ignored when topic based subscription is used with a message selector


isCacheProducers

public boolean isCacheProducers()
Gets whether MessageProducer instances should be cached or not, which defaults to true


setCacheProducers

public void setCacheProducers(boolean cacheProducers)
Sets whether MessageProducer instances should be cached or not, which defaults to true


getDeliveryMode

public int getDeliveryMode()
Returns the delivery mode used on messages sent via this Messenger

Returns:
int

setDeliveryMode

public void setDeliveryMode(int deliveryMode)
Sets the delivery mode used on messages sent via this Messenger

Parameters:
deliveryMode - The deliveryMode to set

setPersistentDelivery

public void setPersistentDelivery(boolean persistentDelivery)
Sets whether message delivery should be persistent or not

Parameters:
persistentDelivery -

borrowMessengerSession

protected abstract MessengerSession borrowMessengerSession()
                                                    throws javax.jms.JMSException
Throws:
javax.jms.JMSException

returnMessengerSession

protected abstract void returnMessengerSession(MessengerSession session)

isTopic

protected abstract boolean isTopic(javax.jms.Connection connection)
                            throws javax.jms.JMSException
Throws:
javax.jms.JMSException

isTopic

protected abstract boolean isTopic(javax.jms.ConnectionFactory factory)
                            throws javax.jms.JMSException
Throws:
javax.jms.JMSException

createMessageProducer

protected javax.jms.MessageProducer createMessageProducer(MessengerSession messengerSession,
                                                          javax.jms.Destination destination)
                                                   throws javax.jms.JMSException
Returns:
a newly created message producer for the given session and destination
Throws:
javax.jms.JMSException

borrowMessageConsumer

protected javax.jms.MessageConsumer borrowMessageConsumer(MessengerSession messengerSession,
                                                          javax.jms.Session session,
                                                          javax.jms.Destination destination)
                                                   throws javax.jms.JMSException
Returns:
a MessageConsumer for the given session and destination
Throws:
javax.jms.JMSException

borrowMessageConsumer

protected javax.jms.MessageConsumer borrowMessageConsumer(MessengerSession messengerSession,
                                                          javax.jms.Session session,
                                                          javax.jms.Destination destination,
                                                          String selector)
                                                   throws javax.jms.JMSException
Returns:
a MessageConsumer for the given session, destination and selector
Throws:
javax.jms.JMSException

returnMessageConsumer

protected void returnMessageConsumer(javax.jms.MessageConsumer messageConsumer)
                              throws javax.jms.JMSException
Returns a message consumer back to the pool. By default this method will close message consumers though we should be able to cache then

Throws:
javax.jms.JMSException

createMessageConsumer

protected javax.jms.MessageConsumer createMessageConsumer(MessengerSession messengerSession,
                                                          javax.jms.Session session,
                                                          javax.jms.Destination destination)
                                                   throws javax.jms.JMSException
Returns:
a new MessageConsumer for the given session and destination
Throws:
javax.jms.JMSException

createMessageConsumer

protected javax.jms.MessageConsumer createMessageConsumer(MessengerSession messengerSession,
                                                          javax.jms.Session session,
                                                          javax.jms.Destination destination,
                                                          String selector)
                                                   throws javax.jms.JMSException
Returns:
a new MessageConsumer for the given session, destination and selector
Throws:
javax.jms.JMSException

createBrowser

protected javax.jms.QueueBrowser createBrowser(MessengerSession session,
                                               javax.jms.Destination destination)
                                        throws javax.jms.JMSException
Returns:
a new QueueBrowser for the given session and destination
Throws:
javax.jms.JMSException

getQueue

protected javax.jms.Queue getQueue(javax.jms.QueueSession session,
                                   String subject)
                            throws javax.jms.JMSException
Throws:
javax.jms.JMSException

getTopic

protected javax.jms.Topic getTopic(javax.jms.TopicSession session,
                                   String subject)
                            throws javax.jms.JMSException
Throws:
javax.jms.JMSException


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