Class 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 a CompositeBehaviour receives 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
    • Field Detail

      • currentExecuted

        protected boolean currentExecuted
    • 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 this CompositeBehaviour. This method executes children according to the scheduling policy defined by concrete subclasses that implements the scheduleFirst() and scheduleNext() methods.
        Specified by:
        action in class Behaviour
        See Also:
        CompositeBehaviour
      • done

        public final boolean done()
        Checks whether this behaviour has terminated.
        Specified by:
        done in class Behaviour
        Returns:
        true if this CompositeBehaviour has finished executing, falseotherwise.
      • 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 by onEnd()) 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 the CompositeBehaviour should terminate.
        Parameters:
        currentDone - a flag indicating whether the just executed child has completed or not.
        currentResult - the termination value (as returned by onEnd()) of the just executed child in the case this child has completed (otherwise this parameter is meaningless)
        Returns:
        true if the CompositeBehaviour should 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 this CompositeBehaviour
      • handleBlockEvent

        protected void handleBlockEvent()
        This method is used internally by the framework. Developer should not call or redefine it.
        Overrides:
        handleBlockEvent in class Behaviour
      • handleRestartEvent

        public void handleRestartEvent()
        This method is used internally by the framework. Developer should not call or redefine it.
        Overrides:
        handleRestartEvent in class Behaviour
      • reset

        public void reset()
        Puts a CompositeBehaviour back in initial state. The internal state is cleaned up and reset() is recursively called for each child behaviour.
        Overrides:
        reset in class 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:
        setAgent in class Behaviour
        Parameters:
        a - The agent this behaviour belongs to.
        See Also:
        Behaviour.setAgent(Agent a)
      • registerAsChild

        protected void registerAsChild​(Behaviour b)