Package jade.proto

Class TwoPhInitiator

    • Constructor Detail

      • TwoPhInitiator

        public TwoPhInitiator​(Agent a,
                              ACLMessage cfp)
        Constructs a TwoPhInitiator behaviour.
        Parameters:
        a - The agent performing the protocol.
        cfp - The message that must be used to initiate the protocol. Notice that the default implementation of the prepareCfps method returns an array composed of that message only.
      • TwoPhInitiator

        public TwoPhInitiator​(Agent a,
                              ACLMessage cfp,
                              DataStore ds)
        Constructs a TwoPhInitiator behaviour.
        Parameters:
        a - The agent performing the protocol.
        cfp - The message that must be used to initiate the protocol. Notice that the default implementation of the prepareCfps method returns an array composed of that message only.
        ds - DataStore that will be used by this TwoPhInitiator.
    • Method Detail

      • prepareCfps

        protected Vector prepareCfps​(ACLMessage cfp)
        This method must return the vector of ACLMessage objects to be sent. It is called in the first state of this protocol. This default implementation just returns the ACLMessage object (a CFP) passed in the constructor. Programmers might prefer to override this method in order to return a vector of CFP objects for 1:N conversations.
        Parameters:
        cfp - the ACLMessage object passed in the constructor
        Returns:
        a vector of ACLMessage objects. The values of the slot reply-with and conversation-id are ignored and regenerated automatically by this class. Instead user can specify reply-by slot representing phase0 timeout.
      • handlePropose

        protected void handlePropose​(ACLMessage propose)
        This method is called every time a propose message is received, which is not out-of-sequence according to the protocol rules. This default implementation does nothing; programmers might wish to override the method in case they need to react to this event.
        Parameters:
        propose - the received propose message
      • handleFailure

        protected void handleFailure​(ACLMessage failure)
        This method is called every time a failure message is received, which is not out-of-sequence according to the protocol rules. This default implementation does nothing; programmers might wish to override the method in case they need to react to this event.
        Parameters:
        failure - the received propose message
      • handleAllPh0Responses

        protected void handleAllPh0Responses​(Vector responses,
                                             Vector proposes,
                                             Vector pendings,
                                             Vector nextPhMsgs)
        This method is called when all the responses of phase 0 have been collected or when the timeout is expired. The used timeout is the minimum value of the slot reply-By of all the CFP messages sent.By response message we intend here all the propose, failure, not-understood received messages, which are not out-of-sequence according to the protocol rules. This default implementation does nothing; programmers might wish to override this method to modify the Vector of initiation messages (nextPhMsgs) for next phase. More in details this Vector already includes messages with the performative set according to the default protocol rules i.e. QUERY_IF (if all responders replied with PROPOSE) or REJECT_PROPOSAL (if at least one responder failed or didn't reply). In particular, by setting the reply-by slot, users can specify a timeout for next phase.
        Parameters:
        responses - The Vector of all messages received as response in phase 0
        proposes - The Vector of PROPOSE messages received as response in phase 0
        pendings - The Vector of CFP messages for which a response has not been received yet.
        nextPhMsgs - The Vector of initiation messages for next phase already filled with QUERY_IF messages (if all responders replied with PROPOSE) or REJECT_PROPOSAL (if at least one responder failed or didn't reply).
      • handleConfirm

        protected void handleConfirm​(ACLMessage confirm)
        This method is called every time a confirm message is received, which is not out-of-sequence according to the protocol rules. This default implementation does nothing; programmers might wish to override the method in case they need to react to this event.
        Parameters:
        confirm - the received propose message
      • handleDisconfirm

        protected void handleDisconfirm​(ACLMessage disconfirm)
        This method is called every time a disconfirm message is received, which is not out-of-sequence according to the protocol rules. This default implementation does nothing; programmers might wish to override the method in case they need to react to this event.
        Parameters:
        disconfirm - the received propose message
      • handlePh1Inform

        protected void handlePh1Inform​(ACLMessage inform)
        This method is called every time an inform message in phase 1 is received, which is not out-of-sequence according to the protocol rules. This default implementation does nothing; programmers might wish to override the method in case they need to react to this event.
        Parameters:
        inform - the received propose message
      • handleAllPh1Responses

        protected void handleAllPh1Responses​(Vector responses,
                                             Vector confirms,
                                             Vector disconfirms,
                                             Vector informs,
                                             Vector pendings,
                                             Vector nextPhMsgs)
        This method is called in phase 1 when all the responses have been collected or when the timeout is expired. The used timeout is the minimum value of the slot reply-By of all the sent messages. By response message we intend here all the disconfirm, confirm, inform received messages, which are not out-of-sequence according to the protocol rules. This default implementation does nothing; programmers might wish to override the method in case they need to react to this event by analysing all the messages in just one call.
        Parameters:
        responses - The Vector of all messages received as response in phase 1
        confirms - all confirms received
        disconfirms - all disconfirms received
        pendings - all queryIfs still pending
        nextPhMsgs - prepared responses for next phase: accept-proposal or reject-proposal
      • handlePh2Inform

        protected void handlePh2Inform​(ACLMessage inform)
        This method is called every time an inform message in phase 2 is received, which is not out-of-sequence according to the protocol rules. This default implementation does nothing; programmers might wish to override the method in case they need to react to this event.
        Parameters:
        inform - the received propose message
      • handleOldResponse

        protected void handleOldResponse​(ACLMessage old)
        This method is called every time a failure, a disconfirm or an inform message is received in phase 2, which is not out-of-sequence according to the protocol rules. This default implementation does nothing; programmers might wish to override the method in case they need to react to this event.
        Parameters:
        old - the received propose message
      • handleAllPh2Responses

        protected void handleAllPh2Responses​(Vector responses)
        This method is called in phase 2 when all the responses have been collected. By response message we intend here all the inform (phase 2), failure (phase 0), disconfirm (phase 1) and inform (phase 1) received messages, which are not out-of-sequence according to the protocol rules. This default implementation does nothing; programmers might wish to override the method in case they need to react to this event by analysing all the messages in just one call.
        Parameters:
        responses - all responses received in phase 2
      • handleOutOfSequence

        protected void handleOutOfSequence​(ACLMessage msg)
        This method is called every time a message is received in phase n (use getCurrentPhase method to know the phase), which is out-of-sequence according to the protocol rules. This default implementation does nothing; programmers might wish to override the method in case they need to react to this event.
        Parameters:
        msg - the received message
      • handleNotUnderstood

        protected void handleNotUnderstood​(ACLMessage notUnderstood)
      • getCurrentPhase

        public String getCurrentPhase()