unsw.cse.mica.blackboard
Class QueuedMessageSender

java.lang.Object
  extended by java.lang.Thread
      extended by unsw.cse.mica.blackboard.QueuedMessageSender
All Implemented Interfaces:
java.lang.Runnable, BlackboardMessageSender

public class QueuedMessageSender
extends java.lang.Thread
implements BlackboardMessageSender

A messaging buffer that enqueues incoming message and handles each one sequentially using an internal thread. This helps to retain interactivity for the blackboard when sending mobs.

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
QueuedMessageSender(BlackboardMessageSender sender)
          Create a new QueuedMessageSender that sends to the given sender.
 
Method Summary
 void run()
          The internal thread run method.
 void sendDeletedMob(java.lang.String agentName, Mob mob)
          Send a deleted mob to the given agent.
 void sendNewMob(java.lang.String agentName, Mob mob)
          Send a new mob to the given agent.
 void sendReplacedMob(java.lang.String agentName, Mob oldMob, Mob newMob)
          Send a replaced mob to the given agent.
 void sendTypeManagerChanged(java.lang.String agentName)
          Send a thpe manager changed message to the given agent.
 void terminate()
          Terminate the thread.
 
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

QueuedMessageSender

public QueuedMessageSender(BlackboardMessageSender sender)
Create a new QueuedMessageSender that sends to the given sender. The constructor automaticlly starts the internal thread.

Parameters:
sender -
Method Detail

sendNewMob

public void sendNewMob(java.lang.String agentName,
                       Mob mob)
Send a new mob to the given agent. This method simply adds the message to the internal queue and returns.

Specified by:
sendNewMob in interface BlackboardMessageSender
Parameters:
agentName - the name of the agent for which the message is inteneded
mob - the mob associated with this message

sendDeletedMob

public void sendDeletedMob(java.lang.String agentName,
                           Mob mob)
Send a deleted mob to the given agent. This method simply adds the message to the internal queue and returns.

Specified by:
sendDeletedMob in interface BlackboardMessageSender
Parameters:
agentName - the name of the agent for which the message is inteneded
mob - the mob associated with this message

sendReplacedMob

public void sendReplacedMob(java.lang.String agentName,
                            Mob oldMob,
                            Mob newMob)
Send a replaced mob to the given agent. This method simply adds the message to the internal queue and returns.

Specified by:
sendReplacedMob in interface BlackboardMessageSender
Parameters:
agentName - the name of the agent for which the message is inteneded
oldMob - the oldMob associated with this message
newMob - the newMob associated with this message

sendTypeManagerChanged

public void sendTypeManagerChanged(java.lang.String agentName)
Send a thpe manager changed message to the given agent. This method simply adds the message to the internal queue and returns.

Specified by:
sendTypeManagerChanged in interface BlackboardMessageSender
Parameters:
agentName - the name of the agent for which the message is inteneded

terminate

public void terminate()
Terminate the thread. If the internal thread is currently sending a message, termination will not occur until after the current send is completed.


run

public void run()
The internal thread run method. Do not call directly - this method is only public to satisfy the Runnable interface

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