Overview  Package   Class  Tree  Deprecated  Index  Help 
PREV CLASS   NEXT CLASS FRAMES    NO FRAMES    All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD

sajas.core.behaviours
Class WrapperBehaviour
java.lang.Object
  sajas.core.behaviours.Behaviour
      sajas.core.behaviours.WrapperBehaviour
All Implemented Interfaces:
jade.util.leap.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 the done() 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;
   }
 });
 


Nested classes/interfaces inherited from class sajas.core.behaviours.Behaviour
Behaviour.RunnableChangedEvent
Fields inherited from class sajas.core.behaviours.Behaviour
myAgent, myEvent, NOTIFY_DOWN, NOTIFY_UP, parent, STATE_BLOCKED, STATE_READY, STATE_RUNNING
Constructor Summary
WrapperBehaviour(Behaviour wrapped)
Method Summary
void
action()
          Runs the behaviour.
boolean
done()
          Check if this behaviour is done.
getDataStore()
          Return the private data store of this Behaviour.
getWrappedBehaviour()
protected void
handle(Behaviour.RunnableChangedEvent rce)
          Handler for block/restart events.
protected void
handleBlockEvent()
          This method is used internally by the framework.
void
handleRestartEvent()
          This method is used internally by the framework.
int
onEnd()
          This method is just an empty placeholder for subclasses.
void
onStart()
          This method is just an empty placeholders for subclasses.
void
reset()
          Restores behaviour initial state.
void
setAgent(Agent a)
          Associates this behaviour with the agent it belongs to.
void
setDataStore(DataStore ds)
          Set the private data store of this Behaviour
Methods inherited from class sajas.core.behaviours.Behaviour
actionWrapper, block, block, getAgent, getBehaviourName, getExecutionState, getParent, getRestartCounter, isRunnable, restart, root, setBehaviourName, setExecutionState
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
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:
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

handle
protected void handle(Behaviour.RunnableChangedEvent rce)
Description copied from class: Behaviour
Handler 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.
Overrides:
handle in class Behaviour
Parameters:
rce - The event to handle

setAgent
public void setAgent(Agent a)
Description copied from class: Behaviour
Associates this behaviour with the agent it belongs to. There is no need to call this method explicitly, since the addBehaviour() call takes care of the association transparently.
Overrides:
setAgent in class Behaviour
Parameters:
a - The agent this behaviour belongs to.

setDataStore
public void setDataStore(DataStore ds)
Description copied from class: Behaviour
Set the private data store of this Behaviour
Overrides:
setDataStore in class Behaviour
Parameters:
ds - the DataStore that this Behaviour will use as its private data store

getDataStore
public DataStore getDataStore()
Description copied from class: Behaviour
Return the private data store of this Behaviour. If it was null, a new DataStore is created and returned.
Overrides:
getDataStore in class Behaviour
Returns:
The private data store of this Behaviour

reset
public void reset()
Description copied from class: Behaviour
Restores behaviour initial state. This method must be implemented by concrete subclasses in such a way that calling reset() 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.
Overrides:
reset in class Behaviour

onStart
public void onStart()
Description copied from class: Behaviour
This 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 this Behaviour.
Overrides:
onStart in class Behaviour

action
public void action()
Description copied from class: Behaviour
Runs the behaviour. This abstract method must be implemented by Behavioursubclasses to perform ordinary behaviour duty. An agent schedules its behaviours calling their action() 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.
Overrides:
action in class Behaviour

done
public boolean done()
Description copied from class: Behaviour
Check if this behaviour is done. The agent scheduler calls this method to see whether a Behaviour still 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.
Overrides:
done in class Behaviour
Returns:
true if the behaviour has completely executed.

onEnd
public int onEnd()
Description copied from class: Behaviour
This 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 this Behaviour.
Note that onEnd is called after the behaviour has been removed from the pool of behaviours to be executed by an agent. Therefore calling reset() is not sufficient to cyclically repeat the task represented by this Behaviour. In order to achieve that, this Behaviour must be added again to the agent (using myAgent.addBehaviour(this)). The same applies to in the case of a Behaviour that is a child of a ParallelBehaviour.
Overrides:
onEnd in class Behaviour
Returns:
an integer code representing the termination value of the behaviour.

getWrappedBehaviour
public Behaviour getWrappedBehaviour()

Overview  Package   Class  Tree  Deprecated  Index  Help 
PREV CLASS   NEXT CLASS FRAMES    NO FRAMES    All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD

Java API documentation generated with DocFlex/Doclet 1.6.1 using JavadocPro template set.
DocFlex/Doclet is both a multi-format Javadoc doclet and a free edition of DocFlex/Javadoc, which is a template-driven programming tool for rapid development of any Javadoc-based Java API documentation generators (i.e. doclets). If you need to customize your Javadoc without writing a full-blown doclet from scratch, DocFlex/Javadoc may be the only tool able to help you! Find out more at www.docflex.com