Package jade.core.behaviours
Class CompositeBehaviour
- java.lang.Object
-
- jade.core.behaviours.Behaviour
-
- jade.core.behaviours.CompositeBehaviour
-
- All Implemented Interfaces:
Serializable,Serializable
- Direct Known Subclasses:
ParallelBehaviour,SerialBehaviour
public abstract class CompositeBehaviour extends Behaviour
An abstract superclass for behaviours composed by many parts. This class holds inside a number of children behaviours. When aCompositeBehaviourreceives it execution quantum from the agent scheduler, it executes one of its children according to some policy. This class must be extended to provide the actual scheduling policy to apply when running children behaviours.- Version:
- $Date$ $Revision$
- Author:
- Giovanni Rimassa - Universita' di Parma, Giovanni Caire - TILAB
- See Also:
SequentialBehaviour,ParallelBehaviour,FSMBehaviour, 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 protected booleancurrentExecuted-
Fields inherited from class jade.core.behaviours.Behaviour
myAgent, myEvent, NOTIFY_DOWN, NOTIFY_UP, parent, STATE_BLOCKED, STATE_READY, STATE_RUNNING
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedCompositeBehaviour()Default constructor, does not set the owner agent.protectedCompositeBehaviour(Agent a)This constructor sets the owner agent.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaction()Executes thisCompositeBehaviour.protected abstract booleancheckTermination(boolean currentDone, int currentResult)This methods is called after the execution of each child in order to check whether theCompositeBehaviourshould terminate.booleandone()Checks whether this behaviour has terminated.abstract CollectiongetChildren()This method returns a Collection view of the children of thisCompositeBehaviourprotected abstract BehaviourgetCurrent()This method returns the child behaviour currently scheduled for executionprotected voidhandleBlockEvent()This method is used internally by the framework.voidhandleRestartEvent()This method is used internally by the framework.protected voidregisterAsChild(Behaviour b)voidreset()Puts aCompositeBehaviourback in initial state.protected voidresetChildren()protected abstract voidscheduleFirst()This method schedules the first child to be executedprotected abstract voidscheduleNext(boolean currentDone, int currentResult)This method schedules the next child to be executedvoidsetAgent(Agent a)Associates this behaviour with the agent it belongs to.-
Methods inherited from class jade.core.behaviours.Behaviour
actionWrapper, block, block, getAgent, getBehaviourName, getDataStore, getExecutionState, getParent, getRestartCounter, handle, isRunnable, onEnd, onStart, restart, root, setBehaviourName, setDataStore, setExecutionState
-
-
-
-
Constructor Detail
-
CompositeBehaviour
protected CompositeBehaviour()
Default constructor, does not set the owner agent.
-
CompositeBehaviour
protected CompositeBehaviour(Agent a)
This constructor sets the owner agent.- Parameters:
a- The agent this behaviour belongs to.
-
-
Method Detail
-
action
public final void action()
Executes thisCompositeBehaviour. This method executes children according to the scheduling policy defined by concrete subclasses that implements thescheduleFirst()andscheduleNext()methods.- Specified by:
actionin classBehaviour- See Also:
CompositeBehaviour
-
done
public final boolean done()
Checks whether this behaviour has terminated.
-
scheduleFirst
protected abstract void scheduleFirst()
This method schedules the first child to be executed
-
scheduleNext
protected abstract void scheduleNext(boolean currentDone, int currentResult)This method schedules the next child to be executed- 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)
-
checkTermination
protected abstract boolean checkTermination(boolean currentDone, int currentResult)This methods is called after the execution of each child in order to check whether theCompositeBehaviourshould terminate.- 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.
-
getCurrent
protected abstract Behaviour getCurrent()
This method returns the child behaviour currently scheduled for execution
-
getChildren
public abstract Collection getChildren()
This method returns a Collection view of the children of thisCompositeBehaviour
-
handleBlockEvent
protected void handleBlockEvent()
This method is used internally by the framework. Developer should not call or redefine it.- Overrides:
handleBlockEventin classBehaviour
-
handleRestartEvent
public void handleRestartEvent()
This method is used internally by the framework. Developer should not call or redefine it.- Overrides:
handleRestartEventin classBehaviour
-
reset
public void reset()
Puts aCompositeBehaviourback in initial state. The internal state is cleaned up andreset()is recursively called for each child behaviour.
-
resetChildren
protected void resetChildren()
-
setAgent
public void setAgent(Agent a)
Associates this behaviour with the agent it belongs to. Overrides the method in the base class to propagate the setting to all children.- Overrides:
setAgentin classBehaviour- Parameters:
a- The agent this behaviour belongs to.- See Also:
Behaviour.setAgent(Agent a)
-
registerAsChild
protected void registerAsChild(Behaviour b)
-
-