Package jade.proto
Class IteratedAchieveREInitiator
- java.lang.Object
-
- jade.core.behaviours.Behaviour
-
- jade.core.behaviours.CompositeBehaviour
-
- jade.core.behaviours.SerialBehaviour
-
- jade.core.behaviours.FSMBehaviour
-
- jade.proto.AchieveREInitiator
-
- jade.proto.IteratedAchieveREInitiator
-
- All Implemented Interfaces:
Serializable,Serializable
public class IteratedAchieveREInitiator extends AchieveREInitiator
This class implements the initiator role in the iterated version of fipa-request like interaction protocols. In the iterated version, having received all the result notifications from the responders, the initiator may send further initiation messages. The session of such a protocol with a given responder terminates when one of the followings occurs: i) The initiator sends an explicit CANCEL message instead of the next initiation message to the responder. ii) The responder replies with a negative reply i.e. REFUSE, NOT_UNDERSTOOD or FAILURE ii) The responder attaches a termination flag to an INFORM result notification. That termination flag can be detected using theisSessionTerminated()method.- Author:
- Giovanni Caire - TILab
- See Also:
- 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_KStringALL_NEXT_REQUESTS_KEYKey to retrieve from the DataStore of the behaviour the vector of ACLMessage objects that will be sent at next round.protected static StringCHECK_IN_SEQprotected static StringCHECK_SESSIONSprotected static StringDUMMY_FINALprotected static StringHANDLE_FAILUREprotected static StringHANDLE_NOT_UNDERSTOODprotected static StringHANDLE_OUT_OF_SEQprotected StringINITIATION_Kprotected static StringPREPARE_INITIATIONSprotected static StringRECEIVE_REPLYstatic StringREINITprotected StringREPLY_Kprotected MsgReceiverreplyReceiverprotected MessageTemplatereplyTemplateprotected static StringSEND_INITIATIONSprotected Mapsessions-
Fields inherited from class jade.proto.AchieveREInitiator
ALL_REQUESTS_KEY, ALL_RESPONSES_KEY, ALL_RESULT_NOTIFICATIONS_KEY, CHECK_AGAIN, HANDLE_AGREE, HANDLE_ALL_RESPONSES, HANDLE_ALL_RESULT_NOTIFICATIONS, HANDLE_INFORM, HANDLE_REFUSE, REPLY_KEY, REQUEST_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 IteratedAchieveREInitiator(Agent a, ACLMessage msg)Construct anIteratedAchieveREInitiatorwith an empty DataStoreIteratedAchieveREInitiator(Agent a, ACLMessage msg, DataStore store)Construct anIteratedAchieveREInitiatorwith a given DataStore
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidadjustReplyTemplate(ACLMessage msg)protected StringcreateConvId(Vector msgs)Create a new conversation identifier to begin a new interaction.protected jade.proto.Initiator.ProtocolSessiongetSession(ACLMessage msg, int sessionIndex)Return a ProtocolSession object to manage replies to a given initiation messageprotected voidhandleAllResultNotifications(Vector resultNotifications)This method is redefined to call the proper overloaded methodprotected voidhandleAllResultNotifications(Vector resultNotifications, Vector nextRequests)This method is called when all the result notification messages of the current round have been collected.protected voidhandleFailure(ACLMessage failure)This method is called every time afailuremessage is received, which is not out-of-sequence according to the protocol rules.protected voidhandleInform(ACLMessage inform)This method is redefined to call the proper overloaded methodprotected voidhandleInform(ACLMessage inform, Vector nextRequests)This method is called every time aninformmessage is received, which is not out-of-sequence according to the protocol rules.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 voidinitializeDataStore(ACLMessage msg)Initialize the data store.static booleanisSessionTerminated(ACLMessage inform)Check if the responder has closed the session just after sending thisinformmessage.voidonStart()Override the onStart() method to initialize the vectors that will keep all the replies in the data store.protected voidprepareForNextRound()voidregisterHandleAllResultNotifications(Behaviour b)This method allows to register a user definedBehaviourin the HANDLE_ALL_RESULT_NOTIFICATIONS state.voidregisterHandleFailure(Behaviour b)This method allows to register a user definedBehaviourin the HANDLE_FAILURE state.voidregisterHandleInform(Behaviour b)This method allows to register a user definedBehaviourin the HANDLE_REFUSE 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.protected voidregisterPrepareInitiations(Behaviour b)Attach a behaviour to thePrepare-initiationsprotocol 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 messagesvoidsetDataStore(DataStore ds)Override the setDataStore() method to propagate this setting to all children.-
Methods inherited from class jade.proto.AchieveREInitiator
checkInSequence, checkSessions, getToBeReset, handleAgree, handleAllResponses, handleRefuse, prepareInitiations, prepareRequests, registerHandleAgree, registerHandleAllResponses, registerHandleRefuse, registerPrepareRequests, 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, setExecutionState
-
-
-
-
Field Detail
-
ALL_NEXT_REQUESTS_KEY
public final String ALL_NEXT_REQUESTS_KEY
Key to retrieve from the DataStore of the behaviour the vector of ACLMessage objects that will be sent at next round.
-
REINIT
public static final String REINIT
- See Also:
- Constant Field Values
-
INITIATION_K
protected final String INITIATION_K
-
ALL_INITIATIONS_K
protected final String ALL_INITIATIONS_K
-
REPLY_K
protected final String REPLY_K
-
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_FAILURE
protected static final String HANDLE_FAILURE
- See Also:
- Constant Field Values
-
HANDLE_OUT_OF_SEQ
protected static final String HANDLE_OUT_OF_SEQ
- 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
-
-
Constructor Detail
-
IteratedAchieveREInitiator
public IteratedAchieveREInitiator(Agent a, ACLMessage msg)
Construct anIteratedAchieveREInitiatorwith an empty DataStore
-
IteratedAchieveREInitiator
public IteratedAchieveREInitiator(Agent a, ACLMessage msg, DataStore store)
Construct anIteratedAchieveREInitiatorwith a given DataStore- Parameters:
a- The agent performing the protocolmsg- The message that must be used to initiate the protocol. Notice that the default implementation of theprepareRequest()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 thisAchieveREInitiator
-
-
Method Detail
-
prepareForNextRound
protected void prepareForNextRound()
-
initializeDataStore
protected void initializeDataStore(ACLMessage msg)
Description copied from class:AchieveREInitiatorInitialize the data store.- Overrides:
initializeDataStorein classAchieveREInitiator
-
getSession
protected jade.proto.Initiator.ProtocolSession getSession(ACLMessage msg, int sessionIndex)
Return a ProtocolSession object to manage replies to a given initiation message- Overrides:
getSessionin classAchieveREInitiator
-
handleInform
protected void handleInform(ACLMessage inform, Vector nextRequests)
This method is called every time aninformmessage is received, which is not out-of-sequence according to the protocol rules. This default implementation does nothing; programmers might wish to override this method in case they need to react to this event.- Parameters:
inform- the received inform messagenextRequest- the Vector of ACLMessage objects to be sent at next round
-
handleInform
protected final void handleInform(ACLMessage inform)
This method is redefined to call the proper overloaded method- Overrides:
handleInformin classAchieveREInitiator- Parameters:
inform- the received inform message
-
handleAllResultNotifications
protected void handleAllResultNotifications(Vector resultNotifications, Vector nextRequests)
This method is called when all the result notification messages of the current round have been collected. By result notification message we intend here all theinform, failurereceived messages, which are not out-of-sequence according to the protocol rules. This default implementation does nothing; programmers might wish to override this method in case they need to react to this event by analysing all the messages in just one call.- Parameters:
resultNodifications- the Vector of ACLMessage object receivednextRequest- the Vector of ACLMessage objects to be sent at next round
-
handleAllResultNotifications
protected final void handleAllResultNotifications(Vector resultNotifications)
This method is redefined to call the proper overloaded method- Overrides:
handleAllResultNotificationsin classAchieveREInitiator
-
registerHandleInform
public void registerHandleInform(Behaviour b)
This method allows to register a user definedBehaviourin the HANDLE_REFUSE 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 receivedinformACLMessage object from the datastore at theREPLY_KEYkey and the Vector of ACLMessage objects to be sent at next round at theALL_NEXT_REQUESTS_KEY.- Overrides:
registerHandleInformin classAchieveREInitiator- Parameters:
b- the Behaviour that will handle this state
-
registerHandleAllResultNotifications
public void registerHandleAllResultNotifications(Behaviour b)
This method allows to register a user definedBehaviourin the HANDLE_ALL_RESULT_NOTIFICATIONS 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 result notification, from the datastore at theALL_RESULT_NOTIFICATIONS_KEYkey and the Vector of ACLMessage objects to be sent at next round at theALL_NEXT_REQUESTS_KEY.- Overrides:
registerHandleAllResultNotificationsin classAchieveREInitiator- Parameters:
b- the Behaviour that will handle this state
-
isSessionTerminated
public static boolean isSessionTerminated(ACLMessage inform)
Check if the responder has closed the session just after sending thisinformmessage.
-
sendInitiations
protected void sendInitiations(Vector initiations)
Create and initialize the Sessions and sends the initiation messages
-
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
-
handleFailure
protected void handleFailure(ACLMessage failure)
This method is called every time afailuremessage 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
-
registerPrepareInitiations
protected void registerPrepareInitiations(Behaviour b)
Attach a behaviour to thePrepare-initiationsprotocol state.- Parameters:
b- The behaviour object to be executed in thePrepare-initiationsstate.
-
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
-
registerHandleFailure
public void registerHandleFailure(Behaviour b)
This method allows to register a user definedBehaviourin the HANDLE_FAILURE 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 thefailureACLMessage 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
-
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 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)
-
-