Package jade.proto

Class TwoPh1Initiator

    • Field Detail

      • QUERYIF_KEY

        public final String QUERYIF_KEY
        key to retrieve from the DataStore of the behaviour the ACLMessage object passed in the constructor of the class.
      • ALL_QUERYIFS_KEY

        public final String ALL_QUERYIFS_KEY
        key to retrieve from the DataStore of the behaviour the Vector of QUERY_IF messages that have to be sent.
      • REPLY_KEY

        public final String REPLY_KEY
        key to retrieve from the DataStore of the behaviour the last ACLMessage object that has been received (null if the timeout expired).
      • ALL_RESPONSES_KEY

        public final String ALL_RESPONSES_KEY
        key to retrieve from the DataStore of the behaviour the Vector of all messages that have been received as response.
      • ALL_CONFIRMS_KEY

        public final String ALL_CONFIRMS_KEY
        key to retrieve from the DataStore of the behaviour the Vector of CONFIRM messages that have been received as response.
      • ALL_DISCONFIRMS_KEY

        public final String ALL_DISCONFIRMS_KEY
        key to retrieve from the DataStore of the behaviour the Vector of DISCONFIRM messages that have been received as response.
      • ALL_INFORMS_KEY

        public final String ALL_INFORMS_KEY
        key to retrieve from the DataStore of the behaviour the Vector of INFORM messages that have been received as response.
      • ALL_PENDINGS_KEY

        public final String ALL_PENDINGS_KEY
        key to retrieve from the DataStore of the behaviour the Vector of QUERY_IF messages for which a response has not been received yet.
      • INITIATION_K

        protected final String INITIATION_K
      • ALL_INITIATIONS_K

        protected final String ALL_INITIATIONS_K
      • REPLY_K

        protected final String REPLY_K
      • sessions

        protected Map sessions
    • Constructor Detail

      • TwoPh1Initiator

        public TwoPh1Initiator​(Agent a,
                               ACLMessage queryIf,
                               String outputKey)
        Constructs a TwoPh1Initiator behaviour.
        Parameters:
        a - The agent performing the protocol.
        conversationId - Conversation-id slot used for all the duration of phase1's protocol.
        inputKey - Data store key where behaviour can get queryIf messages prepared in the previous phase.
        outputKey - Data store key where the behaviour prepares a vector of messages which will be send by a TwoPh2Initiator behaviour. If phase 1 ends with all confirm or inform than messages prepared are accept-proposal, otherwise they are reject-proposal.
      • TwoPh1Initiator

        public TwoPh1Initiator​(Agent a,
                               ACLMessage queryIf,
                               String outputKey,
                               DataStore store)
        Constructs a TwoPh1Initiator behaviour.
        Parameters:
        a - The agent performing the protocol.
        conversationId - Conversation-id slot used for all the duration of phase1's protocol.
        inputKey - Data store key where behaviour can get queryIf messages prepared in the previous phase.
        outputKey - Data store key where the behaviour prepares a vector of messages which will be send by a TwoPh2Initiator behaviour. If phase 1 ends with all confirm or inform than messages prepared are accept-proposal, otherwise they are reject-proposal.
        store - DataStore that will be used by this TwoPh1Initiator.
    • Method Detail

      • onEnd

        public int onEnd()
        Description copied from class: FSMBehaviour
        Override the onEnd() method to return the exit value of the last executed state.
        Overrides:
        onEnd in class FSMBehaviour
        Returns:
        an integer code representing the termination value of the behaviour.
      • prepareQueryIfs

        protected Vector prepareQueryIfs​(ACLMessage queryIf)
        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 QUERY_IF) passed in the constructor. Programmers might prefer to override this method in order to return a vector of QUERY_IF objects for 1:N conversations.
        Parameters:
        queryIf - the ACLMessage object passed in the constructor
        Returns:
        a Vector of ACLMessage objects. The value of the reply-with slot is ignored and regenerated automatically by this class. Instead user can specify reply-by slot representing phase0 timeout.
      • 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
      • handleInform

        protected void handleInform​(ACLMessage inform)
        This method is called every time a inform 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:
        inform - the received propose message
      • handleAllResponses

        protected void handleAllResponses​(Vector responses,
                                          Vector confirms,
                                          Vector disconfirms,
                                          Vector informs,
                                          Vector pendings,
                                          Vector nextPhMsgs)
        This method is called 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:
        confirms - all confirms received
        disconfirms - all disconfirms received
        pendings - all queryIfs still pending
        responses - prepared responses for next phase: accept-proposal or reject-proposal
      • registerPrepareQueryIfs

        public void registerPrepareQueryIfs​(Behaviour b)
        This method allows to register a user-defined Behaviour in the PREPARE_QUERYIFS 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 Vector of ACLMessage objects to be sent into the datastore at the ALL_QUERYIFS_KEY key.
        Parameters:
        b - the Behaviour that will handle this state
      • registerHandleConfirm

        public void registerHandleConfirm​(Behaviour b)
        This method allows to register a user defined Behaviour in the HANDLE_CONFIRM 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. The registered behaviour can retrieve the confirm ACLMessage object received from the datastore at the REPLY_KEY key.
        Parameters:
        b - the Behaviour that will handle this state
      • registerHandleDisconfirm

        public void registerHandleDisconfirm​(Behaviour b)
        This method allows to register a user defined Behaviour in the HANDLE_DISCONFIRM 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. The registered behaviour can retrieve the disconfirm ACLMessage object received from the datastore at the REPLY_KEY key.
        Parameters:
        b - the Behaviour that will handle this state
      • registerHandleInform

        public void registerHandleInform​(Behaviour b)
        This method allows to register a user defined Behaviour in the HANDLE_INFORM 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. The registered behaviour can retrieve the inform ACLMessage object received from the datastore at the REPLY_KEY key.
        Parameters:
        b - the Behaviour that will handle this state
      • registerHandleAllResponses

        public void registerHandleAllResponses​(Behaviour b)
        This method allows to register a user defined Behaviour in the HANDLE_ALL_RESPONSES 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. The registered behaviour can retrieve the vector of ACLMessage confirms, disconfirms, informs, pending and responses from the datastore at ALL_CONFIRMS_KEY, ALL_DISCONFIRMS_KEY, ALL_INFORMS_KEY, ALL_PH1_PENDINGS_KEY and output field.
        Parameters:
        b - the Behaviour that will handle this state
      • getToBeReset

        protected String[] getToBeReset()
        Return the states that must be reset before they are visited again. Note that resetting a state before visiting it again is required only if - The onStart() method is redefined - The state has an "internal memory"
      • prepareInitiations

        protected final Vector prepareInitiations​(ACLMessage initiation)
        Prepare vector containing queryIfs.
        Parameters:
        initiation - queryIf passed in the constructor
        Returns:
        Vector of queryIfs
      • sendInitiations

        protected final void sendInitiations​(Vector initiations)
        This method sets for all prepared queryIfs conversation-id slot (with value passed in the constructor), protocol slot and reply-with slot with a unique value constructed by concatenating receiver's agent name and phase number (i.e. 1). After that it sends all cfps.
        Parameters:
        initiations - vector prepared in PREPARE_QUERYIFS state
      • checkInSequence

        protected final boolean checkInSequence​(ACLMessage reply)
        Check whether a reply is in-sequence and than update the appropriate Session and removes corresponding queryif from vector of pendings.
        Parameters:
        reply - message received
        Returns:
        true if reply is compliant with flow of protocol, false otherwise
      • checkSessions

        protected final int checkSessions​(ACLMessage reply)
        Check if there are still active sessions or if timeout is expired.
        Parameters:
        reply - last message received
        Returns:
        ALL_RESPONSES_RECEIVED or -1 (still active sessions)
      • initializeDataStore

        protected void initializeDataStore​(ACLMessage msg)
        Initialize the data store.
        Parameters:
        msg - Ignored
      • getSession

        protected jade.proto.Initiator.ProtocolSession getSession​(ACLMessage msg,
                                                                  int sessionIndex)
        Return a ProtocolSession object to manage replies to a given initiation message
      • handleNotUnderstood

        protected void handleNotUnderstood​(ACLMessage notUnderstood)
        This method is called every time a not-understood 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:
        notUnderstood - the received not-understood 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 failure message
      • handleOutOfSequence

        protected void handleOutOfSequence​(ACLMessage msg)
        This method is called every time a message is received, 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
      • registerPrepareInitiations

        protected void registerPrepareInitiations​(Behaviour b)
        Attach a behaviour to the Prepare-initiations protocol state.
        Parameters:
        b - The behaviour object to be executed in the Prepare-initiations state.
      • registerHandleNotUnderstood

        public void registerHandleNotUnderstood​(Behaviour b)
        This method allows to register a user defined Behaviour in the HANDLE_NOT_UNDERSTOOD 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. The registered behaviour can retrieve the not-understood ACLMessage object received from the datastore at the REPLY_KEY key.
        Parameters:
        b - the Behaviour that will handle this state
      • registerHandleFailure

        public void registerHandleFailure​(Behaviour b)
        This method allows to register a user defined Behaviour in the HANDLE_FAILURE 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. The registered behaviour can retrieve the failure ACLMessage object received from the datastore at the REPLY_KEY key.
        Parameters:
        b - the Behaviour that will handle this state
      • 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 set 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 REPLY_KEY key.
        Parameters:
        b - the Behaviour that will handle this state
      • reset

        public void reset()
        reset this behaviour by putting a null ACLMessage as message to be sent
        Overrides:
        reset in class FSMBehaviour
      • reset

        public void reset​(ACLMessage msg)
        reset this behaviour
        Parameters:
        msg - is the ACLMessage to be sent
      • reinit

        protected void reinit()
        Re-initialize the internal state without performing a complete reset.
      • onStart

        public void onStart()
        Override the onStart() method to initialize the vectors that will keep all the replies in the data store.
        Overrides:
        onStart in class Behaviour
      • setDataStore

        public void setDataStore​(DataStore ds)
        Override the setDataStore() method to propagate this setting to all children.
        Overrides:
        setDataStore in class Behaviour
        Parameters:
        ds - the DataStore that this Behaviour will use as its private data store
      • createConvId

        protected String createConvId​(Vector msgs)
        Create a new conversation identifier to begin a new interaction.
        Parameters:
        msgs - A vector of ACL messages. If the first one has a non-empty :conversation-id slot, its value is used, else a new conversation identifier is generated.
      • adjustReplyTemplate

        protected void adjustReplyTemplate​(ACLMessage msg)