public class TwoPhResponder extends FSMBehaviour
Modifier and Type | Field and Description |
---|---|
java.lang.String |
RECEIVED_KEY
Key to retrieve from the DataStore of the behaviour the last received
ACLMessage
|
java.lang.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.
|
currentName, lastStates
Constructor and Description |
---|
TwoPhResponder(Agent a,
MessageTemplate mt)
Constructor of the behaviour that creates a new empty DataStore
|
TwoPhResponder(Agent a,
MessageTemplate mt,
DataStore store)
Constructor of the behaviour.
|
Modifier and Type | Method and Description |
---|---|
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.
|
protected ACLMessage |
handleAcceptProposal(ACLMessage accept)
This method is called after the
ACCEPT-PROPOSAL has been received. |
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.
|
protected void |
handleOutOfSequence(ACLMessage msg)
This method is called whenever a message is received that does
not comply to the protocol rules.
|
protected ACLMessage |
handleQueryIf(ACLMessage queryIf)
This method is called after the
QUERY-IF has been received. |
protected ACLMessage |
handleRejectProposal(ACLMessage reject)
This method is called after the
REJECT-PROPOSAL has been received. |
void |
registerHandleAcceptProposal(Behaviour b)
This method allows to register a user defined
Behaviour
in the HANDLE_ACCEPTANCE state. |
void |
registerHandleCfp(Behaviour b)
This method allows to register a user defined
Behaviour
in the PREPARE_PROPOSE state. |
void |
registerHandleOutOfSequence(Behaviour b)
This method allows to register a user defined
Behaviour
in the HANDLE_OUT_OF_SEQ state. |
void |
registerHandleQueryIf(Behaviour b)
This method allows to register a user defined
Behaviour
in the HANDLE_QUERY_IF state. |
void |
registerHandleRejectProposal(Behaviour b)
This method allows to register a user defined
Behaviour
in the HANDLE_REJECT state. |
void |
reset()
Reset this behaviour.
|
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
action, done, resetChildren, setAgent
block, block, getAgent, getBehaviourName, getDataStore, getParent, isRunnable, onStart, restart, root, setBehaviourName, setDataStore
public final java.lang.String RECEIVED_KEY
public final java.lang.String REPLY_KEY
public TwoPhResponder(Agent a, MessageTemplate mt)
public TwoPhResponder(Agent a, MessageTemplate mt, DataStore store)
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 method createMessageTemplate
might be usefull.store
- the DataStore for this protocol behaviourprotected ACLMessage handleCfp(ACLMessage cfp)
cfp
- the received messagePROPOSE, FAILURE
. Remind to
use the method createReply
of the class ACLMessage in order
to create a valid reply messageACLMessage.createReply()
protected ACLMessage handleQueryIf(ACLMessage queryIf)
QUERY-IF
has 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.queryIf
- the received messageCONFIRM, INFORM, DISCONFIRM
. Remind to
use the method createReply of the class ACLMessage in order
to create a valid reply messageACLMessage.createReply()
protected ACLMessage handleRejectProposal(ACLMessage reject)
REJECT-PROPOSAL
has been received.
This default implementation do nothing.
Programmers should override the method in case they need to react to this event.reject
- the received messageINFORM
. Remind to
use the method createReply of the class ACLMessage in order
to create a valid reply messageACLMessage.createReply()
protected ACLMessage handleAcceptProposal(ACLMessage accept)
ACCEPT-PROPOSAL
has 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.accept
- the received messageINFORM
. Remind to use the method createReply of
the class ACLMessage in order to create a valid reply messageACLMessage.createReply()
public void registerHandleCfp(Behaviour b)
Behaviour
in the PREPARE_PROPOSE 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 response
to be sent into the datastore at the PROPOSE_KEY
key.b
- the Behaviour that will handle this statepublic void registerHandleQueryIf(Behaviour b)
Behaviour
in the HANDLE_QUERY_IF 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 response
to be sent into the datastore at the REPLY_KEY
key.b
- the Behaviour that will handle this statepublic void registerHandleRejectProposal(Behaviour b)
Behaviour
in the HANDLE_REJECT 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 response
to be sent into the datastore at the REPLY_KEY
key.b
- the Behaviour that will handle this statepublic void registerHandleAcceptProposal(Behaviour b)
Behaviour
in the HANDLE_ACCEPTANCE 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 response
to be sent into the datastore at the REPLY_KEY
key.b
- the Behaviour that will handle this statepublic static MessageTemplate createMessageTemplate()
FIPANames.InteractionProtocol
public void reset()
protected void handleOutOfSequence(ACLMessage msg)
msg
- the received out-of-sequence message.public void registerHandleOutOfSequence(Behaviour b)
Behaviour
in the HANDLE_OUT_OF_SEQ state.
This behaviour would override the homonymous method.
This method also sets 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 RECEIVED_KEY
key.b
- the Behaviour that will handle this state