Package jade.core.behaviours
Class ParallelBehaviour
- java.lang.Object
-
- jade.core.behaviours.Behaviour
-
- jade.core.behaviours.CompositeBehaviour
-
- jade.core.behaviours.ParallelBehaviour
-
- All Implemented Interfaces:
Serializable,Serializable
public class ParallelBehaviour extends CompositeBehaviour
Composite behaviour with concurrent children scheduling. It is aCompositeBehaviourthat executes its children behaviours concurrently, and it terminates when a particular condition on its sub-behaviours is met i.e. when all children are done, N children are done or any child is done.- Version:
- $Date$ $Revision$
- Author:
- Giovanni Rimassa - Universita` di Parma, Giovanni Caire - Telecom Italia Lab
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jade.core.behaviours.Behaviour
Behaviour.RunnableChangedEvent
-
-
Field Summary
Fields Modifier and Type Field Description static intWHEN_ALLPredefined constant to be used in the constructor to create aParallelBehaviourthat terminates when all its children are done.static intWHEN_ANYPredefined constant to be used in the constructor to create aParallelBehaviourthat terminates when any of its child is done.-
Fields inherited from class jade.core.behaviours.CompositeBehaviour
currentExecuted
-
Fields inherited from class jade.core.behaviours.Behaviour
myAgent, myEvent, NOTIFY_DOWN, NOTIFY_UP, parent, STATE_BLOCKED, STATE_READY, STATE_RUNNING
-
-
Constructor Summary
Constructors Constructor Description ParallelBehaviour()Construct aParallelBehaviourwithout setting the owner agent, and using the default termination condition (i.e.ParallelBehaviour(int endCondition)Construct aParallelBehaviourwithout setting the owner agent.ParallelBehaviour(Agent a, int endCondition)Construct aParallelBehavioursetting the owner agent.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddSubBehaviour(Behaviour b)Add a sub behaviour to thisParallelBehaviourprotected booleancheckTermination(boolean currentDone, int currentResult)Check whether thisParallelBehaviourmust terminate.CollectiongetChildren()Return a Collection view of the children of thisParallelBehaviourprotected BehaviourgetCurrent()Get the current childCollectiongetTerminatedChildren()Return a Collection view of the children of thisParallelBehaviourthat have already completed.protected voidhandle(Behaviour.RunnableChangedEvent rce)Handle block/restart notifications.voidremoveSubBehaviour(Behaviour b)Remove a sub behaviour from thisParallelBehaviourvoidreset()Resets this behaviour.protected voidscheduleFirst()Prepare the first child for executionprotected voidscheduleNext(boolean currentDone, int currentResult)This method schedules children behaviours one at a time, in a round robin fashion.-
Methods inherited from class jade.core.behaviours.CompositeBehaviour
action, done, handleBlockEvent, handleRestartEvent, registerAsChild, resetChildren, setAgent
-
Methods inherited from class jade.core.behaviours.Behaviour
actionWrapper, block, block, getAgent, getBehaviourName, getDataStore, getExecutionState, getParent, getRestartCounter, isRunnable, onEnd, onStart, restart, root, setBehaviourName, setDataStore, setExecutionState
-
-
-
-
Field Detail
-
WHEN_ALL
public static final int WHEN_ALL
Predefined constant to be used in the constructor to create aParallelBehaviourthat terminates when all its children are done.- See Also:
- Constant Field Values
-
WHEN_ANY
public static final int WHEN_ANY
Predefined constant to be used in the constructor to create aParallelBehaviourthat terminates when any of its child is done.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ParallelBehaviour
public ParallelBehaviour()
Construct aParallelBehaviourwithout setting the owner agent, and using the default termination condition (i.e. the parallel behaviour terminates as soon as all its children behaviours terminate.
-
ParallelBehaviour
public ParallelBehaviour(int endCondition)
Construct aParallelBehaviourwithout setting the owner agent.- Parameters:
endCondition- this value defines the termination condition for thisParallelBehaviour. Use-
WHEN_ALLto terminate thisParallelBehaviourwhen all its children are done. -
WHEN_ANYto terminate thisParallelBehaviourwhen any of its child is done. -
a positive
intvalue n to terminate thisParallelBehaviourwhen n of its children are done.
-
-
ParallelBehaviour
public ParallelBehaviour(Agent a, int endCondition)
Construct aParallelBehavioursetting the owner agent.- Parameters:
a- the agent thisParallelBehaviourbelongs to.endCondition- this value defines the termination condition for thisParallelBehaviour. Use-
WHEN_ALLto terminate thisParallelBehaviourwhen all its children are done. -
WHEN_ANYto terminate thisParallelBehaviourwhen any of its child is done. -
a positive
intvalue n to terminate thisParallelBehaviourwhen n of its children are done.
-
-
-
Method Detail
-
scheduleFirst
protected void scheduleFirst()
Prepare the first child for execution- Specified by:
scheduleFirstin classCompositeBehaviour- See Also:
CompositeBehaviour.scheduleFirst()
-
scheduleNext
protected void scheduleNext(boolean currentDone, int currentResult)This method schedules children behaviours one at a time, in a round robin fashion.- Specified by:
scheduleNextin classCompositeBehaviour- Parameters:
currentDone- a flag indicating whether the just executed child has completed or not.currentResult- the termination value (as returned byonEnd()) of the just executed child in the case this child has completed (otherwise this parameter is meaningless)- See Also:
CompositeBehaviour.scheduleNext(boolean, int)
-
checkTermination
protected boolean checkTermination(boolean currentDone, int currentResult)Check whether thisParallelBehaviourmust terminate.- Specified by:
checkTerminationin classCompositeBehaviour- Parameters:
currentDone- a flag indicating whether the just executed child has completed or not.currentResult- the termination value (as returned byonEnd()) of the just executed child in the case this child has completed (otherwise this parameter is meaningless)- Returns:
- true if the
CompositeBehaviourshould terminate. false otherwise. - See Also:
CompositeBehaviour.checkTermination(boolean, int)
-
getCurrent
protected Behaviour getCurrent()
Get the current child- Specified by:
getCurrentin classCompositeBehaviour- See Also:
CompositeBehaviour.getCurrent()
-
getChildren
public Collection getChildren()
Return a Collection view of the children of thisParallelBehaviour- Specified by:
getChildrenin classCompositeBehaviour- See Also:
CompositeBehaviour.getChildren()
-
getTerminatedChildren
public Collection getTerminatedChildren()
Return a Collection view of the children of thisParallelBehaviourthat have already completed.
-
addSubBehaviour
public void addSubBehaviour(Behaviour b)
Add a sub behaviour to thisParallelBehaviour
-
removeSubBehaviour
public void removeSubBehaviour(Behaviour b)
Remove a sub behaviour from thisParallelBehaviour
-
reset
public void reset()
Resets this behaviour. This methods puts aParallelBehaviourback in initial state, besides callingreset()on each child behaviour recursively.- Overrides:
resetin classCompositeBehaviour
-
handle
protected void handle(Behaviour.RunnableChangedEvent rce)
Handle block/restart notifications. AParallelBehaviourobject is blocked only when all its children behaviours are blocked and becomes ready to run as soon as any of its children is runnable. This method takes care of the various possibilities.
-
-