public class ConsumerThread
extends java.lang.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
| Modifier and Type | Field and Description |
|---|---|
private javax.jms.MessageConsumer |
consumer |
private javax.jms.Destination |
destination |
private javax.jms.MessageListener |
listener |
private static org.apache.commons.logging.Log |
log
Logger
|
private Messenger |
messenger |
private java.lang.String |
selector |
private boolean |
shouldStop |
| Constructor and Description |
|---|
ConsumerThread() |
| Modifier and Type | Method and Description |
|---|---|
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.
|
java.lang.String |
getSelector()
Returns the selector.
|
boolean |
isShouldStop()
Returns the shouldStop.
|
protected void |
processMessage(javax.jms.Message message)
Strategy method to process a given message.
|
private javax.jms.Message |
receive()
Strategy method to consume a message using a receive() kind of method.
|
protected void |
rollbackTransaction(java.lang.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(java.lang.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
|
activeCount, checkAccess, clone, 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, yieldprivate static final org.apache.commons.logging.Log log
private javax.jms.MessageConsumer consumer
private Messenger messenger
private javax.jms.Destination destination
private java.lang.String selector
private javax.jms.MessageListener listener
private boolean shouldStop
public void run()
run in interface java.lang.Runnablerun in class java.lang.Threadpublic javax.jms.Destination getDestination()
public javax.jms.MessageListener getListener()
public Messenger getMessenger()
public java.lang.String getSelector()
public boolean isShouldStop()
public void setDestination(javax.jms.Destination destination)
destination - The destination to setpublic void setListener(javax.jms.MessageListener listener)
listener - The listener to setpublic void setMessenger(Messenger messenger)
messenger - The messenger to setpublic void setSelector(java.lang.String selector)
selector - The selector to setpublic void setShouldStop(boolean shouldStop)
shouldStop - The shouldStop to setprotected void startConsumer()
throws javax.jms.JMSException
javax.jms.JMSExceptionprotected void stopConsumer()
throws javax.jms.JMSException
javax.jms.JMSExceptionprotected javax.jms.MessageConsumer createConsumer()
throws javax.jms.JMSException
javax.jms.JMSExceptionprivate javax.jms.Message receive()
throws javax.jms.JMSException
javax.jms.JMSExceptionprotected void processMessage(javax.jms.Message message)
throws javax.jms.JMSException
javax.jms.JMSExceptionprotected void startTransaction()
throws java.lang.Exception
java.lang.Exceptionprotected void commitTransaction()
throws java.lang.Exception
java.lang.Exceptionprotected void rollbackTransaction(java.lang.Exception e)
protected void cancelTransaction()
throws java.lang.Exception
java.lang.Exceptionprotected javax.jms.MessageConsumer getConsumer()