jade.proto
Class TwoPhResponder

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

public class TwoPhResponder
extends jade.proto.Responder

Class description

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

Field Summary
 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.
 
Fields inherited from class jade.core.behaviours.FSMBehaviour
currentName, lastStates
 
Fields inherited from class jade.core.behaviours.Behaviour
myAgent
 
Constructor Summary
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.
 
Method Summary
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.
 
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, onStart, root, setBehaviourName, setDataStore
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RECEIVED_KEY

public final java.lang.String RECEIVED_KEY
Key to retrieve from the DataStore of the behaviour the last received ACLMessage


REPLY_KEY

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

Constructor Detail

TwoPhResponder

public TwoPhResponder(Agent a,
                      MessageTemplate mt)
Constructor of the behaviour that creates a new empty DataStore

See Also:
TwoPhResponder(Agent a, MessageTemplate mt, DataStore store)

TwoPhResponder

public TwoPhResponder(Agent a,
                      MessageTemplate mt,
                      DataStore store)
Constructor of the behaviour.

Parameters:
a - is the reference to the Agent object
mt - 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 behaviour
Method Detail

handleCfp

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. This default implementation return null which has the effect of sending no reponse. Programmers should override the method in case they need to react to this event.

Parameters:
cfp - the received message
Returns:
the ACLMessage to be sent as a response (i.e. one of PROPOSE, FAILURE. Remind to use the method createReply of the class ACLMessage in order to create a valid reply message
See Also:
ACLMessage.createReply()

handleQueryIf

protected ACLMessage handleQueryIf(ACLMessage queryIf)
This method is called after the 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.

Parameters:
queryIf - the received message
Returns:
the ACLMessage to be sent as a result notification (i.e. one of CONFIRM, INFORM, DISCONFIRM. Remind to use the method createReply of the class ACLMessage in order to create a valid reply message
See Also:
ACLMessage.createReply()

handleRejectProposal

protected ACLMessage handleRejectProposal(ACLMessage reject)
This method is called after the REJECT-PROPOSAL has been received. This default implementation do nothing. Programmers should override the method in case they need to react to this event.

Parameters:
reject - the received message
Returns:
the ACLMessage to be sent as a result notification (i.e. an INFORM. Remind to use the method createReply of the class ACLMessage in order to create a valid reply message
See Also:
ACLMessage.createReply()

handleAcceptProposal

protected ACLMessage handleAcceptProposal(ACLMessage accept)
This method is called after the 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.

Parameters:
accept - the received message
Returns:
the ACLMessage to be sent as a result notification (i.e. an INFORM. Remind to use the method createReply of the class ACLMessage in order to create a valid reply message
See Also:
ACLMessage.createReply()

registerHandleCfp

public void registerHandleCfp(Behaviour b)
This method allows to register a user defined 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.

Parameters:
b - the Behaviour that will handle this state

registerHandleQueryIf

public void registerHandleQueryIf(Behaviour b)
This method allows to register a user defined 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.

Parameters:
b - the Behaviour that will handle this state

registerHandleRejectProposal

public void registerHandleRejectProposal(Behaviour b)
This method allows to register a user defined 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.

Parameters:
b - the Behaviour that will handle this state

registerHandleAcceptProposal

public void registerHandleAcceptProposal(Behaviour b)
This method allows to register a user defined 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.

Parameters:
b - the Behaviour that will handle this state

createMessageTemplate

public 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.

See Also:
FIPANames.InteractionProtocol

reset

public void reset()
Description copied from class: jade.proto.Responder
Reset this behaviour.

Overrides:
reset in class jade.proto.Responder

handleOutOfSequence

protected void handleOutOfSequence(ACLMessage msg)
This method is called whenever a message is received that does not comply to the protocol rules. This default implementation does nothing. Programmers may override it in case they need to react to this event.

Parameters:
msg - the received out-of-sequence message.

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 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.

Parameters:
b - the Behaviour that will handle this state


JADE