org.commonreality.sensors.handlers
Class EfferentCommandHandler

java.lang.Object
  extended by org.commonreality.sensors.handlers.EfferentCommandHandler
All Implemented Interfaces:
IEfferentCommandListener, ICommonRealityListener, IObjectListener<IEfferentCommand>

public class EfferentCommandHandler
extends java.lang.Object
implements IEfferentCommandListener

general handler to deal with IEfferentCommands. After instantiating a sensor, this can be attached to the IEfferentCommandManager by using the constructor and providing the appropriate Executor.
By default, all methods ignore all IEfferentCommands. To change this behavior override any of the shouldXXXX methods. If you overload the actual state change methods, be sure to call the super method as well as it invariably sets specific state variables in the IEfferentCommand. At the termination of a command's run be sure to call the completed(IEfferentCommand, Object) or aborted(IEfferentCommand, Object) methods.

The processing of efferent commands should usually be done on the thread that received the event (the io executor). This is because most participants expect that the state change requests will be processed immediately, as opposed to queued up on a clock limited thread. The easiest way to do this is to set the Executor to be InlineExecutor.get().

Author:
harrison

Constructor Summary
EfferentCommandHandler(ISensor sensor)
           
 
Method Summary
 void aborted(IEfferentCommand command, java.lang.Object extraInfo)
          called when a command is aborted on the sensor side (not at the request of the agent).
 void add(ICommandHandlerDelegate delegate)
           
 void completed(IEfferentCommand command, java.lang.Object extraInfo)
          called upon the completion of a command
 java.util.Collection<ICommandHandlerDelegate> getDelegates()
           
 ISensor getSensor()
           
 void objectsAdded(IObjectEvent<IEfferentCommand,?> addEvent)
           
 void objectsRemoved(IObjectEvent<IEfferentCommand,?> removeEvent)
           
 void objectsUpdated(IObjectEvent<IEfferentCommand,?> updateEvent)
           
 void processNewEfferentCommand(IEfferentCommand command)
          process a new efferent command, checking shouldAccept(IEfferentCommand) and either accept(DeltaTracker) or #reject(DeltaTracker)
 void remove(ICommandHandlerDelegate delegate)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EfferentCommandHandler

public EfferentCommandHandler(ISensor sensor)
Method Detail

getDelegates

public java.util.Collection<ICommandHandlerDelegate> getDelegates()

add

public void add(ICommandHandlerDelegate delegate)

remove

public void remove(ICommandHandlerDelegate delegate)

getSensor

public ISensor getSensor()

objectsAdded

public void objectsAdded(IObjectEvent<IEfferentCommand,?> addEvent)
Specified by:
objectsAdded in interface IObjectListener<IEfferentCommand>

objectsRemoved

public void objectsRemoved(IObjectEvent<IEfferentCommand,?> removeEvent)
Specified by:
objectsRemoved in interface IObjectListener<IEfferentCommand>

objectsUpdated

public void objectsUpdated(IObjectEvent<IEfferentCommand,?> updateEvent)
Specified by:
objectsUpdated in interface IObjectListener<IEfferentCommand>

processNewEfferentCommand

public void processNewEfferentCommand(IEfferentCommand command)
process a new efferent command, checking shouldAccept(IEfferentCommand) and either accept(DeltaTracker) or #reject(DeltaTracker)

Parameters:
command -

aborted

public void aborted(IEfferentCommand command,
                    java.lang.Object extraInfo)
called when a command is aborted on the sensor side (not at the request of the agent).

Parameters:
command -
extraInfo - will be stored under IEfferentCommand.RESULT

completed

public void completed(IEfferentCommand command,
                      java.lang.Object extraInfo)
called upon the completion of a command

Parameters:
command -
extraInfo -