Package jade.proto

Class SubscriptionResponder

    • Field Detail

      • SUBSCRIPTION_KEY

        public final String SUBSCRIPTION_KEY
        key to retrieve from the DataStore of the behaviour the ACLMessage object sent by the initiator as a subscription.
      • CANCEL_KEY

        public final String CANCEL_KEY
        key to retrieve from the DataStore of the behaviour the ACLMessage object sent by the initiator to cancel a subscription.
      • 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.
    • Method Detail

      • createMessageTemplate

        public static MessageTemplate createMessageTemplate​(int perf)
        This static method can be used to set the proper message Template (based on the performative of the subscription message) into the constructor of this behaviour.
        Parameters:
        perf - The performative of the subscription message
      • reset

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

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

        protected ACLMessage handleSubscription​(ACLMessage subscription)
                                         throws NotUnderstoodException,
                                                RefuseException
        This method is called when a subscription message is received that matches the message template specified in the constructor. The default implementation creates an new Subscription object, stores it internally and notify the SubscriptionManager used by this responder if any. Then it returns null which has the effect of sending no response. Programmers in general do not need to override this method. In case they need to manage Subscription objects in an application specific way they should rather use a SubscriptionManager with the register() method properly implemented. However they could override it in case they need to react to the reception of a subscription message in a different way, e.g. by sending back an AGREE message.
        Parameters:
        subscription - the received message
        Returns:
        the ACLMessage to be sent as a response: typically one of agree, refuse, not-understood or null if no response must be sent back.
        Throws:
        NotUnderstoodException
        RefuseException
      • handleCancel

        protected ACLMessage handleCancel​(ACLMessage cancel)
                                   throws FailureException
        This method is called when a CANCEL message is received for a previous subscription. The default implementation retrieves the Subscription object the received cancel message refers to, notifies the SubscriptionManager used by this responder if any and remove the Subscription from its internal structures. Then it returns null which has the effect of sending no response. Programmers in general do not need to override this method. In case they need to manage Subscription objects in an application specific way they should rather use a SubscriptionManager with the deregister() method properly implemented. However they could override it in case they need to react to the reception of a cancel message in a different way, e.g. by sending back an INFORM.
        Parameters:
        cancel - the received CANCEL message
        Returns:
        the ACLMessage to be sent as a response to the cancel operation: typically one of inform and failure or null if no response must be sent back.
        Throws:
        FailureException
      • registerHandleSubscription

        public void registerHandleSubscription​(Behaviour b)
        This method allows to register a user defined Behaviour in the HANDLE_SUBSCRIPTION state. This behaviour overrides the homonymous method. This method also sets 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 (if any) to be sent back into the datastore at the RESPONSE_KEY key. The incoming subscription message can be retrieved from the datastore at the SUBSCRIPTION_KEY key
        Parameters:
        b - the Behaviour that will handle this state
      • registerPrepareResponse

        public void registerPrepareResponse​(Behaviour b)
        Deprecated.
        Use registerHandleSubscription() instead.
      • registerHandleCancel

        public void registerHandleCancel​(Behaviour b)
        This method allows to register a user defined Behaviour in the HANDLE_CANCEL state. This behaviour overrides the homonymous method. This method also sets 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 (if any) to be sent back into the datastore at the RESPONSE_KEY key. The incoming CANCEL message can be retrieved from the datastore at the CANCEL_KEY key
        Parameters:
        b - the Behaviour that will handle this state
      • getSubscription

        public SubscriptionResponder.Subscription getSubscription​(ACLMessage msg)
        Utility method to correctly retrieve the Subscription object that is related to the conversation message msg belongs to.
        Parameters:
        msg - The message whose conversation-id indicates the conversation
        Returns:
        the Subscription object related to the conversation the given message belongs to
      • getSubscription

        public SubscriptionResponder.Subscription getSubscription​(String convId)
        Utility method to correctly retrieve the Subscription object that is related a given conversation.
        Parameters:
        convId - The id of the conversation
        Returns:
        the Subscription object related to the given conversation
      • getSubscriptions

        public Vector getSubscriptions​(AID subscriber)
        Utility method that retrieves all Subscription-s done by a given agent
        Parameters:
        subscriber - The AID of the agent whose subscriptions must be retrieved
        Returns:
        A Vector including all Subscription-s made by the given agent
      • getSubscriptions

        public Vector getSubscriptions()
        Utility method that retrieves all Subscription-s managed by this SubscriptionResponder
        Returns:
        A Vector including all Subscription-s managed by this SubscriptionResponder