|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object cz.cuni.amis.pogamut.base.agent.navigation.impl.AbstractPathExecutor<PATH_ELEMENT>
PATH_ELEMENT
- public abstract class AbstractPathExecutor<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
.
Field Summary | |
---|---|
protected java.util.logging.Logger |
log
|
protected Flag<IPathExecutorState> |
state
|
protected java.util.List<IStuckDetector> |
stuckDetectors
|
Constructor Summary | |
---|---|
AbstractPathExecutor()
|
|
AbstractPathExecutor(java.util.logging.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. |
java.util.logging.Logger |
getLog()
Returns log used by path executor (may be null, you should always check that). |
java.util.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. |
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 |
removeStuckDetector(IStuckDetector stuckDetector)
Removes IStuckDetector from the executor (must be the same instance, equals() is NOT USED). |
void |
setLog(java.util.logging.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 |
Field Detail |
---|
protected Flag<IPathExecutorState> state
protected java.util.List<IStuckDetector> stuckDetectors
protected java.util.logging.Logger log
Constructor Detail |
---|
public AbstractPathExecutor()
public AbstractPathExecutor(java.util.logging.Logger log)
Method Detail |
---|
public java.util.logging.Logger getLog()
IPathExecutor
getLog
in interface IPathExecutor<PATH_ELEMENT>
public void setLog(java.util.logging.Logger log)
log
- protected void switchState(IPathExecutorState newState)
AbstractPathExecutor
state into state
.
newState
- public ImmutableFlag<IPathExecutorState> getState()
IPathExecutor
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
PathExecutorState
s.
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)
.
getState
in interface IPathExecutor<PATH_ELEMENT>
public void addStuckDetector(IStuckDetector stuckDetector)
IPathExecutor
IStuckDetector
into the executor to watch over the path execution.
addStuckDetector
in interface IPathExecutor<PATH_ELEMENT>
public void removeStuckDetector(IStuckDetector stuckDetector)
IPathExecutor
IStuckDetector
from the executor (must be the same instance, equals() is NOT USED).
removeStuckDetector
in interface IPathExecutor<PATH_ELEMENT>
public boolean inState(PathExecutorState... states)
IPathExecutor
inState
in interface IPathExecutor<PATH_ELEMENT>
public boolean notInState(PathExecutorState... states)
IPathExecutor
notInState
in interface IPathExecutor<PATH_ELEMENT>
public java.util.List<PATH_ELEMENT> getPath()
IPathExecutor
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.
getPath
in interface IPathExecutor<PATH_ELEMENT>
public PATH_ELEMENT getPathElement()
getPathElementIndex()
is in the range
of getPath()
. Otherwise, returns null.
getPathElement
in interface IPathExecutor<PATH_ELEMENT>
public boolean isExecuting()
IPathExecutor
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.
isExecuting
in interface IPathExecutor<PATH_ELEMENT>
public boolean isTargetReached()
IPathExecutor
False otherwise (note that IPathExecutor.stop()
will switch this to 'false' again).
isTargetReached
in interface IPathExecutor<PATH_ELEMENT>
public boolean isStuck()
IPathExecutor
False otherwise (note that IPathExecuto#stop()
will switch this to 'false' again).
isStuck
in interface IPathExecutor<PATH_ELEMENT>
public boolean isPathUnavailable()
IPathExecutor
False otherwise (note that false does not mark the situation that the path has been computed).
isPathUnavailable
in interface IPathExecutor<PATH_ELEMENT>
public abstract void followPath(IPathFuture<? extends PATH_ELEMENT> path)
IPathExecutor
IPathExecutor.getState()
and appropriate event-listener hooking method ImmutableFlag.addListener(cz.cuni.amis.utils.flag.FlagListener)
).
followPath
in interface IPathExecutor<PATH_ELEMENT>
path
- to followpublic abstract IPathFuture<PATH_ELEMENT> getPathFuture()
IPathExecutor
Returns null if not IPathExecutor.isExecuting()
.
getPathFuture
in interface IPathExecutor<PATH_ELEMENT>
public abstract int getPathElementIndex()
IPathExecutor
IPathExecutor.getPath()
that marks the element
the path executor is currently heading to.
Returns -1 if not IPathExecutor.isExecuting()
.
getPathElementIndex
in interface IPathExecutor<PATH_ELEMENT>
public abstract void stop()
IPathExecutor
stop
in interface IPathExecutor<PATH_ELEMENT>
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |