Package jade.proto

Class ProposeResponder

  • All Implemented Interfaces:
    FIPANames.InteractionProtocol, Serializable, Serializable

    public class ProposeResponder
    extends FSMBehaviour
    implements FIPANames.InteractionProtocol
    Behaviour class for fipa-propose Responder role. This behaviour implements the fipa-propose interaction protocol from the point of view of a responder to a propose (propose) message.

    The API of this class is similar and homogeneous to the AchieveREResponder.

    When a message arrives that matches the message template passed to the constructor, the callback method prepareResponse is executed that must return the wished response, for instance the ACCEPT_PROPOSAL reply message. Any other type of returned communicative act is sent and then closes the protocol.

    If a message were received, with the same value of this conversation-id, but that does not comply with the FIPA protocol, than the method handleOutOfSequence would be called.

    This class can be extended by the programmer by overriding all the needed handle methods or, in alternative, appropriate behaviours can be registered for each handle via the registerHandle-type of methods. This last case is more difficult to use and proper care must be taken to properly use the DataStore of the Behaviour as a shared memory mechanism with the registered behaviour.

    Read carefully the section of the JADE programmer's guide that describes the usage of this class.

    Version:
    $Date$ $Revision$
    Author:
    Jerome Picault - Motorola Labs
    See Also:
    ProposeInitiator, AchieveREResponder, Serialized Form
    • Field Detail

      • PROPOSE_KEY

        public final String PROPOSE_KEY
        key to retrieve from the DataStore of the behaviour the ACLMessage object sent by the initiator.
      • RESPONSE_KEY

        public final String RESPONSE_KEY
        key to retrieve from the DataStore of the behaviour the ACLMessage object sent as a response to the initiator.
    • Constructor Detail

      • ProposeResponder

        public ProposeResponder​(Agent a,
                                MessageTemplate mt,
                                DataStore store)
        Constructor.
        Parameters:
        a - is the reference to the Agent object
        mt - is the MessageTemplate that must be used to match the initiator message. Take care that if mt is null every message is consumed by this protocol.
        store - the DataStore for this protocol
    • Method Detail

      • createMessageTemplate

        public static MessageTemplate createMessageTemplate​(String iprotocol)
        This static method can be used to set the proper message template (based on the interaction protocol and the performative) into the constructor of this behaviour.
        See Also:
        FIPANames.InteractionProtocol
      • reset

        public void reset()
        Reset this behaviour.
        Overrides:
        reset in class FSMBehaviour
      • reset

        public void reset​(MessageTemplate mt)
        This method allows to change the MessageTemplate that defines what messages this ProposeResponder will react to and reset the protocol.
      • prepareResponse

        protected ACLMessage prepareResponse​(ACLMessage propose)
                                      throws NotUnderstoodException,
                                             RefuseException
        This method is called when the initiator's message is received that matches the message template passed in the constructor. This default implementation return null which has the effect of sending no reponse. Programmers should override the method in case they need to react to this event.
        Parameters:
        propose - the received message
        Returns:
        the ACLMessage to be sent as a response (i.e. one of accept_proposal, reject_proposal, not-understood. Remind to use the method createReply of the class ACLMessage in order to create a good reply message
        Throws:
        NotUnderstoodException
        RefuseException
        See Also:
        ACLMessage.createReply()
      • registerPrepareResponse

        public void registerPrepareResponse​(Behaviour b)
        This method allows to register a user defined Behaviour in the PREPARE_RESPONSE state. This behaviour would override the homonymous method. This method also set the data store of the registered Behaviour to the DataStore of this current behaviour. It is responsibility of the registered behaviour to put the response to be sent into the datastore at the RESPONSE_KEY key.
        Parameters:
        b - the Behaviour that will handle this state