jade.proto
Class ProposeResponder

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

public class ProposeResponder
extends FSMBehaviour
implements FIPANames.InteractionProtocol

Behaviour class for fipa-propose Responder role. This behaviour implements the fipa-propose interaction protocol from the point of view of a responder to a propose (propose) message.

The API of this class is similar and homogeneous to the AchieveREResponder.

When a message arrives that matches the message template passed to the constructor, the callback method prepareResponse is executed that must return the wished response, for instance the ACCEPT_PROPOSAL reply message. Any other type of returned communicative act is sent and then closes the protocol.

If a message were received, with the same value of this conversation-id, but that does not comply with the FIPA protocol, than the method handleOutOfSequence would be called.

This class can be extended by the programmer by overriding all the needed handle methods or, in alternative, appropriate behaviours can be registered for each handle via the registerHandle-type of methods. This last case is more difficult to use and proper care must be taken to properly use the DataStore of the Behaviour as a shared memory mechanism with the registered behaviour.

Read carefully the section of the JADE programmer's guide that describes the usage of this class.

Version:
$Date: 2005-09-16 15:54:46 +0200 (ven, 16 set 2005) $ $Revision: 5780 $
Author:
Jerome Picault - Motorola Labs
See Also:
ProposeInitiator, AchieveREResponder, Serialized Form

Field Summary
protected static java.lang.String PREPARE_RESPONSE
           
 java.lang.String PROPOSE_KEY
          key to retrieve from the DataStore of the behaviour the ACLMessage object sent by the initiator.
protected static java.lang.String RECEIVE_PROPOSE
           
 java.lang.String RESPONSE_KEY
          key to retrieve from the DataStore of the behaviour the ACLMessage object sent as a response to the initiator.
protected static java.lang.String SEND_RESPONSE
           
 
Fields inherited from class jade.core.behaviours.FSMBehaviour
currentName, lastStates
 
Fields inherited from class jade.core.behaviours.Behaviour
myAgent
 
Fields inherited from interface jade.domain.FIPANames.InteractionProtocol
FIPA_BROKERING, FIPA_CONTRACT_NET, FIPA_DUTCH_AUCTION, FIPA_ENGLISH_AUCTION, FIPA_ITERATED_CONTRACT_NET, FIPA_PROPOSE, FIPA_QUERY, FIPA_RECRUITING, FIPA_REQUEST, FIPA_REQUEST_WHEN, FIPA_SUBSCRIBE, ITERATED_FIPA_REQUEST
 
Constructor Summary
ProposeResponder(Agent a, MessageTemplate mt)
          Constructor of the behaviour that creates a new empty DataStore
ProposeResponder(Agent a, MessageTemplate mt, DataStore store)
          Constructor.
 
Method Summary
static MessageTemplate createMessageTemplate(java.lang.String iprotocol)
          This static method can be used to set the proper message template (based on the interaction protocol and the performative) into the constructor of this behaviour.
protected  ACLMessage prepareResponse(ACLMessage propose)
          This method is called when the initiator's message is received that matches the message template passed in the constructor.
 void registerPrepareResponse(Behaviour b)
          This method allows to register a user defined Behaviour in the PREPARE_RESPONSE state.
 void reset()
          Reset this behaviour.
 void reset(MessageTemplate mt)
          This method allows to change the MessageTemplate that defines what messages this ProposeResponder will react to and reset the protocol.
 
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

PROPOSE_KEY

public final java.lang.String PROPOSE_KEY
key to retrieve from the DataStore of the behaviour the ACLMessage object sent by the initiator.


RESPONSE_KEY

public final java.lang.String RESPONSE_KEY
key to retrieve from the DataStore of the behaviour the ACLMessage object sent as a response to the initiator.


RECEIVE_PROPOSE

protected static final java.lang.String RECEIVE_PROPOSE
See Also:
Constant Field Values

PREPARE_RESPONSE

protected static final java.lang.String PREPARE_RESPONSE
See Also:
Constant Field Values

SEND_RESPONSE

protected static final java.lang.String SEND_RESPONSE
See Also:
Constant Field Values
Constructor Detail

ProposeResponder

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

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

ProposeResponder

public ProposeResponder(Agent a,
                        MessageTemplate mt,
                        DataStore store)
Constructor.

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.
store - the DataStore for this protocol
Method Detail

createMessageTemplate

public static MessageTemplate createMessageTemplate(java.lang.String iprotocol)
This static method can be used to set the proper message template (based on the interaction protocol and the performative) into the constructor of this behaviour.

See Also:
FIPANames.InteractionProtocol

reset

public void reset()
Reset this behaviour.

Overrides:
reset in class FSMBehaviour

reset

public void reset(MessageTemplate mt)
This method allows to change the MessageTemplate that defines what messages this ProposeResponder will react to and reset the protocol.


prepareResponse

protected ACLMessage prepareResponse(ACLMessage propose)
                              throws NotUnderstoodException,
                                     RefuseException
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:
propose - the received message
Returns:
the ACLMessage to be sent as a response (i.e. one of accept_proposal, reject_proposal, not-understood. Remind to use the method createReply of the class ACLMessage in order to create a good reply message
NotUnderstoodException
RefuseException
See Also:
ACLMessage.createReply()

registerPrepareResponse

public void registerPrepareResponse(Behaviour b)
This method allows to register a user defined Behaviour in the PREPARE_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. It is responsibility of the registered behaviour to put the response to be sent into the datastore at the RESPONSE_KEY key.

Parameters:
b - the Behaviour that will handle this state


JADE