cz.cuni.amis.pogamut.base.communication.command.react
Class CommandReact<COMMAND extends CommandMessage>

java.lang.Object
  extended by cz.cuni.amis.pogamut.base.communication.command.react.CommandReact<COMMAND>
Type Parameters:
EVENT -
Direct Known Subclasses:
CommandReactOnce

public abstract class CommandReact<COMMAND extends CommandMessage>
extends java.lang.Object

This abstract class allows you to easily hook a specific outgoing-command-handling behavior. It automatically register a listener for a specified CommandMessage for you and calls react(CommandMessage) method automatically.

If you need to react only once to the event, use EventReactOnce.

Use EventReact.enable() and EventReact.disable() to enable react / disable react. The reaction is enabled as default.

WARNING:Use as anonymous class, but save it as a field of your class! Note, that we're using weak-references to listeners and if you do not save pointer to the object, it will be gc()ed!


Field Summary
protected  IAct reactAct
           
protected  java.lang.Class<COMMAND> reactCommandClass
           
protected  ICommandListener<COMMAND> reactListener
           
 
Constructor Summary
CommandReact(java.lang.Class<COMMAND> commandClass, IAct worldView)
           
 
Method Summary
 void disable()
          Disables the reaction.
 void enable()
          Enables the reaction.
protected  void postReact(COMMAND event)
          post-EventReact.react(IWorldEvent) hook allowing you to do additional work after the react method.
protected  void preReact(COMMAND event)
          pre-EventReact.react(IWorldEvent) hook allowing you to do additional work before the react method.
protected abstract  void react(COMMAND event)
          React upon event notification.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

reactListener

protected ICommandListener<COMMAND extends CommandMessage> reactListener

reactAct

protected IAct reactAct

reactCommandClass

protected java.lang.Class<COMMAND extends CommandMessage> reactCommandClass
Constructor Detail

CommandReact

public CommandReact(java.lang.Class<COMMAND> commandClass,
                    IAct worldView)
Method Detail

disable

public void disable()
Disables the reaction.


enable

public void enable()
Enables the reaction.


preReact

protected void preReact(COMMAND event)
pre-EventReact.react(IWorldEvent) hook allowing you to do additional work before the react method.

Parameters:
event -

react

protected abstract void react(COMMAND event)
React upon event notification.

Parameters:
event -

postReact

protected void postReact(COMMAND event)
post-EventReact.react(IWorldEvent) hook allowing you to do additional work after the react method.

Parameters:
event -