public class SimpleAchieveREInitiator extends SimpleBehaviour
FIPA has already specified a number of these interaction protocols, like FIPA-Request, FIPA-query, FIPA-Request-When, FIPA-recruiting, FIPA-brokering, FIPA-subscribe, that allows the initiator to verify if the expected rational effect of a single communicative act has been achieved.
The structure of these protocols is equal. The initiator sends a message (in general it performs a communicative act).
The responder can then reply by sending a not-understood
, or a
refuse
to
achieve the rational effect of the communicative act, or also
an agree
message to communicate the agreement to perform
(possibly in the future) the communicative act. This first category
of reply messages has been here identified as a response.
The responder performs the action and, finally, must respond with an
inform
of the result of the action (eventually just that the
action has been done) or with a failure
if anything went wrong.
This second category of reply messages has been here identified as a
result notification.
Notice that we have extended the protocol to make optional the transmission of the agree message. Infact, in most cases performing the action takes so short time that sending the agree message is just an useless and uneffective overhead; in such cases, the agree to perform the communicative act is subsumed by the reception of the following message in the protocol.
Read carefully the section of the JADE programmer's guide that describes the usage of this class.
Known bugs:
The handler handleAllResponses
is not called if the
agree
message is skipped and the inform
message
is received instead.
SimpleAchieveREResponder
,
AchieveREInitiator
,
AchieveREResponder
,
Serialized FormModifier and Type | Field and Description |
---|---|
java.lang.String |
ALL_RESPONSES_KEY
key to retrive all the responses received.
|
java.lang.String |
ALL_RESULT_NOTIFICATIONS_KEY
key to retrive the result notification received.
|
java.lang.String |
REQUEST_KEY
key to retrive from the datastore the ACLMessage passed in the constructor
|
java.lang.String |
REQUEST_SENT_KEY
key to retrive from the datastore the ACLMessage that has been sent.
|
java.lang.String |
SECOND_REPLY_KEY
key to retrive the second reply received.
|
Constructor and Description |
---|
SimpleAchieveREInitiator(Agent a,
ACLMessage msg)
Construct for the class by creating a new empty DataStore
|
SimpleAchieveREInitiator(Agent a,
ACLMessage msg,
DataStore store)
Constructs a
SimpleAchieveREInitiator behaviour |
Modifier and Type | Method and Description |
---|---|
void |
action()
Runs the behaviour.
|
boolean |
done()
Check if this behaviour is done.
|
protected void |
handleAgree(ACLMessage msg)
This method is called every time an
agree
message is received, which is not out-of-sequence according
to the protocol rules. |
protected void |
handleAllResponses(java.util.Vector msgs)
This method is called when all the responses have been
collected or when the timeout is expired.
|
protected void |
handleAllResultNotifications(java.util.Vector msgs)
This method is called when all the result notification messages
have been collected.
|
protected void |
handleFailure(ACLMessage msg)
This method is called every time a
failure
message is received, which is not out-of-sequence according
to the protocol rules. |
protected void |
handleInform(ACLMessage msg)
This method is called every time a
inform
message is received, which is not out-of-sequence according
to the protocol rules. |
protected void |
handleNotUnderstood(ACLMessage msg)
This method is called every time a
not-understood
message is received, which is not out-of-sequence according
to the protocol rules. |
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.
|
protected void |
handleRefuse(ACLMessage msg)
This method is called every time a
refuse
message is received, which is not out-of-sequence according
to the protocol rules. |
void |
onStart()
This method is just an empty placeholders for subclasses.
|
protected ACLMessage |
prepareRequest(ACLMessage msg)
This method must return the ACLMessage to be sent.
|
void |
reset()
This method resets this behaviour so that it restarts from the initial
state of the protocol with a null message.
|
void |
reset(ACLMessage msg)
This method resets this behaviour so that it restarts the protocol with
another request message.
|
block, block, getAgent, getBehaviourName, getDataStore, getParent, isRunnable, onEnd, restart, root, setAgent, setBehaviourName, setDataStore
public final java.lang.String REQUEST_KEY
public final java.lang.String REQUEST_SENT_KEY
public final java.lang.String SECOND_REPLY_KEY
public final java.lang.String ALL_RESPONSES_KEY
public final java.lang.String ALL_RESULT_NOTIFICATIONS_KEY
public SimpleAchieveREInitiator(Agent a, ACLMessage msg)
public SimpleAchieveREInitiator(Agent a, ACLMessage msg, DataStore store)
SimpleAchieveREInitiator
behavioura
- The agent performing the protocolmsg
- The message that must be used to initiate the protocol.
Notice that in this simple implementation, the
prepareMessage
method returns a single message.s
- The DataStore
that will be used by this
SimpleAchieveREInitiator
public final void action()
Behaviour
Behaviour
subclasses to perform ordinary behaviour
duty. An agent schedules its behaviours calling their
action()
method; since all the behaviours belonging
to the same agent are scheduled cooperatively, this method
must not enter in an endless loop and should return as
soon as possible to preserve agent responsiveness. To split a
long and slow task into smaller section, recursive behaviour
aggregation may be used.action
in class Behaviour
CompositeBehaviour
public void onStart()
Behaviour
Behaviour
.public boolean done()
Behaviour
Behaviour
still need to be
run or it has completed its task. Concrete behaviours must
implement this method to return their completion state. Finished
behaviours are removed from the scheduling queue, while others
are kept within to be run again when their turn comes again.protected ACLMessage prepareRequest(ACLMessage msg)
msg
- the ACLMessage object passed in the constructor.protected void handleAgree(ACLMessage msg)
agree
message 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.agree
- the received agree messageprotected void handleRefuse(ACLMessage msg)
refuse
message 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.refuse
- the received refuse messageprotected void handleNotUnderstood(ACLMessage msg)
not-understood
message 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.notUnderstood
- the received not-understood messageprotected void handleInform(ACLMessage msg)
inform
message 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.inform
- the received inform messageprotected void handleFailure(ACLMessage msg)
failure
message 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.failure
- the received failure messageprotected void handleOutOfSequence(ACLMessage msg)
msg
- the received messageprotected void handleAllResponses(java.util.Vector msgs)
agree, not-understood,
refuse
received 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.responses
- the Vector of ACLMessage objects that have been receivedprotected void handleAllResultNotifications(java.util.Vector msgs)
inform,
failure
received 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.resultNodifications
- the Vector of ACLMessage object receivedpublic void reset()
reset
in class SimpleBehaviour
public void reset(ACLMessage msg)
msg
- updates message to be sent.