unsw.cse.mica.agent
Class QueuedMessageHandler

java.lang.Object
  extended by java.lang.Thread
      extended by unsw.cse.mica.agent.QueuedMessageHandler
All Implemented Interfaces:
java.lang.Runnable, MessageHandler

public class QueuedMessageHandler
extends java.lang.Thread
implements MessageHandler

A message handler class that enqueues incoming messages and processes them sequentially This class is used internally by transports as a way of ensuring that blackboard messages are handled without blocking the protocol.

Author:
jhw

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
QueuedMessageHandler(MessageHandler messageHandler, java.lang.String handlerName)
          Create a new QueuedMessageHandler with the given name and sink handler.
 
Method Summary
 void handleDeletedMob(Mob mob)
          handle a deleted mob message.
 void handleNewMob(Mob mob)
          handle a new mob message.
 void handleReplacedMob(Mob oldMob, Mob newMob)
          handle a replaced mob message.
 void handleTypeManagerChanged()
          handle an incoming mob message.
 void run()
          The run method for the internal thread.
 void setHandlerName(java.lang.String handlerName)
           
 void terminate()
          Terminate the enqueued handler.
 
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
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

QueuedMessageHandler

public QueuedMessageHandler(MessageHandler messageHandler,
                            java.lang.String handlerName)
Create a new QueuedMessageHandler with the given name and sink handler. An internal thread which will be responsible for dequeueing and processing enqueued messages.

Parameters:
messageHandler - The handler to which messages are passed when dequeued.
handlerName - the name for this handler
Method Detail

setHandlerName

public void setHandlerName(java.lang.String handlerName)

handleNewMob

public void handleNewMob(Mob mob)
handle a new mob message. This method simply adds the message to the queue.

Specified by:
handleNewMob in interface MessageHandler
Parameters:
mob - the mob that has been written to the blackboard

handleDeletedMob

public void handleDeletedMob(Mob mob)
handle a deleted mob message. This method simply adds the message to the queue.

Specified by:
handleDeletedMob in interface MessageHandler
Parameters:
mob - the mob that has been deleted

handleReplacedMob

public void handleReplacedMob(Mob oldMob,
                              Mob newMob)
handle a replaced mob message. This method simply adds the message to the queue.

Specified by:
handleReplacedMob in interface MessageHandler
Parameters:
oldMob - the old value of the mob (where the name is cleared)
newMob - the new value of the mob

handleTypeManagerChanged

public void handleTypeManagerChanged()
handle an incoming mob message. This method simply adds the message to the queue.

Specified by:
handleTypeManagerChanged in interface MessageHandler

terminate

public void terminate()
Terminate the enqueued handler. If the internal thread is currently idle, it stops immediately. If the thread is handling a message, it terminates on completion of handling that message, and any remaining messages are lost.


run

public void run()
The run method for the internal thread. Do not call this method, it is only public because the Runnable interface demands it.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread