T - a sub-class of IClientpublic abstract class AbstractMessageProcessor<T extends IClient> extends Thread
The DM is supposed to have only one message processor running.
Same thing for an agent. When the DM or an agent stops, the processor thread should be stopped.
This class is a thread that will process messages. The method stopProcessor() will stop
processing messages after the current message is processed, or right after the next one is received.
For an immediate stop, use the Thread.interrupt() method.
Thread.State, Thread.UncaughtExceptionHandler| Modifier and Type | Field and Description |
|---|---|
protected T |
messagingClient |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY| Constructor and Description |
|---|
AbstractMessageProcessor(String threadName)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
LinkedBlockingQueue<Message> |
getMessageQueue() |
boolean |
isRunning() |
protected abstract void |
processMessage(Message message)
Processes a message.
|
void |
run() |
void |
setMessagingClient(T messagingClient)
This method must be invoked before
Thread.start(). |
void |
stopProcessor()
Stops the processor.
|
void |
storeMessage(Message message)
Stores a message so that it can be processed later.
|
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, yieldpublic AbstractMessageProcessor(String threadName)
threadName - the thread namepublic final void storeMessage(Message message)
message - a message to storepublic LinkedBlockingQueue<Message> getMessageQueue()
public void setMessagingClient(T messagingClient)
Thread.start().
It is not recommended to change the messaging client once the thread has started.
It is better to use a ReconfigurableClient to handle messaging reconfiguration.
messagingClient - the messaging client to setpublic boolean isRunning()
public void stopProcessor()
protected abstract void processMessage(Message message)
message - the message to processCopyright © 2015. All rights reserved.