org.apache.uima.adapter.jms.client
Class BaseMessageSender

java.lang.Object
  extended by org.apache.uima.adapter.jms.client.BaseMessageSender
All Implemented Interfaces:
java.lang.Runnable, MessageSender
Direct Known Subclasses:
ActiveMQMessageSender

public abstract class BaseMessageSender
extends java.lang.Object
implements java.lang.Runnable, MessageSender

Creates a worker thread for sending messages. This is an abstract implementation that provides a thread with run logic. The concrete implementation of the Worker Thread must extend this class. The application threads share a special in-memory queue with this worker thread. The application threads add jms messages to the pendingMessageList queue and the worker thread consumes them. The worker thread terminates when the uima ee client calls doStop() method.


Field Summary
protected  boolean done
           
protected  BaseUIMAAsynchronousEngineCommon_impl engine
           
protected  java.lang.Exception exception
           
protected  java.util.concurrent.BlockingQueue<PendingMessage> messageQueue
           
protected  boolean workerThreadFailed
           
 
Constructor Summary
BaseMessageSender(BaseUIMAAsynchronousEngineCommon_impl anEngine)
           
 
Method Summary
protected abstract  void cleanup()
           
 void doStop()
          Stops the worker thread
 boolean failed()
          The uima ee client should call this method to check if there was a failure.
protected abstract  java.lang.String getDestinationEndpoint()
           
abstract  javax.jms.MessageProducer getMessageProducer()
           
 javax.jms.MessageProducer getMessageProducer(javax.jms.Destination destination)
           
 java.lang.Exception getReasonForFailure()
          Return the Exception that caused the failure in this worker thread
protected abstract  void initializeProducer()
           
 void run()
          Initializes jms message producer and starts the main thread.
abstract  void setConnection(javax.jms.Connection connection)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.uima.adapter.jms.client.MessageSender
createBytesMessage, createTextMessage
 

Field Detail

messageQueue

protected java.util.concurrent.BlockingQueue<PendingMessage> messageQueue

done

protected volatile boolean done

engine

protected BaseUIMAAsynchronousEngineCommon_impl engine

workerThreadFailed

protected volatile boolean workerThreadFailed

exception

protected java.lang.Exception exception
Constructor Detail

BaseMessageSender

public BaseMessageSender(BaseUIMAAsynchronousEngineCommon_impl anEngine)
Method Detail

getMessageProducer

public abstract javax.jms.MessageProducer getMessageProducer()
Specified by:
getMessageProducer in interface MessageSender

initializeProducer

protected abstract void initializeProducer()
                                    throws java.lang.Exception
Throws:
java.lang.Exception

cleanup

protected abstract void cleanup()
                         throws java.lang.Exception
Throws:
java.lang.Exception

getDestinationEndpoint

protected abstract java.lang.String getDestinationEndpoint()
                                                    throws java.lang.Exception
Throws:
java.lang.Exception

setConnection

public abstract void setConnection(javax.jms.Connection connection)
Specified by:
setConnection in interface MessageSender

doStop

public void doStop()
Stops the worker thread

Specified by:
doStop in interface MessageSender

getReasonForFailure

public java.lang.Exception getReasonForFailure()
Return the Exception that caused the failure in this worker thread

Specified by:
getReasonForFailure in interface MessageSender
Returns:
- Exception

failed

public boolean failed()
The uima ee client should call this method to check if there was a failure. The method returns true if there was a failure or false otherwise. If true, the uima ee client can call getReasonForFailure() to get the reason for failure

Specified by:
failed in interface MessageSender

run

public void run()
Initializes jms message producer and starts the main thread. This thread waits for messages enqueued by application threads. The application thread adds a jms message to the pendingMessageList 'queue' and signals this worker that there is a new message. The worker thread removes the message and sends it out to a given destination. All messages should be fully initialized The worker thread does check the message nor adds anything new to the message. It just sends it out.

Specified by:
run in interface java.lang.Runnable

getMessageProducer

public javax.jms.MessageProducer getMessageProducer(javax.jms.Destination destination)
                                             throws java.lang.Exception
Specified by:
getMessageProducer in interface MessageSender
Throws:
java.lang.Exception


Copyright © 2012. All Rights Reserved.