jade.proto
Class TwoPhInitiator

java.lang.Object
  |
  +--jade.core.behaviours.Behaviour
        |
        +--jade.core.behaviours.CompositeBehaviour
              |
              +--jade.core.behaviours.SerialBehaviour
                    |
                    +--jade.core.behaviours.FSMBehaviour
                          |
                          +--jade.proto.TwoPhInitiator
All Implemented Interfaces:
Serializable, java.io.Serializable

public class TwoPhInitiator
extends FSMBehaviour

Class description

Author:
Elena Quarantotto - TILAB, Giovanni Caire - TILAB
See Also:
Serialized Form

Field Summary
static java.lang.String PH0_STATE
           
static java.lang.String PH1_STATE
           
static java.lang.String PH2_STATE
           
 
Fields inherited from class jade.core.behaviours.FSMBehaviour
currentName, lastStates
 
Fields inherited from class jade.core.behaviours.Behaviour
myAgent
 
Constructor Summary
TwoPhInitiator(Agent a, ACLMessage cfp)
          Constructs a TwoPhInitiator behaviour.
TwoPhInitiator(Agent a, ACLMessage cfp, DataStore ds)
          Constructs a TwoPhInitiator behaviour.
 
Method Summary
 java.lang.String getCurrentPhase()
           
 Behaviour getPhase(java.lang.String name)
           
protected  void handleAllPh0Responses(java.util.Vector responses, java.util.Vector proposes, java.util.Vector pendings, java.util.Vector nextPhMsgs)
          This method is called when all the responses of phase 0 have been collected or when the timeout is expired.
protected  void handleAllPh1Responses(java.util.Vector responses, java.util.Vector confirms, java.util.Vector disconfirms, java.util.Vector informs, java.util.Vector pendings, java.util.Vector nextPhMsgs)
          This method is called in phase 1 when all the responses have been collected or when the timeout is expired.
protected  void handleAllPh2Responses(java.util.Vector responses)
          This method is called in phase 2 when all the responses have been collected.
protected  void handleConfirm(ACLMessage confirm)
          This method is called every time a confirm message is received, which is not out-of-sequence according to the protocol rules.
protected  void handleDisconfirm(ACLMessage disconfirm)
          This method is called every time a disconfirm message is received, which is not out-of-sequence according to the protocol rules.
protected  void handleFailure(ACLMessage failure)
          This method is called every time a failure message is received, which is not out-of-sequence according to the protocol rules.
protected  void handleNotUnderstood(ACLMessage notUnderstood)
           
protected  void handleOldResponse(ACLMessage old)
          This method is called every time a failure, a disconfirm or an inform message is received in phase 2, which is not out-of-sequence according to the protocol rules.
protected  void handleOutOfSequence(ACLMessage msg)
          This method is called every time a message is received in phase n (use getCurrentPhase method to know the phase), which is out-of-sequence according to the protocol rules.
protected  void handlePh1Inform(ACLMessage inform)
          This method is called every time an inform message in phase 1 is received, which is not out-of-sequence according to the protocol rules.
protected  void handlePh2Inform(ACLMessage inform)
          This method is called every time an inform message in phase 2 is received, which is not out-of-sequence according to the protocol rules.
protected  void handlePropose(ACLMessage propose)
          This method is called every time a propose message is received, which is not out-of-sequence according to the protocol rules.
protected  java.util.Vector prepareCfps(ACLMessage cfp)
          This method must return the vector of ACLMessage objects to be sent.
 
Methods inherited from class jade.core.behaviours.FSMBehaviour
checkTermination, deregisterState, forceTransitionTo, getChildren, getCurrent, getLastExitValue, getName, getPrevious, getState, handleInconsistentFSM, handleStateEntered, onEnd, registerDefaultTransition, registerDefaultTransition, registerFirstState, registerLastState, registerState, registerTransition, registerTransition, reset, resetStates, scheduleFirst, scheduleNext
 
Methods inherited from class jade.core.behaviours.CompositeBehaviour
action, block, done, resetChildren, restart, setAgent
 
Methods inherited from class jade.core.behaviours.Behaviour
block, getBehaviourName, getDataStore, getParent, isRunnable, onStart, root, setBehaviourName, setDataStore
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PH0_STATE

public static final java.lang.String PH0_STATE
See Also:
Constant Field Values

PH1_STATE

public static final java.lang.String PH1_STATE
See Also:
Constant Field Values

PH2_STATE

public static final java.lang.String PH2_STATE
See Also:
Constant Field Values
Constructor Detail

TwoPhInitiator

public TwoPhInitiator(Agent a,
                      ACLMessage cfp)
Constructs a TwoPhInitiator behaviour.

Parameters:
a - The agent performing the protocol.
cfp - The message that must be used to initiate the protocol. Notice that the default implementation of the prepareCfps method returns an array composed of that message only.

TwoPhInitiator

public TwoPhInitiator(Agent a,
                      ACLMessage cfp,
                      DataStore ds)
Constructs a TwoPhInitiator behaviour.

Parameters:
a - The agent performing the protocol.
cfp - The message that must be used to initiate the protocol. Notice that the default implementation of the prepareCfps method returns an array composed of that message only.
ds - DataStore that will be used by this TwoPhInitiator.
Method Detail

prepareCfps

protected java.util.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-with and conversation-id are ignored and regenerated automatically by this class. Instead user can specify reply-by slot representing phase0 timeout.

handlePropose

protected void handlePropose(ACLMessage propose)
This method is called every time a propose message 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 a failure message 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(java.util.Vector responses,
                                     java.util.Vector proposes,
                                     java.util.Vector pendings,
                                     java.util.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 slot reply-By of all the CFP messages sent.By response message we intend here all the propose, failure, not-understood received 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 the reply-by slot, users can specify a timeout for next phase.

Parameters:
responses - The Vector of all messages received as response in phase 0
proposes - The Vector of PROPOSE messages received as response in phase 0
pendings - 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 with QUERY_IF messages (if all responders replied with PROPOSE) or REJECT_PROPOSAL (if at least one responder failed or didn't reply).

handleConfirm

protected void handleConfirm(ACLMessage confirm)
This method is called every time a confirm message 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 a disconfirm message 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 an inform message 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(java.util.Vector responses,
                                     java.util.Vector confirms,
                                     java.util.Vector disconfirms,
                                     java.util.Vector informs,
                                     java.util.Vector pendings,
                                     java.util.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 slot reply-By of all the sent messages. By response message we intend here all the disconfirm, confirm, inform 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 - The Vector of all messages received as response in phase 1
confirms - all confirms received
disconfirms - all disconfirms received
pendings - all queryIfs still pending
nextPhMsgs - prepared responses for next phase: accept-proposal or reject-proposal

handlePh2Inform

protected void handlePh2Inform(ACLMessage inform)
This method is called every time an inform message 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 a failure, a disconfirm or an inform message 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(java.util.Vector responses)
This method is called in phase 2 when all the responses have been collected. By response message we intend here all the inform (phase 2), failure (phase 0), disconfirm (phase 1) and inform (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 (use getCurrentPhase method 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 java.lang.String getCurrentPhase()

getPhase

public Behaviour getPhase(java.lang.String name)


JADE