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

java.lang.Object
  extended by cz.cuni.amis.pogamut.base.agent.module.AgentModule<AGENT>
      extended by cz.cuni.amis.pogamut.base.agent.module.LogicModule<AGENT>
All Implemented Interfaces:
IComponent
Direct Known Subclasses:
UT2004BotLogic

public class LogicModule<AGENT extends IAgent>
extends AgentModule<AGENT>


Field Summary
protected  long lastLogicRun
           
protected  IAgentLogic logic
           
protected  java.lang.Throwable logicException
           
protected  double logicFrequency
           
protected  Flag<java.lang.Boolean> logicPaused
           
protected  double logicPeriod
           
protected  Flag<java.lang.Boolean> logicRunning
           
protected  Flag<java.lang.Boolean> logicShouldPause
           
protected  boolean logicShouldRun
           
protected  java.lang.Thread logicThread
           
static double MAX_LOGIC_FREQUENCY
          Must be greater than 0.
static long MAX_LOGIC_PERIOD_MILLIS
          Must be greater than 0.
static double MIN_LOGIC_FREQUENCY
          Must be greater than 0.
static long MIN_LOGIC_PERIOD_MILLIS
          Must be greater than 0.
protected  java.lang.Object mutex
           
 
Fields inherited from class cz.cuni.amis.pogamut.base.agent.module.AgentModule
agent, controller, eventBus, log
 
Constructor Summary
LogicModule(AGENT agent, IAgentLogic logic)
           
LogicModule(AGENT agent, IAgentLogic logic, java.util.logging.Logger log)
           
LogicModule(AGENT agent, IAgentLogic logic, java.util.logging.Logger log, ComponentDependencies dependencies)
           
 
Method Summary
protected  void afterLogic(java.lang.String threadName)
          Called right after the logic.doLogic() is called.
protected  void afterLogicException(java.lang.String threadName, java.lang.Throwable e)
          Called whenever some exception is thrown inside LogicRunner.
protected  void beforeLogic(java.lang.String threadName)
          Called right before the logic.doLogic() is called.
 java.lang.Throwable getLogicException()
           
 double getLogicFrequency()
           
 double getLogicPeriod()
           
protected  void inThreadKilling()
           
protected  void inThreadPausing()
           
protected  void inThreadResuming()
           
protected  void inThreadStopping()
           
protected  void kill()
          Kills the agent module.
protected  void logicLatch(java.lang.String threadName)
          Called before the IAgentLogic.logic() is periodically called - allows you to sleep the logic until the rest of the agent is ready.
protected  void pause()
          Pauses the agent module.
protected  void resume()
          Resumes the agent module.
 void setLogicFrequency(double frequency)
           
 void setMaxLogicFrequency()
           
 void setMinLogicFrequency()
           
protected  boolean shouldExecuteLogic()
          Controls whether the logic.logic() will be called.
protected  void start(boolean startPaused)
          Starts the agent module.
 void stop()
          Stops the agent module.
 
Methods inherited from class cz.cuni.amis.pogamut.base.agent.module.AgentModule
cleanUp, getComponentId, getLog, getState, initComponentId, isRunning, reset, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MIN_LOGIC_PERIOD_MILLIS

public static final long MIN_LOGIC_PERIOD_MILLIS
Must be greater than 0.

See Also:
Constant Field Values

MAX_LOGIC_FREQUENCY

public static final double MAX_LOGIC_FREQUENCY
Must be greater than 0.

See Also:
Constant Field Values

MAX_LOGIC_PERIOD_MILLIS

public static final long MAX_LOGIC_PERIOD_MILLIS
Must be greater than 0.

See Also:
Constant Field Values

MIN_LOGIC_FREQUENCY

public static final double MIN_LOGIC_FREQUENCY
Must be greater than 0.

See Also:
Constant Field Values

mutex

protected java.lang.Object mutex

logic

protected IAgentLogic logic

logicThread

protected java.lang.Thread logicThread

logicShouldRun

protected boolean logicShouldRun

logicRunning

protected Flag<java.lang.Boolean> logicRunning

logicShouldPause

protected Flag<java.lang.Boolean> logicShouldPause

logicPaused

protected Flag<java.lang.Boolean> logicPaused

logicFrequency

protected double logicFrequency

logicPeriod

protected double logicPeriod

lastLogicRun

protected long lastLogicRun

logicException

protected java.lang.Throwable logicException
Constructor Detail

LogicModule

@Inject
public LogicModule(AGENT agent,
                          IAgentLogic logic)

LogicModule

public LogicModule(AGENT agent,
                   IAgentLogic logic,
                   java.util.logging.Logger log)

LogicModule

public LogicModule(AGENT agent,
                   IAgentLogic logic,
                   java.util.logging.Logger log,
                   ComponentDependencies dependencies)
Method Detail

start

protected void start(boolean startPaused)
              throws AgentException
Description copied from class: AgentModule
Starts the agent module. (Called even if starting to paused state.)

Overrides:
start in class AgentModule<AGENT extends IAgent>
Throws:
AgentException

stop

public void stop()
Description copied from class: AgentModule
Stops the agent module.

Calls AgentModule.cleanUp().

Overrides:
stop in class AgentModule<AGENT extends IAgent>

kill

protected void kill()
Description copied from class: AgentModule
Kills the agent module.

Calls AgentModule.cleanUp().

Overrides:
kill in class AgentModule<AGENT extends IAgent>

pause

protected void pause()
Description copied from class: AgentModule
Pauses the agent module.

Overrides:
pause in class AgentModule<AGENT extends IAgent>

resume

protected void resume()
Description copied from class: AgentModule
Resumes the agent module.

Overrides:
resume in class AgentModule<AGENT extends IAgent>

inThreadStopping

protected void inThreadStopping()

inThreadKilling

protected void inThreadKilling()

inThreadPausing

protected void inThreadPausing()

inThreadResuming

protected void inThreadResuming()

beforeLogic

protected void beforeLogic(java.lang.String threadName)
Called right before the logic.doLogic() is called.


afterLogic

protected void afterLogic(java.lang.String threadName)
Called right after the logic.doLogic() is called.


afterLogicException

protected void afterLogicException(java.lang.String threadName,
                                   java.lang.Throwable e)
Called whenever some exception is thrown inside LogicRunner.

Parameters:
e -

shouldExecuteLogic

protected boolean shouldExecuteLogic()
Controls whether the logic.logic() will be called.

If logic is running & is not paused you may use this to fine control the moments when the logic should execute.

Returns 'true' as default.

Returns:
whether the logic should be executing

logicLatch

protected void logicLatch(java.lang.String threadName)
Called before the IAgentLogic.logic() is periodically called - allows you to sleep the logic until the rest of the agent is ready.


getLogicPeriod

public double getLogicPeriod()

getLogicException

public java.lang.Throwable getLogicException()
Returns:
the throwable that caused the logic to crash.

getLogicFrequency

public double getLogicFrequency()

setMinLogicFrequency

public void setMinLogicFrequency()

setMaxLogicFrequency

public void setMaxLogicFrequency()

setLogicFrequency

public void setLogicFrequency(double frequency)