public abstract class BasePathExecutor<PATH_ELEMENT> extends AbstractPathExecutor<PATH_ELEMENT> implements IPathExecutorHelper<PATH_ELEMENT>
AbstractPathExecutor
which correctly sets the path executor states along the way and provide methods for reporting failures.
Note that it is somewhat hard to use this stub-implementation as the base for implementing
your own IPathExecutor implementation - the AbstractPathExecutor might be more suitable.
That's because this implementation is defining a way how its fields are used, how methods should be synchronized,
how they are called (method protocol), etc.
Implementation notes:
IPathExecutorState may have different implementation providing different kind of the information
about the path - BasePathExecutor defines createState(PathExecutorState) as a hook
for custom IPathExecutorState implementation (currently it uses simple BasePathExecutorState).
AbstractPathExecutor
or copy-paste the BasePathExecutor code and do your changes in copied code.
BasePathExecutor.
followPath(IPathFuture) - interface public method / meant to be called from the outside - begin following the path / handles path future listenerpathComputed() - protected method / it is automatically called by the BasePathExecutor whenever the path future returns the pathpathComputationFailed() - protected method / it is automatically called by the BasePathExecutor whenever path future reports FutureStatus.CANCELED or FutureStatus.COMPUTATION_EXCEPTION.
switchToAnotherPathElement(int) - protected method / meant to be called from within the path executor (descendant) whenever the executor should start to navigate towards another path elementBasePathExecutor#stuck(IStuckDetector) - protected method / automatically called by BasePathExecutor#executePath() whenever one of the AbstractPathExecutor.stuckDetectors reports stuckstop() - interface public method / meant to be called both from the outside or from the inside of path executor / stops the path executorBasePathExecutor. These are:
switchToAnotherPathElement(int) - this method should be called either from prePathComputedImpl() or pathComputed() to mark
the index of the path element that is going to be pursued first (this index will likely be '0').BasePathExecutor#stuck(IStuckDetector) - use this method to report that the stuck has been detectedcheckStuckDetectors()
| Modifier and Type | Field and Description |
|---|---|
protected Object |
mutex
Mutex object synchronizing access to
followPath(IPathFuture) and
stop() methods. |
protected int |
pathElementIndex
Marks the index of the current path element (path element that is currently pursued)
from the path element list of
AbstractPathExecutor.getPath(). |
protected IPathFuture<PATH_ELEMENT> |
pathFuture
Current path future of the path executor.
|
protected int |
previousPathElementIndex
Marks the index of the previous path element (path element that has been previously pursued)
from the path element list of
AbstractPathExecutor.getPath(). |
log, state, stuckDetectors| Constructor and Description |
|---|
BasePathExecutor() |
BasePathExecutor(Logger log) |
| Modifier and Type | Method and Description |
|---|---|
IStuckDetector |
checkStuckDetectors()
This method checks (one-by-one) stuck detectors whether some of them is reporting that the agent has stuck.
|
protected IPathExecutorState |
createState(PathExecutorState state)
Utility method that is responsible for creating new state for the path executor.
|
void |
followPath(IPathFuture<? extends PATH_ELEMENT> path)
Tell the executor to start navigating the agent along the 'path'.
|
protected abstract void |
followPathImpl()
Method that is called just after the executor's state is switched to
PathExecutorState.FOLLOW_PATH_CALLED from
within the followPath(IPathFuture) method. |
int |
getPathElementIndex()
Returns an index pointing into
IPathExecutor.getPath() that marks the element
the path executor is currently heading to. |
PATH_ELEMENT |
getPathFrom()
Returns path origin, from where we're running.
|
IPathFuture<PATH_ELEMENT> |
getPathFuture()
Returns current path that the executor is following.
|
PATH_ELEMENT |
getPathTo()
Returns target where we're running.
|
protected void |
pathComputationFailed()
Path computation has failed, path is unavailable and the executor can't start navigate the agent through the environment.
|
protected abstract void |
pathComputationFailedImpl()
Method that is called just after the executor's state is switched to
PathExecutorState.PATH_COMPUTATION_FAILED from
within the pathComputationFailed() method. |
protected void |
pathComputed()
Path has been computed and is available in
pathFuture. |
protected abstract void |
pathComputedImpl()
Method that is called just after the executor's state is switched to
PathExecutorState.PATH_COMPUTED from
within the pathComputed() method. |
protected void |
preFollowPathImpl()
Method that is called just before the executor's state is switched to
PathExecutorState.FOLLOW_PATH_CALLED from within
the followPath(IPathFuture) method. |
protected void |
prePathComputationFailed()
Method that is called just before the executor's state is switched to
PathExecutorState.PATH_COMPUTATION_FAILED from within
the pathComputationFailed() method. |
protected void |
prePathComputedImpl()
Method that is called just before the executor's state is switched to
PathExecutorState.PATH_COMPUTED from within
the pathComputed() method. |
protected void |
preStuckImpl()
Method that is called just before the executor's state is switched to
PathExecutorState#STUCKD from within the
BasePathExecutor#stuck(IStuckDetector) method. |
protected void |
preSwitchToAnotherPathElementImpl(int newIndex)
Method that is called just before the executor's state is switched to
PathExecutorState.SWITCHED_TO_ANOTHER_PATH_ELEMENT from within
the switchToAnotherPathElement(int) method. |
protected void |
preTargetReachedImpl()
Method that is called just before the executor's state is switched to
PathExecutorState.TARGET_REACHED from within the
targetReached() method. |
void |
stop()
Used to stop the path executor, for more info see
AbstractPathExecutor.stop(). |
protected void |
stopImpl()
Method that is called just before the executor's state is switched to
PathExecutorState.STOPPED from within the
stop() method. |
protected abstract void |
stopped()
Method that is called just after the executor's state is switched to
PathExecutorState.STOPPED from
within the stop() method. |
void |
stuck()
Method that changes the state to
PathExecutorState.STUCK that should be called whenever some
stuck detector detects that the agent is stuck. |
protected abstract void |
stuckImpl()
Method that is called just after the executor's state is switched to
PathExecutorState.STUCK from
within the BasePathExecutor#stuck(IStuckDetector) method. |
void |
switchToAnotherPathElement(int index)
Switches from current path element index into the new one.
|
protected abstract void |
switchToAnotherPathElementImpl()
Method that is called just after the executor's state is switched to
PathExecutorState.SWITCHED_TO_ANOTHER_PATH_ELEMENT from
within the switchToAnotherPathElement(int) method. |
void |
targetReached()
Method that should be called whenever the path executor reaches the end of the path.
|
protected abstract void |
targetReachedImpl()
Method that is called just after the executor's state is switched to
PathExecutorState.TARGET_REACHED from
within the targetReached() method. |
addStuckDetector, getLog, getPath, getPathElement, getState, inState, isExecuting, isPathUnavailable, isStuck, isTargetReached, notInState, removeAllStuckDetectors, removeStuckDetector, setLog, switchStateclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddStuckDetector, getLog, getPath, getPathElement, getState, inState, isExecuting, isPathUnavailable, isStuck, isTargetReached, notInState, removeAllStuckDetectors, removeStuckDetectorprotected Object mutex
followPath(IPathFuture) and
stop() methods.protected IPathFuture<PATH_ELEMENT> pathFuture
followPath(IPathFuture)
and removed (set to 'null') in stop().protected int previousPathElementIndex
AbstractPathExecutor.getPath().
Setting value to this field manually must be done only inside preSwitchToAnotherPathElementImpl(int)
and switchToAnotherPathElementImpl().
protected int pathElementIndex
AbstractPathExecutor.getPath().
Setting value to this field manually must be done only inside preSwitchToAnotherPathElementImpl(int)
and switchToAnotherPathElementImpl().
public BasePathExecutor()
public BasePathExecutor(Logger log)
public int getPathElementIndex()
IPathExecutorIPathExecutor.getPath() that marks the element
the path executor is currently heading to.
Returns -1 if not IPathExecutor.isExecuting().
getPathElementIndex in interface IPathExecutor<PATH_ELEMENT>getPathElementIndex in class AbstractPathExecutor<PATH_ELEMENT>public IPathFuture<PATH_ELEMENT> getPathFuture()
IPathExecutor
Returns null if not IPathExecutor.isExecuting().
getPathFuture in interface IPathExecutor<PATH_ELEMENT>getPathFuture in class AbstractPathExecutor<PATH_ELEMENT>public PATH_ELEMENT getPathFrom()
IPathExecutorgetPathFrom in interface IPathExecutor<PATH_ELEMENT>public PATH_ELEMENT getPathTo()
IPathExecutorgetPathTo in interface IPathExecutor<PATH_ELEMENT>protected IPathExecutorState createState(PathExecutorState state)
IPathExecutorState are instantiated.
This method allows you to provide own IPathExecutorState implementation that may carry additional
information about the executor's state.
state - public final void followPath(IPathFuture<? extends PATH_ELEMENT> path)
If called and the AbstractPathExecutor.isExecuting(), it first calls stop().
For more info see AbstractPathExecutor.followPath(IPathFuture)
followPath in interface IPathExecutor<PATH_ELEMENT>followPath in class AbstractPathExecutor<PATH_ELEMENT>path - path to navigate alongprotected void preFollowPathImpl()
PathExecutorState.FOLLOW_PATH_CALLED from within
the followPath(IPathFuture) method.
You may utilize this methods this way:
createState(PathExecutorState) to create more-informed state object.Current implementation ensures that the state of the path executor is cleared.
protected abstract void followPathImpl()
PathExecutorState.FOLLOW_PATH_CALLED from
within the followPath(IPathFuture) method.
You may utilize this method this way:
protected final void pathComputed()
pathFuture. This method is automatically called
from the followPath(IPathFuture) or by pathFutureListener whenever
the path is ready.
Effective only if the state is: PathExecutorState.FOLLOW_PATH_CALLED
protected void prePathComputedImpl()
PathExecutorState.PATH_COMPUTED from within
the pathComputed() method. Note that since this method is called, the path can be simply
obtained by calling AbstractPathExecutor.getPath().
You may utilize this method (for instance) to:
createState(PathExecutorState) to create more-informed state object.
Note that you should call switchToAnotherPathElement(int) (to mark the index of the first path element)
in this method or in pathComputedImpl(). The first path element index will likely be '0'.
Resets and enables all AbstractPathExecutor.stuckDetectors.
protected abstract void pathComputedImpl()
PathExecutorState.PATH_COMPUTED from
within the pathComputed() method. Note that the path can be simply obtained
by calling AbstractPathExecutor.getPath().
You may utilize this method (for instance) to:
Note that you should call switchToAnotherPathElement(int) (to mark the index of the first path element)
in this method or in prePathComputedImpl(). The first path element index will likely be '0'.
protected final void pathComputationFailed()
followPath(IPathFuture) or by pathFutureListener whenever
it is found out that the path can never be obtained from the pathFuture.
Effective only if the state is: PathExecutorState.FOLLOW_PATH_CALLED
protected void prePathComputationFailed()
PathExecutorState.PATH_COMPUTATION_FAILED from within
the pathComputationFailed() method.
You may utilize this methods (for instance) to:
createState(PathExecutorState) to create more-informed state object.Empty implementation, does not doing anything.
protected abstract void pathComputationFailedImpl()
PathExecutorState.PATH_COMPUTATION_FAILED from
within the pathComputationFailed() method. Note that the path can be simply obtained
by calling AbstractPathExecutor.getPath().
You may utilize this method (for instance) to:
public final void switchToAnotherPathElement(int index)
pathElementIndex.
This method should be also called as a reaction to pathComputed() method call, i.e.,
from prePathComputedImpl() or pathComputedImpl() to change
the index into '0' (or other index as you see fit).
Effective only if AbstractPathExecutor.isExecuting().
switchToAnotherPathElement in interface IPathExecutorHelper<PATH_ELEMENT>protected void preSwitchToAnotherPathElementImpl(int newIndex)
PathExecutorState.SWITCHED_TO_ANOTHER_PATH_ELEMENT from within
the switchToAnotherPathElement(int) method. Note that this method is called to alter
values inside previousPathElementIndex and pathElementIndex
by using 'newIndex'.
You may additionally utilize this method (for instance) to:
createState(PathExecutorState) to create more-informed state object.Current implementation does (and nothing else):
newIndex - index of the path element that should be pursued nowprotected abstract void switchToAnotherPathElementImpl()
PathExecutorState.SWITCHED_TO_ANOTHER_PATH_ELEMENT from
within the switchToAnotherPathElement(int) method. Note that this method
is called after the values inside previousPathElementIndex and pathElementIndex
are overwritten with new ones.
You may utilize this method (for instance) to:
public final void stop()
AbstractPathExecutor.stop().
Effective only if the state is NOT: PathExecutorState.STOPPED
stop in interface IPathExecutor<PATH_ELEMENT>stop in class AbstractPathExecutor<PATH_ELEMENT>protected void stopImpl()
PathExecutorState.STOPPED from within the
stop() method. Note that this method is called to clean up internal data structures
before we switch itself into PathExecutorState.STOPPED state.
You may additionally utilize this method (for instance) to:
createState(PathExecutorState) to create more-informed state object.Current implementation does (and nothing else):
previousPathElementIndex and pathElementIndex to -1pathFutureListener from the pathFuturepathFuture to nullAbstractPathExecutor.stuckDetectorsnewIndex - index of the path element that should be pursued nowprotected abstract void stopped()
PathExecutorState.STOPPED from
within the stop() method.
You may utilize this method (for instance) to:
public IStuckDetector checkStuckDetectors()
IStuckDetector is returned. If the stuck is not detected,
null is returned.checkStuckDetectors in interface IPathExecutorHelper<PATH_ELEMENT>public final void stuck()
PathExecutorState.STUCK that should be called whenever some
stuck detector detects that the agent is stuck.
It is currently called only from checkStuckDetectors() which must be called from
the descendant.
Note that you may actually pass 'null' as 'detector' into the method.
Effective only if the state is: PathExecutorState.FOLLOW_PATH_CALLED or PathExecutorState.PATH_COMPUTED or PathExecutorState.SWITCHED_TO_ANOTHER_PATH_ELEMENT
stuck in interface IPathExecutorHelper<PATH_ELEMENT>protected void preStuckImpl()
PathExecutorState#STUCKD from within the
BasePathExecutor#stuck(IStuckDetector) method. Note that this method is called to clean up internal data structures
before we switch itself into PathExecutorState.STUCK state.
BasePathExecutor's implementation disables all AbstractPathExecutor.stuckDetectors.
You may utilize this method (for instance) to:
createState(PathExecutorState) to create more-informed state object.Current implementation does (and nothing else):
AbstractPathExecutor.stuckDetectorsprotected abstract void stuckImpl()
PathExecutorState.STUCK from
within the BasePathExecutor#stuck(IStuckDetector) method.
You may utilize this method (for instance) to:
WARNING: 'null' may be passed as 'detector' if the stuck has been detected by different component
public final void targetReached()
BasePathExecutor.
Effective only if the state is: PathExecutorState.FOLLOW_PATH_CALLED or PathExecutorState.PATH_COMPUTED or PathExecutorState.SWITCHED_TO_ANOTHER_PATH_ELEMENT
targetReached in interface IPathExecutorHelper<PATH_ELEMENT>protected void preTargetReachedImpl()
PathExecutorState.TARGET_REACHED from within the
targetReached() method.
You may utilize this method (for instance) to:
createState(PathExecutorState) to create more-informed state object.Empty implementation, does not doing anything.
protected abstract void targetReachedImpl()
PathExecutorState.TARGET_REACHED from
within the targetReached() method.
You may utilize this method (for instance) to:
Copyright © 2012 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.