Class GatewayBehaviour

  • All Implemented Interfaces:
    Serializable, Serializable

    public abstract class GatewayBehaviour
    extends CyclicBehaviour
    This is a cyclic behaviour that processes the commands received via JadeGateway. JadeGateway enables two alternative ways to implement a gateway that allows non-JADE code to communicate with JADE agents.
    The first one is to extend the GatewayAgent (see its javadoc for reference).
    The second one is to extend this GatewayBehaviour and 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
    • Constructor Detail

      • GatewayBehaviour

        public GatewayBehaviour()
    • Method Detail

      • 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.
        Specified by:
        action in class Behaviour
        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: if (c instanceof Command1) execCommand1(c); else if (c instanceof Command2) execCommand2(c);

        REMIND THAT WHEN THE COMMAND HAS BEEN PROCESSED, YOU MUST CALL THE METHOD 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.
      • 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: 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.