Class ContractNetResponder
-
- All Implemented Interfaces:
Serializable,Serializable
public class ContractNetResponder extends SSContractNetResponder
Behaviour class forfipa-contract-netResponder role. This behaviour implements thefipa-contract-netinteraction protocol from the point of view of a responder to a call for proposal (cfp) message.The API of this class is similar and homogeneous to the
AchieveREResponder.Read also the introduction to ContractNetInitiator for a description of the protocol.
When a message arrives that matches the message template passed to the constructor, the callback method
prepareResponseis executed that must return the wished response, for instance thePROPOSEreply message. Any other type of returned communicative act is sent and then closes the protocol.Then, if the initiator accepted the proposal, i.e. if an
ACCEPT-PROPOSALmessage was received, the callback methodprepareResultNotificationwould be executed that must return the message with the result notification, i.e.INFORMorFAILURE.
In alternative, if the initiator rejected the proposal, i.e. if anREJECT-PROPOSALmessage was received, the callback methodhandleRejectProposalwould be executed and the protocol terminated.If a message were received, with the same value of this
conversation-id, but that does not comply with the FIPA protocol, than the methodhandleOutOfSequencewould 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 theDataStoreof theBehaviouras 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$ $Revision$
- Author:
- Fabio Bellifemine - TILAB, Giovanni Caire - TILAB, Marco Monticone - TILAB
- See Also:
ContractNetInitiator,AchieveREResponder, 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 protected static StringCHECK_IN_SEQprotected static StringDUMMY_FINALprotected static StringHANDLE_OUT_OF_SEQUENCEStringINITIATION_KEYKey to retrieve from the DataStore of the behaviour the initiation ACLMessage that triggered this responder sessionStringPROPOSE_ACCEPTANCE_KEYDeprecated.Use eitherACCEPT_PROPOSAL_KEYorREJECT_PROPOSAL_KEYaccording to the message that has been receivedstatic StringRECEIVE_CFPprotected static StringRECEIVE_NEXTStringRECEIVED_KEYKey to retrieve from the DataStore of the behaviour the last received ACLMessageStringREPLY_KEYKey to set into the DataStore of the behaviour the new ACLMessage to be sent back to the initiator as a reply.StringRESPONSE_KEYDeprecated.UseREPLY_KEYStringRESULT_NOTIFICATION_KEYDeprecated.UseREPLY_KEYprotected static StringSEND_REPLY-
Fields inherited from class jade.proto.SSContractNetResponder
ACCEPT_PROPOSAL_KEY, CFP_KEY, HANDLE_ACCEPT_PROPOSAL, HANDLE_CFP, HANDLE_REJECT_PROPOSAL, PROPOSE_KEY, REJECT_PROPOSAL_KEY
-
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 ContractNetResponder(Agent a, MessageTemplate mt)Constructor of the behaviour that creates a new empty DataStoreContractNetResponder(Agent a, MessageTemplate mt, DataStore store)Constructor of the behaviour.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static MessageTemplatecreateMessageTemplate(String iprotocol)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 ACLMessagehandleAcceptProposal(ACLMessage cfp, ACLMessage propose, ACLMessage accept)Redefine this method to call prepareResultNotification()protected ACLMessagehandleCfp(ACLMessage cfp)Redefine this method to call prepareResponse()voidonStart()This method is just an empty placeholders for subclasses.protected ACLMessageprepareResponse(ACLMessage cfp)Deprecated.UsehandleCfp()insteadprotected ACLMessageprepareResultNotification(ACLMessage cfp, ACLMessage propose, ACLMessage accept)Deprecated.UsehandleAcceptProposal()instead.protected voidregisterDSState(Behaviour b, String name)Utility method to register a behaviour in a state of the protocol and set the DataStore appropriatelyvoidregisterHandleCfp(Behaviour b)Redefine this method so that the HANDLE_CFP state is not registered as first statevoidregisterHandleOutOfSequence(Behaviour b)This method allows to register a user definedBehaviourin the HANDLE_OUT_OF_SEQ state.voidregisterPrepareResponse(Behaviour b)Deprecated.UseregisterHandleCfp()instead.voidregisterPrepareResultNotification(Behaviour b)Deprecated.UseregisterHandleAcceptProposal()instead.voidreset()Reset this behaviour.protected voidsessionTerminated()This method can be redefined by protocol specific implementations to take proper actions after the completion of the current protocol session.-
Methods inherited from class jade.proto.SSContractNetResponder
afterReply, beforeReply, checkInSequence, handleOutOfSequence, handleOutOfSequence, handleRejectProposal, registerHandleAcceptProposal, registerHandleRejectProposal, reinit
-
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, 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, restart, root, setBehaviourName, setDataStore, setExecutionState
-
-
-
-
Field Detail
-
RESPONSE_KEY
public final String RESPONSE_KEY
Deprecated.UseREPLY_KEY
-
PROPOSE_ACCEPTANCE_KEY
public final String PROPOSE_ACCEPTANCE_KEY
Deprecated.Use eitherACCEPT_PROPOSAL_KEYorREJECT_PROPOSAL_KEYaccording to the message that has been received
-
RESULT_NOTIFICATION_KEY
public final String RESULT_NOTIFICATION_KEY
Deprecated.UseREPLY_KEY
-
RECEIVE_CFP
public static final String RECEIVE_CFP
- See Also:
- Constant Field Values
-
INITIATION_KEY
public final String INITIATION_KEY
Key to retrieve from the DataStore of the behaviour the initiation ACLMessage that triggered this responder session
-
RECEIVED_KEY
public final String RECEIVED_KEY
Key to retrieve from the DataStore of the behaviour the last received ACLMessage
-
REPLY_KEY
public final 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.
-
RECEIVE_NEXT
protected static final String RECEIVE_NEXT
- See Also:
- Constant Field Values
-
CHECK_IN_SEQ
protected static final String CHECK_IN_SEQ
- See Also:
- Constant Field Values
-
HANDLE_OUT_OF_SEQUENCE
protected static final String HANDLE_OUT_OF_SEQUENCE
- See Also:
- Constant Field Values
-
SEND_REPLY
protected static final String SEND_REPLY
- See Also:
- Constant Field Values
-
DUMMY_FINAL
protected static final String DUMMY_FINAL
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ContractNetResponder
public ContractNetResponder(Agent a, MessageTemplate mt)
Constructor of the behaviour that creates a new empty DataStore
-
ContractNetResponder
public ContractNetResponder(Agent a, MessageTemplate mt, DataStore store)
Constructor of the behaviour.- Parameters:
a- is the reference to the Agent objectmt- 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 methodcreateMessageTemplatemight be usefull.store- the DataStore for this protocol behaviour
-
-
Method Detail
-
prepareResponse
protected ACLMessage prepareResponse(ACLMessage cfp) throws NotUnderstoodException, RefuseException
Deprecated.UsehandleCfp()instead
-
prepareResultNotification
protected ACLMessage prepareResultNotification(ACLMessage cfp, ACLMessage propose, ACLMessage accept) throws FailureException
Deprecated.UsehandleAcceptProposal()instead.- Throws:
FailureException
-
registerPrepareResponse
public void registerPrepareResponse(Behaviour b)
Deprecated.UseregisterHandleCfp()instead.
-
registerPrepareResultNotification
public void registerPrepareResultNotification(Behaviour b)
Deprecated.UseregisterHandleAcceptProposal()instead.
-
handleCfp
protected ACLMessage handleCfp(ACLMessage cfp) throws RefuseException, FailureException, NotUnderstoodException
Redefine this method to call prepareResponse()- Overrides:
handleCfpin classSSContractNetResponder- Parameters:
cfp- the initial CFP message to handle.- Returns:
- the reply message to be sent back to the initiator. Returning a message different than PROPOSE (or returning null) terminates the protocol.
- Throws:
RefuseException- if the CFP is refused. Throwing a RefuseException has the same effect as returning a REFUSE message, but automatically manages the:contentslot.FailureException- if there is an error serving the CFP. Throwing a FailureException has the same effect as returning a FAILURE message, but automatically manages the:contentslot.NotUnderstoodException- if the CFP content is not understood. Throwing a NotUnderstoodException has the same effect as returning a NOT_UNDERSTOOD message, but automatically manages the:contentslot.
-
handleAcceptProposal
protected ACLMessage handleAcceptProposal(ACLMessage cfp, ACLMessage propose, ACLMessage accept) throws FailureException
Redefine this method to call prepareResultNotification()- Overrides:
handleAcceptProposalin classSSContractNetResponder- Parameters:
cfp- the initial CFP message.propose- the PROPOSE message sent back as reply to the initial CFP message.accept- the received ACCEPT_PROPOSAL message.- Returns:
- the reply message to be sent back to the initiator.
- Throws:
FailureException- if there is an error serving the ACCEPT_PROPOSAL. Throwing a FailureException has the same effect as returning a FAILURE message, but automatically manages the:contentslot.
-
registerHandleCfp
public void registerHandleCfp(Behaviour b)
Redefine this method so that the HANDLE_CFP state is not registered as first state- Overrides:
registerHandleCfpin classSSContractNetResponder- Parameters:
b- the Behaviour that will handle this state
-
sessionTerminated
protected void sessionTerminated()
This method can be redefined by protocol specific implementations to take proper actions after the completion of the current protocol session.
-
createMessageTemplate
public static MessageTemplate createMessageTemplate(String iprotocol)
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
-
onStart
public void onStart()
Description copied from class:BehaviourThis method is just an empty placeholders for subclasses. It is executed just once before starting behaviour execution. Therefore, it acts as a prolog to the task represented by thisBehaviour.
-
registerHandleOutOfSequence
public void registerHandleOutOfSequence(Behaviour b)
This method allows to register a user definedBehaviourin the HANDLE_OUT_OF_SEQ state. This behaviour would override the homonymous method. This method also sets the data store of the registeredBehaviourto the DataStore of this current behaviour. The registered behaviour can retrieve theout of sequenceACLMessage object received from the datastore at theRECEIVED_KEYkey.- Parameters:
b- the Behaviour that will handle this state
-
reset
public void reset()
Reset this behaviour.- Overrides:
resetin classFSMBehaviour
-
-