Package jade.proto
Class TwoPhResponder
-
- All Implemented Interfaces:
Serializable,Serializable
public class TwoPhResponder extends FSMBehaviour
Class description- Author:
- Elena Quarantotto - TILAB, Giovanni Caire - TILAB
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jade.core.behaviours.Behaviour
Behaviour.RunnableChangedEvent
-
-
Field Summary
Fields Modifier and Type Field Description protected static StringCHECK_IN_SEQprotected static StringHANDLE_OUT_OF_SEQUENCEprotected static StringRECEIVE_INITIATIONprotected static StringRECEIVE_NEXTStringRECEIVED_KEYKey to retrieve from the DataStore of the behaviour the last received ACLMessageStringREPLY_KEYKey to set into the DataStore of the behaviour the new ACLMessage to be sent back to the initiator as a reply.protected static StringSEND_REPLY-
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
-
-
Constructor Summary
Constructors Constructor Description TwoPhResponder(Agent a, MessageTemplate mt)Constructor of the behaviour that creates a new empty DataStoreTwoPhResponder(Agent a, MessageTemplate mt, DataStore store)Constructor of the behaviour.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleancheckInSequence(ACLMessage received)Check whether a received message complies with the protocol rules.static MessageTemplatecreateMessageTemplate()This static method can be used to set the proper message Template (based on the interaction protocol and the performative) to be passed to the constructor of this behaviour.protected ACLMessagehandleAcceptProposal(ACLMessage accept)This method is called after theACCEPT-PROPOSALhas been received.protected ACLMessagehandleCfp(ACLMessage cfp)This method is called when the initiator's message is received that matches the message template passed in the constructor.protected voidhandleOutOfSequence(ACLMessage msg)This method is called whenever a message is received that does not comply to the protocol rules.protected ACLMessagehandleQueryIf(ACLMessage queryIf)This method is called after theQUERY-IFhas been received.protected ACLMessagehandleRejectProposal(ACLMessage reject)This method is called after theREJECT-PROPOSALhas been received.protected voidregisterDSState(Behaviour b, String name)Utility method to register a behaviour in a state of the protocol and set the DataStore appropriatelyvoidregisterHandleAcceptProposal(Behaviour b)This method allows to register a user definedBehaviourin the HANDLE_ACCEPTANCE state.voidregisterHandleCfp(Behaviour b)This method allows to register a user definedBehaviourin the PREPARE_PROPOSE state.voidregisterHandleOutOfSequence(Behaviour b)This method allows to register a user definedBehaviourin the HANDLE_OUT_OF_SEQ state.voidregisterHandleQueryIf(Behaviour b)This method allows to register a user definedBehaviourin the HANDLE_QUERY_IF state.voidregisterHandleRejectProposal(Behaviour b)This method allows to register a user definedBehaviourin the HANDLE_REJECT state.protected voidreplySent(int exitValue)This method can be redefined by protocol specific implementations to update the status of the protocol after a reply has been sent.voidreset()Reset this behaviour.-
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
-
RECEIVED_KEY
public final String RECEIVED_KEY
Key to retrieve from the DataStore of the behaviour the last received ACLMessage
-
REPLY_KEY
public final String REPLY_KEY
Key to set into the DataStore of the behaviour the new ACLMessage to be sent back to the initiator as a reply.
-
RECEIVE_INITIATION
protected static final String RECEIVE_INITIATION
- See Also:
- Constant Field Values
-
RECEIVE_NEXT
protected static final String RECEIVE_NEXT
- See Also:
- Constant Field Values
-
HANDLE_OUT_OF_SEQUENCE
protected static final String HANDLE_OUT_OF_SEQUENCE
- See Also:
- Constant Field Values
-
CHECK_IN_SEQ
protected static final String CHECK_IN_SEQ
- See Also:
- Constant Field Values
-
SEND_REPLY
protected static final String SEND_REPLY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TwoPhResponder
public TwoPhResponder(Agent a, MessageTemplate mt)
Constructor of the behaviour that creates a new empty DataStore
-
TwoPhResponder
public TwoPhResponder(Agent a, MessageTemplate mt, DataStore store)
Constructor of the behaviour.- Parameters:
a- is the reference to the Agent objectmt- is the MessageTemplate that must be used to match the initiator message. Take care that if mt is null every message is consumed by this protocol. The best practice is to have a MessageTemplate that matches the protocol slot; the static methodcreateMessageTemplatemight be usefull.store- the DataStore for this protocol behaviour
-
-
Method Detail
-
handleCfp
protected ACLMessage handleCfp(ACLMessage cfp)
This method is called when the initiator's message is received that matches the message template passed in the constructor. This default implementation return null which has the effect of sending no reponse. Programmers should override the method in case they need to react to this event.- Parameters:
cfp- the received message- Returns:
- the ACLMessage to be sent as a response (i.e. one of
PROPOSE, FAILURE. Remind to use the methodcreateReplyof the class ACLMessage in order to create a valid reply message - See Also:
ACLMessage.createReply()
-
handleQueryIf
protected ACLMessage handleQueryIf(ACLMessage queryIf)
This method is called after theQUERY-IFhas been received. This default implementation return null which has the effect of sending no result notification. Programmers should override the method in case they need to react to this event.- Parameters:
queryIf- the received message- Returns:
- the ACLMessage to be sent as a result notification (i.e. one of
CONFIRM, INFORM, DISCONFIRM. Remind to use the method createReply of the class ACLMessage in order to create a valid reply message - See Also:
ACLMessage.createReply()
-
handleRejectProposal
protected ACLMessage handleRejectProposal(ACLMessage reject)
This method is called after theREJECT-PROPOSALhas been received. This default implementation do nothing. Programmers should override the method in case they need to react to this event.- Parameters:
reject- the received message- Returns:
- the ACLMessage to be sent as a result notification (i.e. an
INFORM. Remind to use the method createReply of the class ACLMessage in order to create a valid reply message - See Also:
ACLMessage.createReply()
-
handleAcceptProposal
protected ACLMessage handleAcceptProposal(ACLMessage accept)
This method is called after theACCEPT-PROPOSALhas been received. This default implementation return null which has the effect of sending no result notification. Programmers should override the method in case they need to react to this event.- Parameters:
accept- the received message- Returns:
- the ACLMessage to be sent as a result notification (i.e. an
INFORM. Remind to use the method createReply of the class ACLMessage in order to create a valid reply message - See Also:
ACLMessage.createReply()
-
registerHandleCfp
public void registerHandleCfp(Behaviour b)
This method allows to register a user definedBehaviourin the PREPARE_PROPOSE state. This behaviour would override the homonymous method. This method also set the data store of the registeredBehaviourto the DataStore of this current behaviour. It is responsibility of the registered behaviour to put the response to be sent into the datastore at thePROPOSE_KEYkey.- Parameters:
b- the Behaviour that will handle this state
-
registerHandleQueryIf
public void registerHandleQueryIf(Behaviour b)
This method allows to register a user definedBehaviourin the HANDLE_QUERY_IF state. This behaviour would override the homonymous method. This method also set the data store of the registeredBehaviourto the DataStore of this current behaviour. It is responsibility of the registered behaviour to put the response to be sent into the datastore at theREPLY_KEYkey.- Parameters:
b- the Behaviour that will handle this state
-
registerHandleRejectProposal
public void registerHandleRejectProposal(Behaviour b)
This method allows to register a user definedBehaviourin the HANDLE_REJECT state. This behaviour would override the homonymous method. This method also set the data store of the registeredBehaviourto the DataStore of this current behaviour. It is responsibility of the registered behaviour to put the response to be sent into the datastore at theREPLY_KEYkey.- Parameters:
b- the Behaviour that will handle this state
-
registerHandleAcceptProposal
public void registerHandleAcceptProposal(Behaviour b)
This method allows to register a user definedBehaviourin the HANDLE_ACCEPTANCE state. This behaviour would override the homonymous method. This method also set the data store of the registeredBehaviourto the DataStore of this current behaviour. It is responsibility of the registered behaviour to put the response to be sent into the datastore at theREPLY_KEYkey.- Parameters:
b- the Behaviour that will handle this state
-
createMessageTemplate
public static MessageTemplate createMessageTemplate()
This static method can be used to set the proper message Template (based on the interaction protocol and the performative) to be passed to the constructor of this behaviour.- See Also:
FIPANames.InteractionProtocol
-
reset
public void reset()
Reset this behaviour.
-
checkInSequence
protected boolean checkInSequence(ACLMessage received)
Check whether a received message complies with the protocol rules.
-
replySent
protected void replySent(int exitValue)
This method can be redefined by protocol specific implementations to update the status of the protocol after a reply has been sent. This default implementation does nothing.
-
handleOutOfSequence
protected void handleOutOfSequence(ACLMessage msg)
This method is called whenever a message is received that does not comply to the protocol rules. This default implementation does nothing. Programmers may override it in case they need to react to this event.- Parameters:
msg- the received out-of-sequence message.
-
registerHandleOutOfSequence
public void registerHandleOutOfSequence(Behaviour b)
This method allows to register a user definedBehaviourin the HANDLE_OUT_OF_SEQ state. This behaviour would override the homonymous method. This method also sets the data store of the registeredBehaviourto the DataStore of this current behaviour. The registered behaviour can retrieve theout of sequenceACLMessage object received from the datastore at theRECEIVED_KEYkey.- Parameters:
b- the Behaviour that will handle this state
-
-