cz.cuni.amis.pogamut.base.agent.module
Class AgentModule<AGENT extends IAgent>

java.lang.Object
  extended by cz.cuni.amis.pogamut.base.agent.module.AgentModule<AGENT>
Type Parameters:
AGENT -
All Implemented Interfaces:
IComponent
Direct Known Subclasses:
JMXAgentModule, LogicModule, MotoricModule, SensomotoricModule, SensorModule

public abstract class AgentModule<AGENT extends IAgent>
extends java.lang.Object
implements IComponent

Ancestor of all agent modules that contains ComponentController and defines protected methods for the control of the module's lifecycle (AgentModule#start(), stop(), pause(), resume(), kill() and reset()). Override them when needed.


Field Summary
protected  AGENT agent
           
protected  ComponentController controller
           
protected  IComponentBus eventBus
           
protected  java.util.logging.Logger log
           
 
Constructor Summary
AgentModule(AGENT agent)
          Initialize agent module - it will start ComponentDependencyType.STARTS_WITH the agent.
AgentModule(AGENT agent, java.util.logging.Logger log)
          Initialize agent module - it will start ComponentDependencyType.STARTS_WITH the agent.
AgentModule(AGENT agent, java.util.logging.Logger log, ComponentDependencies dependencies)
          Initialize agent module with custom dependencies.
 
Method Summary
protected  void cleanUp()
          Hook where to perform clean up of data structures of the module.
 Token getComponentId()
          Unique identification of the component.
 java.util.logging.Logger getLog()
          Returns a logger used by the AgentModule.
 ImmutableFlag<ComponentState> getState()
          Returns state of the component.
protected  Token initComponentId()
          Returns token made from simple name of the module's class.
 boolean isRunning()
          Whether the component is running.
protected  void kill()
          Kills the agent module.
protected  void pause()
          Pauses the agent module.
protected  void reset()
          Resets the agent module so it may be reused.
protected  void resume()
          Resumes the agent module.
protected  void start(boolean startToPaused)
          Starts the agent module.
protected  void stop()
          Stops the agent module.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

agent

protected final AGENT extends IAgent agent

log

protected java.util.logging.Logger log

controller

protected final ComponentController controller

eventBus

protected final IComponentBus eventBus
Constructor Detail

AgentModule

public AgentModule(AGENT agent)
Initialize agent module - it will start ComponentDependencyType.STARTS_WITH the agent.

Parameters:
agent -

AgentModule

public AgentModule(AGENT agent,
                   java.util.logging.Logger log)
Initialize agent module - it will start ComponentDependencyType.STARTS_WITH the agent.

Parameters:
agent -
log - should be used, if null is provided, it is created automatically

AgentModule

public AgentModule(AGENT agent,
                   java.util.logging.Logger log,
                   ComponentDependencies dependencies)
Initialize agent module with custom dependencies.

Parameters:
agent -
log - which should be used, if null is provided, it is created automatically
dependencies -
Method Detail

getLog

public java.util.logging.Logger getLog()
Returns a logger used by the AgentModule. AgentModule always has a logger, even if you do not supply it with one (it will allocate one on its own).

Returns:

initComponentId

protected Token initComponentId()
Returns token made from simple name of the module's class.

Called during the construction of the module, called only once (and even before your constructors take effect)!

Returns:
component id

getComponentId

public Token getComponentId()
Description copied from interface: IComponent
Unique identification of the component.

Specified by:
getComponentId in interface IComponent
Returns:

isRunning

public boolean isRunning()
Whether the component is running.

Returns:
See Also:
AbstractComponentControllerBase.isRunning()

getState

public ImmutableFlag<ComponentState> getState()
Returns state of the component.

Returns:

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

start

protected void start(boolean startToPaused)
Starts the agent module. (Called even if starting to paused state.)


stop

protected void stop()
Stops the agent module.

Calls cleanUp().


kill

protected void kill()
Kills the agent module.

Calls cleanUp().


pause

protected void pause()
Pauses the agent module.


resume

protected void resume()
Resumes the agent module.


reset

protected void reset()
Resets the agent module so it may be reused.

Calls cleanUp().


cleanUp

protected void cleanUp()
Hook where to perform clean up of data structures of the module.

Called from stop(), kill(), reset().