Package jade.proto
Class TwoPh2Initiator
-
- All Implemented Interfaces:
Serializable,Serializable
public class TwoPh2Initiator 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 StringACCEPTANCE_KEYkey to retrieve from the DataStore of the behaviour the ACLMessage object passed in the constructor of the class.StringALL_ACCEPTANCES_KEYkey to retrieve from the DataStore of the behaviour the vector of ACCEPT_PROPOSAL or REJECT_PROPOSAL messages that have to be sent.StringALL_INFORMS_KEYkey to retrieve from the DataStore of the behaviour the vector of INFORM messages that have been received as response.protected StringALL_INITIATIONS_KStringALL_PENDINGS_KEYkey to retrieve from the DataStore of the behaviour the vector of ACCEPT_PROPOSAL or REJECT_PROPOSAL messages for which a response has not been received yet.StringALL_RESPONSES_KEYkey to retrieve from the DataStore of the behaviour the Vector of all messages that have been received as response.protected static StringCHECK_IN_SEQprotected static StringCHECK_SESSIONSprotected static StringDUMMY_FINALprotected static StringHANDLE_FAILUREprotected static StringHANDLE_NOT_UNDERSTOODprotected static StringHANDLE_OUT_OF_SEQprotected StringINITIATION_Kprotected static StringPREPARE_INITIATIONSprotected static StringRECEIVE_REPLYprotected StringREPLY_KStringREPLY_KEYkey to retrieve from the DataStore of the behaviour the last ACLMessage object that has been received (null if the timeout expired).protected MsgReceiverreplyReceiverprotected MessageTemplatereplyTemplateprotected static StringSEND_INITIATIONSprotected Mapsessions-
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 TwoPh2Initiator(Agent a, ACLMessage acceptance)Constructs aTwoPh2Initiatorbehaviour.TwoPh2Initiator(Agent a, ACLMessage acceptance, DataStore store)Constructs aTwoPh2Initiatorbehaviour.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidadjustReplyTemplate(ACLMessage msg)protected booleancheckInSequence(ACLMessage reply)Check whether a reply is in-sequence and than update the appropriate Session and removes corresponding accept/reject-proposal from vector of pendings.protected intcheckSessions(ACLMessage reply)Check if there are still active sessions or if timeout is expired.protected StringcreateConvId(Vector msgs)Create a new conversation identifier to begin a new interaction.protected jade.proto.Initiator.ProtocolSessiongetSession(ACLMessage msg, int sessionIndex)Return a ProtocolSession object to manage replies to a given initiation messageprotected String[]getToBeReset()Return the states that must be reset before they are visited again.protected voidhandleAllResponses(Vector responses)This method is called when all the responses have been collected.protected voidhandleFailure(ACLMessage failure)This method is called every time afailuremessage is received, which is not out-of-sequence according to the protocol rules.protected voidhandleInform(ACLMessage inform)This method is called every time ainformmessage is received, which is not out-of-sequence according to the protocol rules.protected voidhandleNotUnderstood(ACLMessage notUnderstood)This method is called every time anot-understoodmessage is received, which is not out-of-sequence according to the protocol rules.protected voidhandleOldResponse(ACLMessage old)This method is called every time afailure, adisconfirmor aninformmessage is received, which is not out-of-sequence according to the protocol rules.protected voidhandleOutOfSequence(ACLMessage msg)This method is called every time a message is received, which is out-of-sequence according to the protocol rules.protected voidinitializeDataStore(ACLMessage msg)Initialize the data store.voidonStart()Override the onStart() method to initialize the vectors that will keep all the replies in the data store.protected VectorprepareAcceptances(ACLMessage acceptance)This method must return the vector of ACLMessage objects to be sent.protected VectorprepareInitiations(ACLMessage initiation)Returns vector of accept/reject-proposal stored in the data store at keyinputKeyfrom previouse phase.voidregisterHandleAllResponses(Behaviour b)This method allows to register a user definedBehaviourin the HANDLE_ALL_RESPONSES state.voidregisterHandleFailure(Behaviour b)This method allows to register a user definedBehaviourin the HANDLE_FAILURE state.voidregisterHandleInform(Behaviour b)This method allows to register a user definedBehaviourin the HANDLE_INFORM state.voidregisterHandleNotUnderstood(Behaviour b)This method allows to register a user definedBehaviourin the HANDLE_NOT_UNDERSTOOD state.voidregisterHandleOldResponse(Behaviour b)This method allows to register a user definedBehaviourin the HANDLE_OLD_RESPONSE state.voidregisterHandleOutOfSequence(Behaviour b)This method allows to register a user definedBehaviourin the HANDLE_OUT_OF_SEQ state.protected voidregisterPrepareInitiations(Behaviour b)Attach a behaviour to thePrepare-initiationsprotocol state.voidregisterPrepareProposals(Behaviour b)This method allows to register a user-definedBehaviourin the PREPARE_ACCEPTANCES state.protected voidreinit()Re-initialize the internal state without performing a complete reset.voidreset()reset this behaviour by putting a null ACLMessage as message to be sentvoidreset(ACLMessage msg)reset this behaviourprotected voidsendInitiations(Vector initiations)This method sets for all prepared accept/reject-proposalconversation-idslot (with value passed in the constructor),protocolslot andreply-withslot with a unique value constructed by concatenating receiver's agent name and phase number (i.e.voidsetDataStore(DataStore ds)Override the setDataStore() method to propagate this setting to all children.-
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, restart, root, setBehaviourName, setExecutionState
-
-
-
-
Field Detail
-
ACCEPTANCE_KEY
public final String ACCEPTANCE_KEY
key to retrieve from the DataStore of the behaviour the ACLMessage object passed in the constructor of the class.
-
ALL_ACCEPTANCES_KEY
public final String ALL_ACCEPTANCES_KEY
key to retrieve from the DataStore of the behaviour the vector of ACCEPT_PROPOSAL or REJECT_PROPOSAL messages that have to be sent.
-
REPLY_KEY
public final String REPLY_KEY
key to retrieve from the DataStore of the behaviour the last ACLMessage object that has been received (null if the timeout expired).
-
ALL_RESPONSES_KEY
public final String ALL_RESPONSES_KEY
key to retrieve from the DataStore of the behaviour the Vector of all messages that have been received as response.
-
ALL_INFORMS_KEY
public final String ALL_INFORMS_KEY
key to retrieve from the DataStore of the behaviour the vector of INFORM messages that have been received as response.
-
ALL_PENDINGS_KEY
public final String ALL_PENDINGS_KEY
key to retrieve from the DataStore of the behaviour the vector of ACCEPT_PROPOSAL or REJECT_PROPOSAL messages for which a response has not been received yet.
-
INITIATION_K
protected final String INITIATION_K
-
ALL_INITIATIONS_K
protected final String ALL_INITIATIONS_K
-
REPLY_K
protected final String REPLY_K
-
PREPARE_INITIATIONS
protected static final String PREPARE_INITIATIONS
- See Also:
- Constant Field Values
-
SEND_INITIATIONS
protected static final String SEND_INITIATIONS
- See Also:
- Constant Field Values
-
RECEIVE_REPLY
protected static final String RECEIVE_REPLY
- See Also:
- Constant Field Values
-
CHECK_IN_SEQ
protected static final String CHECK_IN_SEQ
- See Also:
- Constant Field Values
-
HANDLE_NOT_UNDERSTOOD
protected static final String HANDLE_NOT_UNDERSTOOD
- See Also:
- Constant Field Values
-
HANDLE_FAILURE
protected static final String HANDLE_FAILURE
- See Also:
- Constant Field Values
-
HANDLE_OUT_OF_SEQ
protected static final String HANDLE_OUT_OF_SEQ
- See Also:
- Constant Field Values
-
CHECK_SESSIONS
protected static final String CHECK_SESSIONS
- See Also:
- Constant Field Values
-
DUMMY_FINAL
protected static final String DUMMY_FINAL
- See Also:
- Constant Field Values
-
sessions
protected Map sessions
-
replyReceiver
protected MsgReceiver replyReceiver
-
replyTemplate
protected MessageTemplate replyTemplate
-
-
Constructor Detail
-
TwoPh2Initiator
public TwoPh2Initiator(Agent a, ACLMessage acceptance)
Constructs aTwoPh2Initiatorbehaviour.- Parameters:
a- The agent performing the protocol.conversationId-Conversation-idslot used for all the duration of phase2's protocol.inputKey- Data store key where behaviour can get accept-proposal or reject-proposal messages prepared in the previous phase.
-
TwoPh2Initiator
public TwoPh2Initiator(Agent a, ACLMessage acceptance, DataStore store)
Constructs aTwoPh2Initiatorbehaviour.- Parameters:
a- The agent performing the protocol.conversationId-Conversation-idslot used for all the duration of phase2's protocol.inputKey- Data store key where behaviour can get accept-proposal or reject-proposal messages prepared in the previous phase.store-DataStorethat will be used by thisTwoPh2Initiator.
-
-
Method Detail
-
prepareAcceptances
protected Vector prepareAcceptances(ACLMessage acceptance)
This method must return the vector of ACLMessage objects to be sent. It is called in the first state of this protocol. This default implementation just returns the ACLMessage object passed in the constructor. Programmers might prefer to override this method in order to return a vector of ACCEPT_PROPOSAL or REJECT_PROPOSAL objects for 1:N conversations.- Parameters:
acceptance- the ACLMessage object passed in the constructor- Returns:
- a Vector of ACLMessage objects. The value of the
reply-withslot is ignored and regenerated automatically by this class. Instead user can specify thereply-byslot representing phase2 timeout.
-
handleInform
protected void handleInform(ACLMessage inform)
This method is called every time ainformmessage 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:
inform- the received propose message
-
handleOldResponse
protected void handleOldResponse(ACLMessage old)
This method is called every time afailure, adisconfirmor aninformmessage 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:
old- the received propose message
-
handleAllResponses
protected void handleAllResponses(Vector responses)
This method is called when all the responses have been collected. By response message we intend here all theinform(phase 2),failure(phase 0),disconfirm(phase 1) andinform(phase 1) received messages, which are 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 by analysing all the messages in just one call.- Parameters:
responses- all responses received
-
registerPrepareProposals
public void registerPrepareProposals(Behaviour b)
This method allows to register a user-definedBehaviourin the PREPARE_ACCEPTANCES 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 theVectorof ACLMessage objects to be sent into the datastore at theALL_ACCEPTANCES_KEYkey.- Parameters:
b- the Behaviour that will handle this state
-
registerHandleInform
public void registerHandleInform(Behaviour b)
This method allows to register a user definedBehaviourin the HANDLE_INFORM state. This behaviour would override the homonymous method. This method also set the data store of the registeredBehaviourto the DataStore of this current behaviour. The registered behaviour can retrieve theinformACLMessage object received from the datastore at theREPLY_KEYkey.- Parameters:
b- the Behaviour that will handle this state
-
registerHandleOldResponse
public void registerHandleOldResponse(Behaviour b)
This method allows to register a user definedBehaviourin the HANDLE_OLD_RESPONSE state. This behaviour would override the homonymous method. This method also set the data store of the registeredBehaviourto the DataStore of this current behaviour. The registered behaviour can retrieve thefailure, disconfirm or informACLMessage object received from the datastore at theREPLY_KEYkey.- Parameters:
b- the Behaviour that will handle this state
-
registerHandleAllResponses
public void registerHandleAllResponses(Behaviour b)
This method allows to register a user definedBehaviourin the HANDLE_ALL_RESPONSES state. This behaviour would override the homonymous method. This method also set the data store of the registeredBehaviourto the DataStore of this current behaviour. The registered behaviour can retrieve the vector of ACLMessage received from the datastore atALL_RESPONSES_RECEIVED_KEY.- Parameters:
b- the Behaviour that will handle this state
-
getToBeReset
protected String[] getToBeReset()
Return the states that must be reset before they are visited again. Note that resetting a state before visiting it again is required only if - The onStart() method is redefined - The state has an "internal memory"
-
prepareInitiations
protected final Vector prepareInitiations(ACLMessage initiation)
Returns vector of accept/reject-proposal stored in the data store at keyinputKeyfrom previouse phase.- Parameters:
initiation- ignored- Returns:
- Vector of accept/reject-proposal
-
sendInitiations
protected final void sendInitiations(Vector initiations)
This method sets for all prepared accept/reject-proposalconversation-idslot (with value passed in the constructor),protocolslot andreply-withslot with a unique value constructed by concatenating receiver's agent name and phase number (i.e. 2). After that it sends all accept/reject-proposal.- Parameters:
initiations- vector prepared in PREPARE_ACCEPTANCES state
-
checkInSequence
protected final boolean checkInSequence(ACLMessage reply)
Check whether a reply is in-sequence and than update the appropriate Session and removes corresponding accept/reject-proposal from vector of pendings.- Parameters:
reply- message received- Returns:
- true if reply is compliant with flow of protocol, false otherwise
-
checkSessions
protected final int checkSessions(ACLMessage reply)
Check if there are still active sessions or if timeout is expired.- Parameters:
reply- last message received- Returns:
- ALL_RESPONSES_RECEIVED, -1 (still active sessions)
-
initializeDataStore
protected void initializeDataStore(ACLMessage msg)
Initialize the data store.- Parameters:
msg- Ignored
-
getSession
protected jade.proto.Initiator.ProtocolSession getSession(ACLMessage msg, int sessionIndex)
Return a ProtocolSession object to manage replies to a given initiation message
-
handleNotUnderstood
protected void handleNotUnderstood(ACLMessage notUnderstood)
This method is called every time anot-understoodmessage 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 afailuremessage 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 thePrepare-initiationsprotocol state.- Parameters:
b- The behaviour object to be executed in thePrepare-initiationsstate.
-
registerHandleNotUnderstood
public void registerHandleNotUnderstood(Behaviour b)
This method allows to register a user definedBehaviourin the HANDLE_NOT_UNDERSTOOD state. This behaviour would override the homonymous method. This method also set the data store of the registeredBehaviourto the DataStore of this current behaviour. The registered behaviour can retrieve thenot-understoodACLMessage object received from the datastore at theREPLY_KEYkey.- Parameters:
b- the Behaviour that will handle this state
-
registerHandleFailure
public void registerHandleFailure(Behaviour b)
This method allows to register a user definedBehaviourin the HANDLE_FAILURE state. This behaviour would override the homonymous method. This method also set the data store of the registeredBehaviourto the DataStore of this current behaviour. The registered behaviour can retrieve thefailureACLMessage object received from the datastore at theREPLY_KEYkey.- Parameters:
b- the Behaviour that will handle this state
-
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 set 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 theREPLY_KEYkey.- 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:
resetin classFSMBehaviour
-
reset
public void reset(ACLMessage msg)
reset this behaviour- Parameters:
msg- is the ACLMessage to be sent
-
reinit
protected void reinit()
Re-initialize the internal state without performing a complete reset.
-
onStart
public void onStart()
Override the onStart() method to initialize the vectors that will keep all the replies in the data store.
-
setDataStore
public void setDataStore(DataStore ds)
Override the setDataStore() method to propagate this setting to all children.- Overrides:
setDataStorein classBehaviour- Parameters:
ds- theDataStorethat thisBehaviourwill 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-idslot, its value is used, else a new conversation identifier is generated.
-
adjustReplyTemplate
protected void adjustReplyTemplate(ACLMessage msg)
-
-