Package jade.proto

Class TwoPhResponder

    • Constructor Detail

      • TwoPhResponder

        public TwoPhResponder​(Agent a,
                              MessageTemplate mt,
                              DataStore store)
        Constructor of the behaviour.
        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. The best practice is to have a MessageTemplate that matches the protocol slot; the static method createMessageTemplate might be usefull.
        store - the DataStore for this protocol behaviour
    • Method Detail

      • handleCfp

        protected ACLMessage handleCfp​(ACLMessage cfp)
        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:
        cfp - the received message
        Returns:
        the ACLMessage to be sent as a response (i.e. one of PROPOSE, FAILURE. Remind to use the method createReply of the class ACLMessage in order to create a valid reply message
        See Also:
        ACLMessage.createReply()
      • handleQueryIf

        protected ACLMessage handleQueryIf​(ACLMessage queryIf)
        This method is called after the QUERY-IF has been received. This default implementation return null which has the effect of sending no result notification. Programmers should override the method in case they need to react to this event.
        Parameters:
        queryIf - the received message
        Returns:
        the ACLMessage to be sent as a result notification (i.e. one of CONFIRM, INFORM, DISCONFIRM. Remind to use the method createReply of the class ACLMessage in order to create a valid reply message
        See Also:
        ACLMessage.createReply()
      • handleRejectProposal

        protected ACLMessage handleRejectProposal​(ACLMessage reject)
        This method is called after the REJECT-PROPOSAL has been received. This default implementation do nothing. Programmers should override the method in case they need to react to this event.
        Parameters:
        reject - the received message
        Returns:
        the ACLMessage to be sent as a result notification (i.e. an INFORM. Remind to use the method createReply of the class ACLMessage in order to create a valid reply message
        See Also:
        ACLMessage.createReply()
      • handleAcceptProposal

        protected ACLMessage handleAcceptProposal​(ACLMessage accept)
        This method is called after the ACCEPT-PROPOSAL has been received. This default implementation return null which has the effect of sending no result notification. Programmers should override the method in case they need to react to this event.
        Parameters:
        accept - the received message
        Returns:
        the ACLMessage to be sent as a result notification (i.e. an INFORM. Remind to use the method createReply of the class ACLMessage in order to create a valid reply message
        See Also:
        ACLMessage.createReply()
      • registerHandleCfp

        public void registerHandleCfp​(Behaviour b)
        This method allows to register a user defined Behaviour in the PREPARE_PROPOSE 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 PROPOSE_KEY key.
        Parameters:
        b - the Behaviour that will handle this state
      • registerHandleQueryIf

        public void registerHandleQueryIf​(Behaviour b)
        This method allows to register a user defined Behaviour in the HANDLE_QUERY_IF 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 REPLY_KEY key.
        Parameters:
        b - the Behaviour that will handle this state
      • registerHandleRejectProposal

        public void registerHandleRejectProposal​(Behaviour b)
        This method allows to register a user defined Behaviour in the HANDLE_REJECT 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 REPLY_KEY key.
        Parameters:
        b - the Behaviour that will handle this state
      • registerHandleAcceptProposal

        public void registerHandleAcceptProposal​(Behaviour b)
        This method allows to register a user defined Behaviour in the HANDLE_ACCEPTANCE 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 REPLY_KEY key.
        Parameters:
        b - the Behaviour that will handle this state
      • createMessageTemplate

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

        public void reset()
        Reset this behaviour.
      • checkInSequence

        protected boolean checkInSequence​(ACLMessage received)
        Check whether a received message complies with the protocol rules.
      • replySent

        protected void replySent​(int exitValue)
        This method can be redefined by protocol specific implementations to update the status of the protocol after a reply has been sent. This default implementation does nothing.
      • handleOutOfSequence

        protected void handleOutOfSequence​(ACLMessage msg)
        This method is called whenever a message is received that does not comply to the protocol rules. This default implementation does nothing. Programmers may override it in case they need to react to this event.
        Parameters:
        msg - the received out-of-sequence message.
      • registerHandleOutOfSequence

        public void registerHandleOutOfSequence​(Behaviour b)
        This method allows to register a user defined Behaviour in the HANDLE_OUT_OF_SEQ state. This behaviour would override the homonymous method. This method also sets the data store of the registered Behaviour to the DataStore of this current behaviour. The registered behaviour can retrieve the out of sequence ACLMessage object received from the datastore at the RECEIVED_KEY key.
        Parameters:
        b - the Behaviour that will handle this state
      • registerDSState

        protected void registerDSState​(Behaviour b,
                                       String name)
        Utility method to register a behaviour in a state of the protocol and set the DataStore appropriately