Class ProposeInitiator
-
- All Implemented Interfaces:
Serializable,Serializable
public class ProposeInitiator extends FSMBehaviour
This class implements the Fipa-Propose interaction protocol with an API similar and homogeneous toAchieveREInitiator.
This implementation works both for 1:1 and 1:N conversation and, of course, implements the role of the initiator of the protocol.The following is a brief description of the protocol. The programmer should however refer to the FIPA Spec for a complete description.
The initiator sends a
PROPOSEmessage to the Participant indicating that it will perform some action if the Participant agrees. The implementation of the callback methodprepareInitiationsmust return the vector of messages to be sent (eventually a single message with multiple receivers).The responders can then reply by sending a
ACCEPT-PROPOSALmessage. Alternatively, responders may send aREJECT-PROPOSAL, to refuse the proposal or, eventually, aNOT-UNDERSTOODto communicate communication problems. This category of reply messages has been here identified as a response and can be handled via thehandleAllResponsescallback method. Specific handle callback methods for each type of communicative act are also available when the programmer wishes to handle them separately:handleRejectProposal, handleAcceptProposal, handleNotUnderstoodIf 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.
- Since:
- JADE3.1
- Version:
- $Date$ $Revision$
- Author:
- Jerome Picault - Motorola Labs
- See Also:
ProposeResponder,AchieveREInitiator, FIPA Spec, 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 StringALL_INITIATIONS_Kkey to retrieve from the DataStore of the behaviour the vector of PROPOSE ACLMessage objects that have to be sent.StringALL_RESPONSES_KEYkey to retrieve from the DataStore of the behaviour the vector of ACLMessage objects that have been received as responses.protected static StringCHECK_IN_SEQprotected static StringCHECK_SESSIONSprotected static StringDUMMY_FINALprotected static StringHANDLE_ACCEPT_PROPOSALprotected static StringHANDLE_ALL_RESPONSESprotected static StringHANDLE_NOT_UNDERSTOODprotected static StringHANDLE_OUT_OF_SEQprotected static StringHANDLE_REJECT_PROPOSALprotected StringINITIATION_Kkey to retrieve from the DataStore of the behaviour the ACLMessage object passed in the constructor of the class.protected static StringPREPARE_INITIATIONSprotected static StringRECEIVE_REPLYStringREPLY_KEYkey to retrieve from the DataStore of the behaviour the last ACLMessage object that has been received (null if the timeout expired).protected MsgReceiverreplyReceiverprotected MessageTemplatereplyTemplateprotected static StringSEND_INITIATIONSprotected Mapsessionsprotected String[]toBeReset-
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 ProposeInitiator(Agent a, ACLMessage msg)Construct aProposeInitiatorwith an empty DataStoreProposeInitiator(Agent a, ACLMessage initiation, DataStore store)Construct aProposeInitiatorwith a given DataStore
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidadjustReplyTemplate(ACLMessage msg)protected booleancheckInSequence(ACLMessage reply)Check whether a reply is in-sequence and update the appropriate Session.protected intcheckSessions(ACLMessage reply)Check the status of the sessions after the reception of the last reply or the expiration of the timeout.protected StringcreateConvId(Vector msgs)Create a new conversation identifier to begin a new interaction.protected voidhandleAcceptProposal(ACLMessage accept_proposal)This method is called every time anaccept-proposalmessage is received, which is not out-of-sequence according to the protocol rules.protected voidhandleAllResponses(Vector responses)This method is called when all the responses have been collected or when the timeout is expired.protected voidhandleNotUnderstood(ACLMessage notUnderstood)This method is called every time anot-understoodmessage is received, which is not out-of-sequence according to the protocol rules.protected voidhandleOutOfSequence(ACLMessage msg)This method is called every time a message is received, which is out-of-sequence according to the protocol rules.protected voidhandleRejectProposal(ACLMessage reject_proposal)This method is called every time anreject-proposalmessage is received, which is not out-of-sequence according to the protocol rules.protected voidinitializeDataStore(ACLMessage msg)Initialize the data store.voidonStart()Override the onStart() method to initialize the vectors that will keep all the replies in the data store.protected VectorprepareInitiations(ACLMessage propose)This method must return the vector of ACLMessage objects to be sent.voidregisterHandleAcceptProposal(Behaviour b)This method allows to register a user definedBehaviourin the HANDLE_ACCEPT_PROPOSAL state.voidregisterHandleAllResponses(Behaviour b)This method allows to register a user definedBehaviourin the HANDLE_ALL_RESPONSES state.voidregisterHandleNotUnderstood(Behaviour b)This method allows to register a user definedBehaviourin the HANDLE_NOT_UNDERSTOOD state.voidregisterHandleOutOfSequence(Behaviour b)This method allows to register a user definedBehaviourin the HANDLE_OUT_OF_SEQ state.voidregisterHandleRejectProposal(Behaviour b)This method allows to register a user definedBehaviourin the HANDLE_REJECT_PROPOSAL state.voidreset()reset this behaviour by putting a null ACLMessage as message to be sentvoidreset(ACLMessage msg)reset this behaviourprotected voidsendInitiations(Vector initiations)Create and initialize the Sessions and sends the initiation messages.voidsetDataStore(DataStore ds)Override the setDataStore() method to initialize propagate this setting to all children.-
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, setExecutionState
-
-
-
-
Field Detail
-
INITIATION_K
protected final String INITIATION_K
key to retrieve from the DataStore of the behaviour the ACLMessage object passed in the constructor of the class.
-
ALL_INITIATIONS_K
protected final String ALL_INITIATIONS_K
key to retrieve from the DataStore of the behaviour the vector of PROPOSE ACLMessage objects that have to be sent.
-
REPLY_KEY
public final 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 String ALL_RESPONSES_KEY
key to retrieve from the DataStore of the behaviour the vector of ACLMessage objects that have been received as responses.
-
PREPARE_INITIATIONS
protected static final String PREPARE_INITIATIONS
- See Also:
- Constant Field Values
-
SEND_INITIATIONS
protected static final String SEND_INITIATIONS
- See Also:
- Constant Field Values
-
RECEIVE_REPLY
protected static final String RECEIVE_REPLY
- See Also:
- Constant Field Values
-
CHECK_IN_SEQ
protected static final String CHECK_IN_SEQ
- See Also:
- Constant Field Values
-
HANDLE_NOT_UNDERSTOOD
protected static final String HANDLE_NOT_UNDERSTOOD
- See Also:
- Constant Field Values
-
HANDLE_OUT_OF_SEQ
protected static final String HANDLE_OUT_OF_SEQ
- See Also:
- Constant Field Values
-
HANDLE_ALL_RESPONSES
protected static final String HANDLE_ALL_RESPONSES
- See Also:
- Constant Field Values
-
HANDLE_REJECT_PROPOSAL
protected static final String HANDLE_REJECT_PROPOSAL
- See Also:
- Constant Field Values
-
HANDLE_ACCEPT_PROPOSAL
protected static final String HANDLE_ACCEPT_PROPOSAL
- See Also:
- Constant Field Values
-
CHECK_SESSIONS
protected static final String CHECK_SESSIONS
- See Also:
- Constant Field Values
-
DUMMY_FINAL
protected static final String DUMMY_FINAL
- See Also:
- Constant Field Values
-
sessions
protected Map sessions
-
replyReceiver
protected MsgReceiver replyReceiver
-
replyTemplate
protected MessageTemplate replyTemplate
-
toBeReset
protected String[] toBeReset
-
-
Constructor Detail
-
ProposeInitiator
public ProposeInitiator(Agent a, ACLMessage msg)
Construct aProposeInitiatorwith an empty DataStore
-
ProposeInitiator
public ProposeInitiator(Agent a, ACLMessage initiation, DataStore store)
Construct aProposeInitiatorwith a given DataStore- Parameters:
a- The agent performing the protocolinitiation- The message that must be used to initiate the protocol. Notice that the default implementation of theprepareInitiations()method returns an array composed of only this message. The values of the slotreply-withis ignored and a different value is assigned automatically by this class for each receiver.store- TheDataStorethat will be used by thisProposeInitiator
-
-
Method Detail
-
initializeDataStore
protected void initializeDataStore(ACLMessage msg)
Initialize the data store.
-
sendInitiations
protected void sendInitiations(Vector initiations)
Create and initialize the Sessions and sends the initiation messages. This method is called internally by the framework and is not intended to be called by the user
-
checkInSequence
protected boolean checkInSequence(ACLMessage reply)
Check whether a reply is in-sequence and update the appropriate Session. This method is called internally by the framework and is not intended to be called by the user
-
checkSessions
protected int checkSessions(ACLMessage reply)
Check the status of the sessions after the reception of the last reply or the expiration of the timeout. This method is called internally by the framework and is not intended to be called by the user
-
prepareInitiations
protected Vector prepareInitiations(ACLMessage propose)
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 PROPOSE) passed in the constructor. Programmers might prefer to override this method in order to return a vector of PROPOSE objects for 1:N conversations or also to prepare the messages during the execution of the behaviour.- Parameters:
propose- the ACLMessage object passed in the constructor- Returns:
- a Vector of ACLMessage objects. The value of the slot
reply-withis ignored and regenerated automatically by this class.
-
handleAcceptProposal
protected void handleAcceptProposal(ACLMessage accept_proposal)
This method is called every time anaccept-proposalmessage 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:
accept_proposal- the received accept-proposal message
-
handleRejectProposal
protected void handleRejectProposal(ACLMessage reject_proposal)
This method is called every time anreject-proposalmessage 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:
reject_proposal- the received reject-proposal message
-
handleNotUnderstood
protected void handleNotUnderstood(ACLMessage notUnderstood)
This method is called every time anot-understoodmessage 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
-
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
-
registerHandleAllResponses
public void registerHandleAllResponses(Behaviour b)
This method allows to register a user definedBehaviourin the HANDLE_ALL_RESPONSES state. This behaviour would override the homonymous method. This method also set the data store of the registeredBehaviourto the DataStore of this current behaviour. The registered behaviour can retrieve the vector of ACLMessage objects, received as a response, from the datastore at theALL_RESPONSES_KEYkey.- Parameters:
b- the Behaviour that will handle this state
-
registerHandleAcceptProposal
public void registerHandleAcceptProposal(Behaviour b)
This method allows to register a user definedBehaviourin the HANDLE_ACCEPT_PROPOSAL state. This behaviour would override the homonymous method. This method also set the data store of the registeredBehaviourto the DataStore of this current behaviour. The registered behaviour can retrieve theinformACLMessage object received from the datastore at theREPLY_KEYkey.- Parameters:
b- the Behaviour that will handle this state
-
registerHandleRejectProposal
public void registerHandleRejectProposal(Behaviour b)
This method allows to register a user definedBehaviourin the HANDLE_REJECT_PROPOSAL state. This behaviour would override the homonymous method. This method also set the data store of the registeredBehaviourto the DataStore of this current behaviour. The registered behaviour can retrieve theinformACLMessage object received from the datastore at theREPLY_KEYkey.- Parameters:
b- the Behaviour that will handle this state
-
registerHandleNotUnderstood
public void registerHandleNotUnderstood(Behaviour b)
This method allows to register a user definedBehaviourin the HANDLE_NOT_UNDERSTOOD state. This behaviour would override the homonymous method. This method also set the data store of the registeredBehaviourto the DataStore of this current behaviour. The registered behaviour can retrieve thenot-understoodACLMessage object received from the datastore at theREPLY_KEYkey.- Parameters:
b- the Behaviour that will handle this state
-
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 set 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 theREPLY_KEYkey.- Parameters:
b- the Behaviour that will handle this state
-
handleAllResponses
protected void handleAllResponses(Vector responses)
This method is called when all the responses have been collected or when the timeout is expired. The used timeout is the minimum value of the slotreplyByof all the sent messages. By response message we intend here all theaccept-proposal, reject-proposal, not-understoodreceived messages, which are not 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 ACLMessage objects that have been received
-
reset
public void reset()
reset this behaviour by putting a null ACLMessage as message to be sent- Overrides:
resetin classFSMBehaviour
-
reset
public void reset(ACLMessage msg)
reset this behaviour- Parameters:
msg- is the ACLMessage to be sent
-
onStart
public void onStart()
Override the onStart() method to initialize the vectors that will keep all the replies in the data store.
-
setDataStore
public void setDataStore(DataStore ds)
Override the setDataStore() method to initialize propagate this setting to all children.- Overrides:
setDataStorein classBehaviour- Parameters:
ds- theDataStorethat thisBehaviourwill use as its private data store
-
createConvId
protected String createConvId(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-idslot, its value is used, else a new conversation identifier is generated.
-
adjustReplyTemplate
protected void adjustReplyTemplate(ACLMessage msg)
-
-