Package jade.core.behaviours
Class ThreadedBehaviourFactory.ThreadedBehaviourWrapper
- java.lang.Object
-
- jade.core.behaviours.Behaviour
-
- jade.core.behaviours.ThreadedBehaviourFactory.ThreadedBehaviourWrapper
-
- All Implemented Interfaces:
Serializable,Serializable,Runnable
- Enclosing class:
- ThreadedBehaviourFactory
public class ThreadedBehaviourFactory.ThreadedBehaviourWrapper extends Behaviour implements Runnable
Inner class ThreadedBehaviourWrapper This class is declared public for debugging purpose only- 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
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaction()Runs the behaviour.booleandone()Check if this behaviour is done.BehaviourgetBehaviour()DataStoregetDataStore()Return the private data store of thisBehaviour.ThreadgetThread()StringgetThreadState()protected voidhandle(Behaviour.RunnableChangedEvent rce)Propagate a DOWNWARDS event (typically this happens when this ThreadedBehaviourWrapper is added as a child of a CompositeBehaviour and the latter, or an ancestor, is blocked/restarted) to the wrapped threaded behaviour.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.voidrestart()Propagate a restart() call (typically this happens when this ThreadedBehaviourWrapped is directly added to the agent Scheduler and a message is received) to the wrapped threaded behaviour.voidrun()voidsetDataStore(DataStore ds)Set the private data store of thisBehaviourprotected voidsetParent(CompositeBehaviour parent)Propagate the parent to the wrapped behaviour.-
Methods inherited from class jade.core.behaviours.Behaviour
actionWrapper, block, block, getAgent, getBehaviourName, getExecutionState, getParent, getRestartCounter, handleBlockEvent, handleRestartEvent, isRunnable, root, setAgent, setBehaviourName, setExecutionState
-
-
-
-
Method Detail
-
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.
-
setParent
protected void setParent(CompositeBehaviour parent)
Propagate the parent to the wrapped behaviour. NOTE that theparentmember variable of the wrapped behaviour must point to the DummyParentBehaviour --> From the wrapped behaviour accessing the actual parent must always be retrieved through the getParent() method.
-
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.
-
restart
public void restart()
Propagate a restart() call (typically this happens when this ThreadedBehaviourWrapped is directly added to the agent Scheduler and a message is received) to the wrapped threaded behaviour.- Overrides:
restartin classBehaviour- See Also:
Behaviour.block()
-
handle
protected void handle(Behaviour.RunnableChangedEvent rce)
Propagate a DOWNWARDS event (typically this happens when this ThreadedBehaviourWrapper is added as a child of a CompositeBehaviour and the latter, or an ancestor, is blocked/restarted) to the wrapped threaded behaviour. If the event is a restart, also notify the dedicated thread.
-
getThread
public final Thread getThread()
-
getBehaviour
public final Behaviour getBehaviour()
-
getThreadState
public final String getThreadState()
-
-