Package jade.wrapper.gateway
Class GatewayBehaviour
- java.lang.Object
-
- jade.core.behaviours.Behaviour
-
- jade.core.behaviours.SimpleBehaviour
-
- jade.core.behaviours.CyclicBehaviour
-
- jade.wrapper.gateway.GatewayBehaviour
-
- All Implemented Interfaces:
Serializable,Serializable
public abstract class GatewayBehaviour extends CyclicBehaviour
This is a cyclic behaviour that processes the commands received via JadeGateway.JadeGatewayenables two alternative ways to implement a gateway that allows non-JADE code to communicate with JADE agents.
The first one is to extend theGatewayAgent(see its javadoc for reference).
The second one is to extend thisGatewayBehaviourand add an instance of this Behaviour to your own agent that will have to function as a gateway.- Version:
- $Date: $ $Revision: $
- Author:
- Fabio Bellifemine, Telecom Italia Lab
- 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 GatewayBehaviour()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaction()Runs the behaviour.intonEnd()This method is just an empty placeholder for subclasses.protected abstract voidprocessCommand(Object command)subclasses must implement this method.voidreleaseCommand(Object command)notify that the command has been processed and remove the command from the queue-
Methods inherited from class jade.core.behaviours.CyclicBehaviour
done
-
Methods inherited from class jade.core.behaviours.SimpleBehaviour
reset
-
Methods inherited from class jade.core.behaviours.Behaviour
actionWrapper, block, block, getAgent, getBehaviourName, getDataStore, getExecutionState, getParent, getRestartCounter, handle, handleBlockEvent, handleRestartEvent, isRunnable, onStart, restart, root, setAgent, setBehaviourName, setDataStore, setExecutionState
-
-
-
-
Method Detail
-
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
-
processCommand
protected abstract void processCommand(Object command)
subclasses must implement this method. The method is called each time a request to process a command is received from the JSP Gateway.The recommended pattern is the following implementation:
REMIND THAT WHEN THE COMMAND HAS BEEN PROCESSED, YOU MUST CALL THE METHODif (c instanceof Command1) execCommand1(c); else if (c instanceof Command2) execCommand2(c);releaseCommand. Sometimes, you might prefer launching a new Behaviour that asynchronously processes this command and release the command just when the Behaviour terminates, i.e. in itsonEnd()method.
-
releaseCommand
public final void releaseCommand(Object command)
notify that the command has been processed and remove the command from the queue- Parameters:
command- is the same object that was passed in the processCommand method
-
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.
-
-