jade.proto
Class TwoPh2Initiator

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

public class TwoPh2Initiator
extends jade.proto.Initiator

Class description

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

Field Summary
 java.lang.String ACCEPTANCE_KEY
          key to retrieve from the DataStore of the behaviour the ACLMessage object passed in the constructor of the class.
 java.lang.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.
 java.lang.String ALL_INFORMS_KEY
          key to retrieve from the DataStore of the behaviour the vector of INFORM messages that have been received as response.
 java.lang.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.
 java.lang.String ALL_RESPONSES_KEY
          key to retrieve from the DataStore of the behaviour the Vector of all messages that have been received as response.
 java.lang.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).
 
Fields inherited from class jade.core.behaviours.FSMBehaviour
currentName, lastStates
 
Fields inherited from class jade.core.behaviours.Behaviour
myAgent
 
Constructor Summary
TwoPh2Initiator(Agent a, ACLMessage acceptance)
          Constructs a TwoPh2Initiator behaviour.
TwoPh2Initiator(Agent a, ACLMessage acceptance, DataStore store)
          Constructs a TwoPh2Initiator behaviour.
 
Method Summary
protected  java.lang.String createConvId(java.util.Vector msgs)
          Create a new conversation identifier to begin a new interaction.
protected  ProtocolSession getSession(ACLMessage msg, int sessionIndex)
           
protected  void handleAllResponses(java.util.Vector responses)
          This method is called when all the responses have been collected.
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 handleInform(ACLMessage inform)
          This method is called every time a inform message is received, which is not out-of-sequence according to the protocol rules.
protected  void handleNotUnderstood(ACLMessage notUnderstood)
          This method is called every time a not-understood message is received, which is not out-of-sequence according to the protocol rules.
protected  void handleOldResponse(ACLMessage old)
          This method is called every time a failure, a disconfirm or an inform message is received, 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, which is out-of-sequence according to the protocol rules.
 void onStart()
          Override the onStart() method to initialize the vectors that will keep all the replies in the data store.
protected  java.util.Vector prepareAcceptances(ACLMessage acceptance)
          This method must return the vector of ACLMessage objects to be sent.
 void registerHandleAllResponses(Behaviour b)
          This method allows to register a user defined Behaviour in the HANDLE_ALL_RESPONSES state.
 void registerHandleFailure(Behaviour b)
          This method allows to register a user defined Behaviour in the HANDLE_FAILURE state.
 void registerHandleInform(Behaviour b)
          This method allows to register a user defined Behaviour in the HANDLE_INFORM state.
 void registerHandleNotUnderstood(Behaviour b)
          This method allows to register a user defined Behaviour in the HANDLE_NOT_UNDERSTOOD state.
 void registerHandleOldResponse(Behaviour b)
          This method allows to register a user defined Behaviour in the HANDLE_OLD_RESPONSE state.
 void registerHandleOutOfSequence(Behaviour b)
          This method allows to register a user defined Behaviour in the HANDLE_OUT_OF_SEQ state.
 void registerPrepareProposals(Behaviour b)
          This method allows to register a user-defined Behaviour in the PREPARE_ACCEPTANCES state.
protected  void reinit()
          Re-initialize the internal state without performing a complete reset.
 void reset()
          reset this behaviour by putting a null ACLMessage as message to be sent
 void reset(ACLMessage msg)
          reset this behaviour
 void setDataStore(DataStore ds)
          Override the setDataStore() method to propagate this setting to all children.
 
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, 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, root, setBehaviourName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACCEPTANCE_KEY

public final java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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.

Constructor Detail

TwoPh2Initiator

public TwoPh2Initiator(Agent a,
                       ACLMessage acceptance)
Constructs a TwoPh2Initiator behaviour.

Parameters:
a - The agent performing the protocol.

TwoPh2Initiator

public TwoPh2Initiator(Agent a,
                       ACLMessage acceptance,
                       DataStore store)
Constructs a TwoPh2Initiator behaviour.

Parameters:
a - The agent performing the protocol.
store - DataStore that will be used by this TwoPh2Initiator.
Method Detail

prepareAcceptances

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

handleInform

protected void handleInform(ACLMessage inform)
This method is called every time a inform 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:
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, 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(java.util.Vector responses)
This method is called 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

registerPrepareProposals

public void registerPrepareProposals(Behaviour b)
This method allows to register a user-defined Behaviour in the PREPARE_ACCEPTANCES 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 Vector of ACLMessage objects to be sent into the datastore at the ALL_ACCEPTANCES_KEY key.

Parameters:
b - the Behaviour that will handle this state

registerHandleInform

public void registerHandleInform(Behaviour b)
This method allows to register a user defined Behaviour in the HANDLE_INFORM 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. The registered behaviour can retrieve the inform ACLMessage object received from the datastore at the REPLY_KEY key.

Parameters:
b - the Behaviour that will handle this state

registerHandleOldResponse

public void registerHandleOldResponse(Behaviour b)
This method allows to register a user defined Behaviour in the HANDLE_OLD_RESPONSE 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. The registered behaviour can retrieve the failure, disconfirm or inform ACLMessage object received from the datastore at the REPLY_KEY key.

Parameters:
b - the Behaviour that will handle this state

registerHandleAllResponses

public void registerHandleAllResponses(Behaviour b)
This method allows to register a user defined Behaviour in the HANDLE_ALL_RESPONSES 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. The registered behaviour can retrieve the vector of ACLMessage received from the datastore at ALL_RESPONSES_RECEIVED_KEY.

Parameters:
b - the Behaviour that will handle this state

getSession

protected ProtocolSession getSession(ACLMessage msg,
                                     int sessionIndex)

handleNotUnderstood

protected void handleNotUnderstood(ACLMessage notUnderstood)
This method is called every time a not-understood 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:
notUnderstood - the received not-understood 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 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

registerHandleNotUnderstood

public void registerHandleNotUnderstood(Behaviour b)
This method allows to register a user defined Behaviour in the HANDLE_NOT_UNDERSTOOD 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. The registered behaviour can retrieve the not-understood ACLMessage object received from the datastore at the REPLY_KEY key.

Parameters:
b - the Behaviour that will handle this state

registerHandleFailure

public void registerHandleFailure(Behaviour b)
This method allows to register a user defined Behaviour in the HANDLE_FAILURE 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. The registered behaviour can retrieve the failure ACLMessage object received from the datastore at the REPLY_KEY key.

Parameters:
b - the Behaviour that will handle this state

registerHandleOutOfSequence

public void registerHandleOutOfSequence(Behaviour b)
This method allows to register a user defined Behaviour in the HANDLE_OUT_OF_SEQ 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. The registered behaviour can retrieve the out of sequence ACLMessage object received from the datastore at the REPLY_KEY key.

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:
reset in class FSMBehaviour

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.

Overrides:
onStart in class Behaviour

setDataStore

public void setDataStore(DataStore ds)
Override the setDataStore() method to propagate this setting to all children.

Overrides:
setDataStore in class Behaviour
Parameters:
ds - the DataStore that this Behaviour will use as its private data store

createConvId

protected java.lang.String createConvId(java.util.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-id slot, its value is used, else a new conversation identifier is generated.


JADE