cz.cuni.amis.pogamut.base.agent.navigation.impl
Class AbstractPathExecutor<PATH_ELEMENT>

Package class diagram package AbstractPathExecutor
java.lang.Object
  extended by cz.cuni.amis.pogamut.base.agent.navigation.impl.AbstractPathExecutor<PATH_ELEMENT>
Type Parameters:
PATH_ELEMENT -
All Implemented Interfaces:
IPathExecutor<PATH_ELEMENT>
Direct Known Subclasses:
BasePathExecutor

public abstract class AbstractPathExecutor<PATH_ELEMENT>
extends Object
implements IPathExecutor<PATH_ELEMENT>

Stub implementation of the IPathExecutor that implements several trivial methods from the interface leaving the important one to be implemented by descendants.

Methods that need to be implemented are: followPath(IPathFuture), getPathFuture(), getPathElementIndex() and stop()). Note that these methods must correctly set the path executor state according to javadoc in PathExecutorState.

Author:
Jimmy

Field Summary
protected  Logger log
           
protected  cz.cuni.amis.utils.flag.Flag<IPathExecutorState> state
           
protected  List<IStuckDetector> stuckDetectors
           
 
Constructor Summary
AbstractPathExecutor()
           
AbstractPathExecutor(Logger log)
           
 
Method Summary
 void addStuckDetector(IStuckDetector stuckDetector)
          Adds IStuckDetector into the executor to watch over the path execution.
abstract  void followPath(IPathFuture<? extends PATH_ELEMENT> path)
          Makes the agent follow given path.
 Logger getLog()
          Returns log used by path executor (may be null, you should always check that).
 List<PATH_ELEMENT> getPath()
          If the IPathExecutor.isExecuting() and the path has been already computed, returns path the executor is currently following.
 PATH_ELEMENT getPathElement()
          Returns correct path element only if the getPathElementIndex() is in the range of getPath().
abstract  int getPathElementIndex()
          Returns an index pointing into IPathExecutor.getPath() that marks the element the path executor is currently heading to.
abstract  IPathFuture<PATH_ELEMENT> getPathFuture()
          Returns current path that the executor is following.
 cz.cuni.amis.utils.flag.ImmutableFlag<IPathExecutorState> getState()
          Returns a flag with the state of the executor - it is desirable you to set up listeners on this flag as it publish important informations about the path execution.
 boolean inState(PathExecutorState... states)
          True if the path executor is in one of 'states', false otherwise.
 boolean isExecuting()
          Determines, whether the path executor instance has been submitted with IPathFuture and working on getting the bot to its target.
 boolean isPathUnavailable()
          True if the path does not exist (is null) or can't be computed at all (an exception has happened or the computation has been canceled).
 boolean isStuck()
          Sets to true whenever the path executor detect that the bot has stuck and is unable to reach the path destination.
 boolean isTargetReached()
          Sets to true whenever the path executor reaches the end of the provided path.
 boolean notInState(PathExecutorState... states)
          True if the path executor's state is not among 'states', false otherwise.
 void removeAllStuckDetectors()
          Removes all stuck detectors it has.
 void removeStuckDetector(IStuckDetector stuckDetector)
          Removes IStuckDetector from the executor (must be the same instance, equals() is NOT USED).
 void setLog(Logger log)
          Sets logger to be used by the path executor.
abstract  void stop()
          Stops the path executor unconditionally.
protected  void switchState(IPathExecutorState newState)
          Simple method that sets new AbstractPathExecutor state into state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface cz.cuni.amis.pogamut.base.agent.navigation.IPathExecutor
getPathFrom, getPathTo
 

Field Detail

state

protected cz.cuni.amis.utils.flag.Flag<IPathExecutorState> state

stuckDetectors

protected List<IStuckDetector> stuckDetectors

log

protected Logger log
Constructor Detail

AbstractPathExecutor

public AbstractPathExecutor()

AbstractPathExecutor

public AbstractPathExecutor(Logger log)
Method Detail

getLog

public Logger getLog()
Description copied from interface: IPathExecutor
Returns log used by path executor (may be null, you should always check that).

Specified by:
getLog in interface IPathExecutor<PATH_ELEMENT>
Returns:
log

setLog

public void setLog(Logger log)
Sets logger to be used by the path executor.

Parameters:
log -

switchState

protected void switchState(IPathExecutorState newState)
Simple method that sets new AbstractPathExecutor state into state.

Parameters:
newState -

getState

public cz.cuni.amis.utils.flag.ImmutableFlag<IPathExecutorState> getState()
Description copied from interface: IPathExecutor
Returns a flag with the state of the executor - it is desirable you to set up listeners on this flag as it publish important informations about the path execution.

Note that the flag contains IPathExecutorState NOT PathExecutorState itself - this way, every IPathExecutor implementor can create own IPathExecutorState implementation that may carry much more information about the state that just PathExecutorState extending the meanings of core PathExecutorStates.

It is advisable to study PathExecutorState javadoc, as it contains a description how the states can change giving you a picture how IPathExecutor is working (this description is a contract for every IPathExecutor implementation).

Listeners to the state can be attached via ImmutableFlag.addListener(cz.cuni.amis.utils.flag.FlagListener).

Specified by:
getState in interface IPathExecutor<PATH_ELEMENT>
Returns:
flag with the state

addStuckDetector

public void addStuckDetector(IStuckDetector stuckDetector)
Description copied from interface: IPathExecutor
Adds IStuckDetector into the executor to watch over the path execution.

Specified by:
addStuckDetector in interface IPathExecutor<PATH_ELEMENT>

removeStuckDetector

public void removeStuckDetector(IStuckDetector stuckDetector)
Description copied from interface: IPathExecutor
Removes IStuckDetector from the executor (must be the same instance, equals() is NOT USED).

Specified by:
removeStuckDetector in interface IPathExecutor<PATH_ELEMENT>

removeAllStuckDetectors

public void removeAllStuckDetectors()
Description copied from interface: IPathExecutor
Removes all stuck detectors it has.

Specified by:
removeAllStuckDetectors in interface IPathExecutor<PATH_ELEMENT>

inState

public boolean inState(PathExecutorState... states)
Description copied from interface: IPathExecutor
True if the path executor is in one of 'states', false otherwise.

Specified by:
inState in interface IPathExecutor<PATH_ELEMENT>
Returns:

notInState

public boolean notInState(PathExecutorState... states)
Description copied from interface: IPathExecutor
True if the path executor's state is not among 'states', false otherwise.

Specified by:
notInState in interface IPathExecutor<PATH_ELEMENT>
Returns:

getPath

public List<PATH_ELEMENT> getPath()
Description copied from interface: IPathExecutor
If the IPathExecutor.isExecuting() and the path has been already computed, returns path the executor is currently following. Returns null otherwise.

First path element is agent's starting position and the last path element is agent's target.

Specified by:
getPath in interface IPathExecutor<PATH_ELEMENT>
Returns:
current path or null

getPathElement

public PATH_ELEMENT getPathElement()
Returns correct path element only if the getPathElementIndex() is in the range of getPath(). Otherwise, returns null.

Specified by:
getPathElement in interface IPathExecutor<PATH_ELEMENT>
Returns:
current path element the executor is navigating to or null

isExecuting

public boolean isExecuting()
Description copied from interface: IPathExecutor
Determines, whether the path executor instance has been submitted with IPathFuture and working on getting the bot to its target.

Note that true is also returned for the situation in which the path executor awaits the path computation to be finished.

Specified by:
isExecuting in interface IPathExecutor<PATH_ELEMENT>
Returns:
returns true, if this instance is controlling the agent and navigate it along PATH_ELEMENTs (or at least waiting for the path). False otherwise

isTargetReached

public boolean isTargetReached()
Description copied from interface: IPathExecutor
Sets to true whenever the path executor reaches the end of the provided path.

False otherwise (note that IPathExecutor.stop() will switch this to 'false' again).

Specified by:
isTargetReached in interface IPathExecutor<PATH_ELEMENT>
Returns:
whether the target is reached

isStuck

public boolean isStuck()
Description copied from interface: IPathExecutor
Sets to true whenever the path executor detect that the bot has stuck and is unable to reach the path destination.

False otherwise (note that IPathExecuto#stop() will switch this to 'false' again).

Specified by:
isStuck in interface IPathExecutor<PATH_ELEMENT>
Returns:

isPathUnavailable

public boolean isPathUnavailable()
Description copied from interface: IPathExecutor
True if the path does not exist (is null) or can't be computed at all (an exception has happened or the computation has been canceled).

False otherwise (note that false does not mark the situation that the path has been computed).

Specified by:
isPathUnavailable in interface IPathExecutor<PATH_ELEMENT>
Returns:

followPath

public abstract void followPath(IPathFuture<? extends PATH_ELEMENT> path)
Description copied from interface: IPathExecutor
Makes the agent follow given path. Events are fired at different stages of movement (see IPathExecutor.getState() and appropriate event-listener hooking method ImmutableFlag.addListener(cz.cuni.amis.utils.flag.FlagListener)).

Specified by:
followPath in interface IPathExecutor<PATH_ELEMENT>
Parameters:
path - to follow

getPathFuture

public abstract IPathFuture<PATH_ELEMENT> getPathFuture()
Description copied from interface: IPathExecutor
Returns current path that the executor is following.

Returns null if not IPathExecutor.isExecuting().

Specified by:
getPathFuture in interface IPathExecutor<PATH_ELEMENT>
Returns:
current path

getPathElementIndex

public abstract int getPathElementIndex()
Description copied from interface: IPathExecutor
Returns an index pointing into IPathExecutor.getPath() that marks the element the path executor is currently heading to.

Returns -1 if not IPathExecutor.isExecuting().

Specified by:
getPathElementIndex in interface IPathExecutor<PATH_ELEMENT>
Returns:

stop

public abstract void stop()
Description copied from interface: IPathExecutor
Stops the path executor unconditionally.

Specified by:
stop in interface IPathExecutor<PATH_ELEMENT>


Copyright © 2014 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.