Package jade.proto
Class SubscriptionResponder
- java.lang.Object
-
- jade.core.behaviours.Behaviour
-
- jade.core.behaviours.CompositeBehaviour
-
- jade.core.behaviours.SerialBehaviour
-
- jade.core.behaviours.FSMBehaviour
-
- jade.proto.SubscriptionResponder
-
- All Implemented Interfaces:
FIPANames.InteractionProtocol,Serializable,Serializable
public class SubscriptionResponder extends FSMBehaviour implements FIPANames.InteractionProtocol
This is a single homogeneous and effective implementation of the responder role in all the FIPA-Subscribe-like interaction protocols defined by FIPA, that is all those protocols where the initiator sends a single "subscription" message and receives notifications each time a given condition becomes true.- Author:
- Elisabetta Cortese - TILAB, Giovanni Caire - TILAB
- See Also:
SubscriptionInitiator, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSubscriptionResponder.SubscriptionInner calss Subscriptionstatic interfaceSubscriptionResponder.SubscriptionManagerInner interface SubscriptionManager.-
Nested classes/interfaces inherited from class jade.core.behaviours.Behaviour
Behaviour.RunnableChangedEvent
-
-
Field Summary
Fields Modifier and Type Field Description StringCANCEL_KEYkey to retrieve from the DataStore of the behaviour the ACLMessage object sent by the initiator to cancel a subscription.protected SubscriptionResponder.SubscriptionManagermySubscriptionManagerTheSubscriptionManagerused by thisSubscriptionResponderto register subscriptionsStringRESPONSE_KEYkey to retrieve from the DataStore of the behaviour the ACLMessage object sent as a response to the initiator.StringSUBSCRIPTION_KEYkey to retrieve from the DataStore of the behaviour the ACLMessage object sent by the initiator as a subscription.-
Fields inherited from class jade.core.behaviours.FSMBehaviour
currentName, lastStates
-
Fields inherited from class jade.core.behaviours.CompositeBehaviour
currentExecuted
-
Fields inherited from class jade.core.behaviours.Behaviour
myAgent, myEvent, NOTIFY_DOWN, NOTIFY_UP, parent, STATE_BLOCKED, STATE_READY, STATE_RUNNING
-
Fields inherited from interface jade.domain.FIPANames.InteractionProtocol
FIPA_BROKERING, FIPA_CONTRACT_NET, FIPA_DUTCH_AUCTION, FIPA_ENGLISH_AUCTION, FIPA_ITERATED_CONTRACT_NET, FIPA_PROPOSE, FIPA_QUERY, FIPA_RECRUITING, FIPA_REQUEST, FIPA_REQUEST_WHEN, FIPA_SUBSCRIBE, ITERATED_FIPA_REQUEST
-
-
Constructor Summary
Constructors Constructor Description SubscriptionResponder(Agent a, MessageTemplate mt)Construct a SubscriptionResponder behaviour that handles subscription messages matching a given template.SubscriptionResponder(Agent a, MessageTemplate mt, SubscriptionResponder.SubscriptionManager sm)Construct a SubscriptionResponder behaviour that handles subscription messages matching a given template and notifies a given SubscriptionManager about subscription/un-subscription events.SubscriptionResponder(Agent a, MessageTemplate mt, SubscriptionResponder.SubscriptionManager sm, DataStore store)Construct a SubscriptionResponder behaviour that handles subscription messages matching a given template, notifies a given SubscriptionManager about subscription/un-subscription events and uses a given DataStore.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static MessageTemplatecreateMessageTemplate(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.SubscriptionResponder.SubscriptioncreateSubscription(ACLMessage subsMsg)Utility method to correctly create a newSubscriptionobject managed by thisSubscriptionResponderSubscriptionResponder.SubscriptiongetSubscription(ACLMessage msg)Utility method to correctly retrieve theSubscriptionobject that is related to the conversation messagemsgbelongs to.SubscriptionResponder.SubscriptiongetSubscription(String convId)Utility method to correctly retrieve theSubscriptionobject that is related a given conversation.VectorgetSubscriptions()Utility method that retrieves all Subscription-s managed by thisSubscriptionResponderVectorgetSubscriptions(AID subscriber)Utility method that retrieves all Subscription-s done by a given agentprotected ACLMessagehandleCancel(ACLMessage cancel)This method is called when a CANCEL message is received for a previous subscription.protected ACLMessagehandleSubscription(ACLMessage subscription)This method is called when a subscription message is received that matches the message template specified in the constructor.protected ACLMessageprepareResponse(ACLMessage subscription)Deprecated.Use handleSubscription() insteadvoidregisterHandleCancel(Behaviour b)This method allows to register a user definedBehaviourin the HANDLE_CANCEL state.voidregisterHandleSubscription(Behaviour b)This method allows to register a user definedBehaviourin the HANDLE_SUBSCRIPTION state.voidregisterPrepareResponse(Behaviour b)Deprecated.Use registerHandleSubscription() instead.voidreset()Reset this behaviourvoidreset(MessageTemplate mt)This method resets the protocol and allows to change theMessageTemplatethat defines what messages this SubscriptionResponder will react to.-
Methods inherited from class jade.core.behaviours.FSMBehaviour
checkTermination, deregisterDefaultTransition, deregisterState, deregisterTransition, forceTransitionTo, getChildren, getCurrent, getLastExitValue, getName, getPrevious, getState, handleInconsistentFSM, handleStateEntered, hasDefaultTransition, onEnd, registerDefaultTransition, registerDefaultTransition, registerFirstState, registerLastState, registerState, registerTransition, registerTransition, resetStates, scheduleFirst, scheduleNext, stringifyTransitionTable
-
Methods inherited from class jade.core.behaviours.SerialBehaviour
handle
-
Methods inherited from class jade.core.behaviours.CompositeBehaviour
action, done, handleBlockEvent, handleRestartEvent, registerAsChild, resetChildren, setAgent
-
Methods inherited from class jade.core.behaviours.Behaviour
actionWrapper, block, block, getAgent, getBehaviourName, getDataStore, getExecutionState, getParent, getRestartCounter, isRunnable, onStart, restart, root, setBehaviourName, setDataStore, setExecutionState
-
-
-
-
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.
-
mySubscriptionManager
protected SubscriptionResponder.SubscriptionManager mySubscriptionManager
TheSubscriptionManagerused by thisSubscriptionResponderto register subscriptions
-
-
Constructor Detail
-
SubscriptionResponder
public SubscriptionResponder(Agent a, MessageTemplate mt)
Construct a SubscriptionResponder behaviour that handles subscription messages matching a given template.
-
SubscriptionResponder
public SubscriptionResponder(Agent a, MessageTemplate mt, SubscriptionResponder.SubscriptionManager sm)
Construct a SubscriptionResponder behaviour that handles subscription messages matching a given template and notifies a given SubscriptionManager about subscription/un-subscription events.
-
SubscriptionResponder
public SubscriptionResponder(Agent a, MessageTemplate mt, SubscriptionResponder.SubscriptionManager sm, DataStore store)
Construct a SubscriptionResponder behaviour that handles subscription messages matching a given template, notifies a given SubscriptionManager about subscription/un-subscription events and uses a given DataStore.- Parameters:
a- is the reference to the Agent performing this behaviour.mt- is the MessageTemplate that must be used to match subscription messages sent by the initiators. Take care that if mt is null every message is consumed by this protocol.sm- TheSubscriptionManagerobject that is notified about subscription/un-subscription eventsstore- the DataStore that will be used by protocol
-
-
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:
resetin classFSMBehaviour
-
reset
public void reset(MessageTemplate mt)
This method resets the protocol and allows to change theMessageTemplatethat 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 newSubscriptionobject, stores it internally and notify theSubscriptionManagerused 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 aSubscriptionManagerwith theregister()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-understoodor null if no response must be sent back. - Throws:
NotUnderstoodExceptionRefuseException
-
prepareResponse
protected ACLMessage prepareResponse(ACLMessage subscription) throws NotUnderstoodException, RefuseException
Deprecated.Use handleSubscription() instead
-
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 theSubscriptionobject the received cancel message refers to, notifies theSubscriptionManagerused 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 aSubscriptionManagerwith thederegister()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
informandfailureor null if no response must be sent back. - Throws:
FailureException
-
registerHandleSubscription
public void registerHandleSubscription(Behaviour b)
This method allows to register a user definedBehaviourin the HANDLE_SUBSCRIPTION state. This behaviour overrides the homonymous method. This method also sets the data store of the registeredBehaviourto 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 theRESPONSE_KEYkey. The incoming subscription message can be retrieved from the datastore at theSUBSCRIPTION_KEYkey- 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 definedBehaviourin the HANDLE_CANCEL state. This behaviour overrides the homonymous method. This method also sets the data store of the registeredBehaviourto 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 theRESPONSE_KEYkey. The incoming CANCEL message can be retrieved from the datastore at theCANCEL_KEYkey- Parameters:
b- the Behaviour that will handle this state
-
createSubscription
public SubscriptionResponder.Subscription createSubscription(ACLMessage subsMsg)
Utility method to correctly create a newSubscriptionobject managed by thisSubscriptionResponder
-
getSubscription
public SubscriptionResponder.Subscription getSubscription(ACLMessage msg)
Utility method to correctly retrieve theSubscriptionobject that is related to the conversation messagemsgbelongs to.- Parameters:
msg- The message whoseconversation-idindicates the conversation- Returns:
- the
Subscriptionobject related to the conversation the given message belongs to
-
getSubscription
public SubscriptionResponder.Subscription getSubscription(String convId)
Utility method to correctly retrieve theSubscriptionobject that is related a given conversation.- Parameters:
convId- The id of the conversation- Returns:
- the
Subscriptionobject 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
Vectorincluding allSubscription-s made by the given agent
-
getSubscriptions
public Vector getSubscriptions()
Utility method that retrieves all Subscription-s managed by thisSubscriptionResponder- Returns:
- A
Vectorincluding allSubscription-s managed by thisSubscriptionResponder
-
-