org.apache.commons.messagelet
Class ConsumerThread

java.lang.Object
  extended by java.lang.Thread
      extended by org.apache.commons.messagelet.ConsumerThread
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
XAConsumerThread

public class ConsumerThread
extends Thread

ConsumerThread is a thread which will repeatedly consume JMS messages using a receive() method on Messenger and then process the message. This class is a good base class when implementing some kind of transactional processing of JMS messages

Version:
$Revision: 155459 $
Author:
James Strachan

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ConsumerThread()
           
 
Method Summary
protected  void cancelTransaction()
          Strategy method to represent the code required to cancel a transaction.
protected  void commitTransaction()
          Strategy method to represent the code required to commit a transaction.
protected  javax.jms.MessageConsumer createConsumer()
          Factory method to create a new MessageConsumer
protected  javax.jms.MessageConsumer getConsumer()
           
 javax.jms.Destination getDestination()
          Returns the destination.
 javax.jms.MessageListener getListener()
          Returns the listener.
 Messenger getMessenger()
          Returns the messenger.
 String getSelector()
          Returns the selector.
 boolean isShouldStop()
          Returns the shouldStop.
protected  void processMessage(javax.jms.Message message)
          Strategy method to process a given message.
protected  void rollbackTransaction(Exception e)
          Strategy method to represent the code required to rollback a transaction.
 void run()
          Starts all the JMS connections and consumes JMS messages, passing them onto the MessageListener and Message Driven Objects
 void setDestination(javax.jms.Destination destination)
          Sets the destination.
 void setListener(javax.jms.MessageListener listener)
          Sets the listener.
 void setMessenger(Messenger messenger)
          Sets the messenger.
 void setSelector(String selector)
          Sets the selector.
 void setShouldStop(boolean shouldStop)
          Sets the shouldStop.
protected  void startConsumer()
          Starts consuming messages
protected  void startTransaction()
          Strategy method to represent the code required to start a transaction.
protected  void stopConsumer()
          Stops consuming messages
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConsumerThread

public ConsumerThread()
Method Detail

run

public void run()
Starts all the JMS connections and consumes JMS messages, passing them onto the MessageListener and Message Driven Objects

Specified by:
run in interface Runnable
Overrides:
run in class Thread

getDestination

public javax.jms.Destination getDestination()
Returns the destination.

Returns:
Destination

getListener

public javax.jms.MessageListener getListener()
Returns the listener.

Returns:
MessageListener

getMessenger

public Messenger getMessenger()
Returns the messenger.

Returns:
Messenger

getSelector

public String getSelector()
Returns the selector.

Returns:
String

isShouldStop

public boolean isShouldStop()
Returns the shouldStop.

Returns:
boolean

setDestination

public void setDestination(javax.jms.Destination destination)
Sets the destination.

Parameters:
destination - The destination to set

setListener

public void setListener(javax.jms.MessageListener listener)
Sets the listener.

Parameters:
listener - The listener to set

setMessenger

public void setMessenger(Messenger messenger)
Sets the messenger.

Parameters:
messenger - The messenger to set

setSelector

public void setSelector(String selector)
Sets the selector.

Parameters:
selector - The selector to set

setShouldStop

public void setShouldStop(boolean shouldStop)
Sets the shouldStop.

Parameters:
shouldStop - The shouldStop to set

startConsumer

protected void startConsumer()
                      throws javax.jms.JMSException
Starts consuming messages

Throws:
javax.jms.JMSException

stopConsumer

protected void stopConsumer()
                     throws javax.jms.JMSException
Stops consuming messages

Throws:
javax.jms.JMSException

createConsumer

protected javax.jms.MessageConsumer createConsumer()
                                            throws javax.jms.JMSException
Factory method to create a new MessageConsumer

Throws:
javax.jms.JMSException

processMessage

protected void processMessage(javax.jms.Message message)
                       throws javax.jms.JMSException
Strategy method to process a given message. By default this will just invoke the MessageListener

Throws:
javax.jms.JMSException

startTransaction

protected void startTransaction()
                         throws Exception
Strategy method to represent the code required to start a transaction.

Throws:
Exception

commitTransaction

protected void commitTransaction()
                          throws Exception
Strategy method to represent the code required to commit a transaction.

Throws:
Exception

rollbackTransaction

protected void rollbackTransaction(Exception e)
Strategy method to represent the code required to rollback a transaction.


cancelTransaction

protected void cancelTransaction()
                          throws Exception
Strategy method to represent the code required to cancel a transaction. This is called when a message is not received.

Throws:
Exception

getConsumer

protected javax.jms.MessageConsumer getConsumer()


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