public abstract class GatewayBehaviour extends CyclicBehaviour
JadeGateway
enables two alternative ways to implement a gateway
that allows non-JADE code to communicate with JADE agents.
GatewayAgent
(see its javadoc for reference).
GatewayBehaviour
and add an instance
of this Behaviour to your own agent that will have to function as a gateway.Constructor and Description |
---|
GatewayBehaviour() |
Modifier and Type | Method and Description |
---|---|
void |
action()
Runs the behaviour.
|
int |
onEnd()
This method is just an empty placeholder for subclasses.
|
protected abstract void |
processCommand(java.lang.Object command)
subclasses must implement this method.
|
void |
releaseCommand(java.lang.Object command)
notify that the command has been processed and remove the command from the queue
|
done
reset
block, block, getAgent, getBehaviourName, getDataStore, getParent, isRunnable, onStart, restart, root, setAgent, setBehaviourName, setDataStore
public void action()
Behaviour
Behaviour
subclasses 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.action
in class Behaviour
CompositeBehaviour
protected abstract void processCommand(java.lang.Object command)
The recommended pattern is the following implementation:
if (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 its onEnd()
method.public final void releaseCommand(java.lang.Object command)
command
- is the same object that was passed in the processCommand methodpublic int onEnd()
Behaviour
Behaviour
.
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
.