Package jade.proto

Class IteratedAchieveREInitiator

  • All Implemented Interfaces:
    Serializable, Serializable

    public class IteratedAchieveREInitiator
    extends AchieveREInitiator
    This class implements the initiator role in the iterated version of fipa-request like interaction protocols. In the iterated version, having received all the result notifications from the responders, the initiator may send further initiation messages. The session of such a protocol with a given responder terminates when one of the followings occurs: i) The initiator sends an explicit CANCEL message instead of the next initiation message to the responder. ii) The responder replies with a negative reply i.e. REFUSE, NOT_UNDERSTOOD or FAILURE ii) The responder attaches a termination flag to an INFORM result notification. That termination flag can be detected using the isSessionTerminated() method.
    Author:
    Giovanni Caire - TILab
    See Also:
    Serialized Form
    • Constructor Detail

      • IteratedAchieveREInitiator

        public IteratedAchieveREInitiator​(Agent a,
                                          ACLMessage msg)
        Construct an IteratedAchieveREInitiator with an empty DataStore
      • IteratedAchieveREInitiator

        public IteratedAchieveREInitiator​(Agent a,
                                          ACLMessage msg,
                                          DataStore store)
        Construct an IteratedAchieveREInitiator with a given DataStore
        Parameters:
        a - The agent performing the protocol
        msg - The message that must be used to initiate the protocol. Notice that the default implementation of the prepareRequest() method returns an array composed of only this message. The values of the slot reply-with is ignored and a different value is assigned automatically by this class for each receiver.
        store - The DataStore that will be used by this AchieveREInitiator
    • Method Detail

      • prepareForNextRound

        protected void prepareForNextRound()
      • getSession

        protected jade.proto.Initiator.ProtocolSession getSession​(ACLMessage msg,
                                                                  int sessionIndex)
        Return a ProtocolSession object to manage replies to a given initiation message
        Overrides:
        getSession in class AchieveREInitiator
      • handleInform

        protected void handleInform​(ACLMessage inform,
                                    Vector nextRequests)
        This method is called every time an 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 this method in case they need to react to this event.
        Parameters:
        inform - the received inform message
        nextRequest - the Vector of ACLMessage objects to be sent at next round
      • handleInform

        protected final void handleInform​(ACLMessage inform)
        This method is redefined to call the proper overloaded method
        Overrides:
        handleInform in class AchieveREInitiator
        Parameters:
        inform - the received inform message
      • handleAllResultNotifications

        protected void handleAllResultNotifications​(Vector resultNotifications,
                                                    Vector nextRequests)
        This method is called when all the result notification messages of the current round have been collected. By result notification message we intend here all the inform, failure 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 in case they need to react to this event by analysing all the messages in just one call.
        Parameters:
        resultNodifications - the Vector of ACLMessage object received
        nextRequest - the Vector of ACLMessage objects to be sent at next round
      • registerHandleInform

        public void registerHandleInform​(Behaviour b)
        This method allows to register a user defined Behaviour in the HANDLE_REFUSE 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 received inform ACLMessage object from the datastore at the REPLY_KEY key and the Vector of ACLMessage objects to be sent at next round at the ALL_NEXT_REQUESTS_KEY.
        Overrides:
        registerHandleInform in class AchieveREInitiator
        Parameters:
        b - the Behaviour that will handle this state
      • registerHandleAllResultNotifications

        public void registerHandleAllResultNotifications​(Behaviour b)
        This method allows to register a user defined Behaviour in the HANDLE_ALL_RESULT_NOTIFICATIONS 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 objects, received as a result notification, from the datastore at the ALL_RESULT_NOTIFICATIONS_KEY key and the Vector of ACLMessage objects to be sent at next round at the ALL_NEXT_REQUESTS_KEY.
        Overrides:
        registerHandleAllResultNotifications in class AchieveREInitiator
        Parameters:
        b - the Behaviour that will handle this state
      • isSessionTerminated

        public static boolean isSessionTerminated​(ACLMessage inform)
        Check if the responder has closed the session just after sending this inform message.
      • sendInitiations

        protected void sendInitiations​(Vector initiations)
        Create and initialize the Sessions and sends the initiation messages
      • 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
      • 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)