Package jade.core.behaviours
Class WrapperBehaviour
- java.lang.Object
-
- jade.core.behaviours.Behaviour
-
- jade.core.behaviours.WrapperBehaviour
-
- All Implemented Interfaces:
Serializable,Serializable
public class WrapperBehaviour extends Behaviour
This behaviour allows modifying on the fly the way an existing behaviour object works The following piece of code provides an example where we modify thedone()method of an existing behaviour object to print on the standard output a proper message when the behaviour is completing.Behaviour b = // get the behaviour object addBehaviour(new WrapperBehaviour(b) { public boolean done() { boolean ret = super.done(); if (ret) { System.out.println("done() method returned true --> The behaviour is completing!"); } return ret; } });- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jade.core.behaviours.Behaviour
Behaviour.RunnableChangedEvent
-
-
Field Summary
-
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 WrapperBehaviour(Behaviour wrapped)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaction()Runs the behaviour.booleandone()Check if this behaviour is done.DataStoregetDataStore()Return the private data store of thisBehaviour.BehaviourgetWrappedBehaviour()protected voidhandle(Behaviour.RunnableChangedEvent rce)Handler for block/restart events.protected voidhandleBlockEvent()This method is used internally by the framework.voidhandleRestartEvent()This method is used internally by the framework.intonEnd()This method is just an empty placeholder for subclasses.voidonStart()This method is just an empty placeholders for subclasses.voidreset()Restores behaviour initial state.voidsetAgent(Agent a)Associates this behaviour with the agent it belongs to.voidsetDataStore(DataStore ds)Set the private data store of thisBehaviour-
Methods inherited from class jade.core.behaviours.Behaviour
actionWrapper, block, block, getAgent, getBehaviourName, getExecutionState, getParent, getRestartCounter, isRunnable, restart, root, setBehaviourName, setExecutionState
-
-
-
-
Constructor Detail
-
WrapperBehaviour
public WrapperBehaviour(Behaviour wrapped)
-
-
Method Detail
-
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
-
handle
protected void handle(Behaviour.RunnableChangedEvent rce)
Description copied from class:BehaviourHandler for block/restart events. This method handles notification by copying its runnable state and then by simply forwarding the event when it is traveling upwards and by doing nothing when it is traveling downwards, since an ordinary behaviour has no children.
-
setAgent
public void setAgent(Agent a)
Description copied from class:BehaviourAssociates this behaviour with the agent it belongs to. There is no need to call this method explicitly, since theaddBehaviour()call takes care of the association transparently.- Overrides:
setAgentin classBehaviour- Parameters:
a- The agent this behaviour belongs to.- See Also:
Agent.addBehaviour(Behaviour b)
-
setDataStore
public void setDataStore(DataStore ds)
Description copied from class:BehaviourSet the private data store of thisBehaviour- Overrides:
setDataStorein classBehaviour- Parameters:
ds- theDataStorethat thisBehaviourwill use as its private data store
-
getDataStore
public DataStore getDataStore()
Description copied from class:BehaviourReturn the private data store of thisBehaviour. If it was null, a new DataStore is created and returned.- Overrides:
getDataStorein classBehaviour- Returns:
- The private data store of this
Behaviour
-
reset
public void reset()
Description copied from class:BehaviourRestores behaviour initial state. This method must be implemented by concrete subclasses in such a way that callingreset()on a behaviour object is equivalent to destroying it and recreating it back. The main purpose for this method is to realize multistep cyclic behaviours without needing expensive constructions an deletion of objects at each loop iteration. Remind to call super.reset() from the sub-classes.
-
onStart
public void onStart()
Description copied from class:BehaviourThis method is just an empty placeholders for subclasses. It is executed just once before starting behaviour execution. Therefore, it acts as a prolog to the task represented by thisBehaviour.
-
action
public void action()
Description copied from class:BehaviourRuns the behaviour. This abstract method must be implemented byBehavioursubclasses to perform ordinary behaviour duty. An agent schedules its behaviours calling theiraction()method; since all the behaviours belonging to the same agent are scheduled cooperatively, this method must not enter in an endless loop and should return as soon as possible to preserve agent responsiveness. To split a long and slow task into smaller section, recursive behaviour aggregation may be used.- Specified by:
actionin classBehaviour- See Also:
CompositeBehaviour
-
done
public boolean done()
Description copied from class:BehaviourCheck if this behaviour is done. The agent scheduler calls this method to see whether aBehaviourstill need to be run or it has completed its task. Concrete behaviours must implement this method to return their completion state. Finished behaviours are removed from the scheduling queue, while others are kept within to be run again when their turn comes again.
-
onEnd
public int onEnd()
Description copied from class:BehaviourThis method is just an empty placeholder for subclasses. It is invoked just once after this behaviour has ended. Therefore, it acts as an epilog for the task represented by thisBehaviour.
Note thatonEndis called after the behaviour has been removed from the pool of behaviours to be executed by an agent. Therefore callingreset()is not sufficient to cyclically repeat the task represented by thisBehaviour. In order to achieve that, thisBehaviourmust be added again to the agent (usingmyAgent.addBehaviour(this)). The same applies to in the case of aBehaviourthat is a child of aParallelBehaviour.
-
getWrappedBehaviour
public Behaviour getWrappedBehaviour()
-
-