Package jade.proto
Class TwoPhInitiator
-
- All Implemented Interfaces:
Serializable,Serializable
public class TwoPhInitiator 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 static StringPH0_STATEstatic StringPH1_STATEstatic StringPH2_STATE-
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 TwoPhInitiator(Agent a, ACLMessage cfp)Constructs aTwoPhInitiatorbehaviour.TwoPhInitiator(Agent a, ACLMessage cfp, DataStore ds)Constructs aTwoPhInitiatorbehaviour.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetCurrentPhase()BehaviourgetPhase(String name)protected voidhandleAllPh0Responses(Vector responses, Vector proposes, Vector pendings, Vector nextPhMsgs)This method is called when all the responses of phase 0 have been collected or when the timeout is expired.protected voidhandleAllPh1Responses(Vector responses, Vector confirms, Vector disconfirms, Vector informs, Vector pendings, Vector nextPhMsgs)This method is called in phase 1 when all the responses have been collected or when the timeout is expired.protected voidhandleAllPh2Responses(Vector responses)This method is called in phase 2 when all the responses have been collected.protected voidhandleConfirm(ACLMessage confirm)This method is called every time aconfirmmessage is received, which is not out-of-sequence according to the protocol rules.protected voidhandleDisconfirm(ACLMessage disconfirm)This method is called every time adisconfirmmessage is received, which is not out-of-sequence according to the protocol rules.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 voidhandleNotUnderstood(ACLMessage notUnderstood)protected voidhandleOldResponse(ACLMessage old)This method is called every time afailure, adisconfirmor aninformmessage is received in phase 2, 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 in phase n (usegetCurrentPhasemethod to know the phase), which is out-of-sequence according to the protocol rules.protected voidhandlePh1Inform(ACLMessage inform)This method is called every time aninformmessage in phase 1 is received, which is not out-of-sequence according to the protocol rules.protected voidhandlePh2Inform(ACLMessage inform)This method is called every time aninformmessage in phase 2 is received, which is not out-of-sequence according to the protocol rules.protected voidhandlePropose(ACLMessage propose)This method is called every time aproposemessage is received, which is not out-of-sequence according to the protocol rules.protected VectorprepareCfps(ACLMessage cfp)This method must return the vector of ACLMessage objects to be sent.-
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, reset, 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
-
PH0_STATE
public static final String PH0_STATE
- See Also:
- Constant Field Values
-
PH1_STATE
public static final String PH1_STATE
- See Also:
- Constant Field Values
-
PH2_STATE
public static final String PH2_STATE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TwoPhInitiator
public TwoPhInitiator(Agent a, ACLMessage cfp)
Constructs aTwoPhInitiatorbehaviour.- Parameters:
a- The agent performing the protocol.cfp- The message that must be used to initiate the protocol. Notice that the default implementation of theprepareCfpsmethod returns an array composed of that message only.
-
TwoPhInitiator
public TwoPhInitiator(Agent a, ACLMessage cfp, DataStore ds)
Constructs aTwoPhInitiatorbehaviour.- Parameters:
a- The agent performing the protocol.cfp- The message that must be used to initiate the protocol. Notice that the default implementation of theprepareCfpsmethod returns an array composed of that message only.ds-DataStorethat will be used by thisTwoPhInitiator.
-
-
Method Detail
-
prepareCfps
protected Vector prepareCfps(ACLMessage cfp)
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 (a CFP) passed in the constructor. Programmers might prefer to override this method in order to return a vector of CFP objects for 1:N conversations.- Parameters:
cfp- the ACLMessage object passed in the constructor- Returns:
- a vector of ACLMessage objects. The values of the slot
reply-withandconversation-idare ignored and regenerated automatically by this class. Instead user can specifyreply-byslot representing phase0 timeout.
-
handlePropose
protected void handlePropose(ACLMessage propose)
This method is called every time aproposemessage 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:
propose- the received propose 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 propose message
-
handleAllPh0Responses
protected void handleAllPh0Responses(Vector responses, Vector proposes, Vector pendings, Vector nextPhMsgs)
This method is called when all the responses of phase 0 have been collected or when the timeout is expired. The used timeout is the minimum value of the slotreply-Byof all the CFP messages sent.By response message we intend here all thepropose, failure, not-understoodreceived messages, which are not out-of-sequence according to the protocol rules. This default implementation does nothing; programmers might wish to override this method to modify the Vector of initiation messages (nextPhMsgs) for next phase. More in details this Vector already includes messages with the performative set according to the default protocol rules i.e. QUERY_IF (if all responders replied with PROPOSE) or REJECT_PROPOSAL (if at least one responder failed or didn't reply). In particular, by setting thereply-byslot, users can specify a timeout for next phase.- Parameters:
responses- The Vector of all messages received as response in phase 0proposes- The Vector of PROPOSE messages received as response in phase 0pendings- The Vector of CFP messages for which a response has not been received yet.nextPhMsgs- The Vector of initiation messages for next phase already filled withQUERY_IFmessages (if all responders replied withPROPOSE) orREJECT_PROPOSAL(if at least one responder failed or didn't reply).
-
handleConfirm
protected void handleConfirm(ACLMessage confirm)
This method is called every time aconfirmmessage 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:
confirm- the received propose message
-
handleDisconfirm
protected void handleDisconfirm(ACLMessage disconfirm)
This method is called every time adisconfirmmessage 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:
disconfirm- the received propose message
-
handlePh1Inform
protected void handlePh1Inform(ACLMessage inform)
This method is called every time aninformmessage in phase 1 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
-
handleAllPh1Responses
protected void handleAllPh1Responses(Vector responses, Vector confirms, Vector disconfirms, Vector informs, Vector pendings, Vector nextPhMsgs)
This method is called in phase 1 when all the responses have been collected or when the timeout is expired. The used timeout is the minimum value of the slotreply-Byof all the sent messages. By response message we intend here all thedisconfirm, confirm, informreceived 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- The Vector of all messages received as response in phase 1confirms- all confirms receiveddisconfirms- all disconfirms receivedpendings- all queryIfs still pendingnextPhMsgs- prepared responses for next phase:accept-proposalorreject-proposal
-
handlePh2Inform
protected void handlePh2Inform(ACLMessage inform)
This method is called every time aninformmessage in phase 2 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 in phase 2, 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
-
handleAllPh2Responses
protected void handleAllPh2Responses(Vector responses)
This method is called in phase 2 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 in phase 2
-
handleOutOfSequence
protected void handleOutOfSequence(ACLMessage msg)
This method is called every time a message is received in phase n (usegetCurrentPhasemethod to know the phase), 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
-
handleNotUnderstood
protected void handleNotUnderstood(ACLMessage notUnderstood)
-
getCurrentPhase
public String getCurrentPhase()
-
-