public class RequestInitiator extends Object implements Behavior, Protocol
An implementation of an initiator in the FIPA Request Interaction Protocol. The preparation of the request message and handling the responses and result notifications can be implemented by means of call-back methods.
The implementation of the initiator internally employs a finite-state machine behavior. Hence, it is also possible to register (arbitrarily complex) behaviors (which may themselves be finite-state machine behaviors) for preparing requests and handling responses and result notifications.
If the call-back methods are employed, all relevant messages are provided by the method parameters. If behaviors are registered, there exists an interface that provides access to the respective messages. Note that its methods can only be called if the respective behavior is currently executed. Otherwise, an illegal state exception occurs.
RequestResponder
,
FIPA Request
Interaction Protocol SpecificationModifier and Type | Class and Description |
---|---|
static interface |
RequestInitiator.MessageAccess
An interface to access the messages handled by a request initiator.
|
Constructor and Description |
---|
RequestInitiator(BehaviorController controller)
Creates the request initiator for the FIPA Request Interaction Protocol.
|
RequestInitiator(BehaviorController controller,
ModifiableMessage request)
Creates the request initiator for the FIPA Request Interaction Protocol.
|
Modifier and Type | Method and Description |
---|---|
ProtocolIdentifier |
getIdentifier()
Returns the identifier of this identifiable object.
|
RequestInitiator.MessageAccess |
getMessageAccess()
Returns an interface to access the messages handled by this request
initiator.
|
void |
handleAgree(Message agree)
This method can be implemented in order to handle agree messages that are
responses to the original request.
|
void |
handleAllResponses(List<Message> responses)
This method can be implemented in order to handle together all responses
(agree, refuse, not-understood) that are responses to the original
request.
|
void |
handleAllResultNotifications(List<Message> resultNotifications)
This method can be implemented in order to handle together all result
notifications (inform, failure) that are responses to the original
request.
|
void |
handleFailure(Message failure)
This method can be implemented in order to handle failure messages that
are responses to the original request.
|
void |
handleInform(Message inform)
This method can be implemented in order to handle inform messages that
are responses to the original request.
|
void |
handleNotUnderstood(Message notUnderstood)
This method can be implemented in order to handle not-understood messages
that are responses to the original request.
|
void |
handleOutOfSequence(Message message)
This method can be implemented in order to handle messages that arrive
out-of-sequence of the underlying protocol.
|
void |
handleRefuse(Message refuse)
This method can be implemented in order to handle refuse messages that
are responses to the original request.
|
boolean |
isFinished()
Indicates whether the behavior is finished or requires re-scheduling.
|
ModifiableMessage |
prepareRequest(ModifiableMessage request)
This method can be implemented in order to further prepare the request
message provided in the constructor.
|
void |
registerHandleAgree(Behavior behavior)
Registers a behavior to handle agree messages that are responses to the
original request.
|
void |
registerHandleAllResponses(Behavior behavior)
Registers a behavior to handle together all messages (agree, refuse,
not-understood) that are responses to the original request.
|
void |
registerHandleAllResultNotifications(Behavior behavior)
Registers a behavior to handle together all result notifications (inform,
failure) that are responses to the original request.
|
void |
registerHandleFailure(Behavior behavior)
Registers a behavior to handle failure messages that are responses to the
original request.
|
void |
registerHandleInform(Behavior behavior)
Registers a behavior to handle inform messages that are responses to the
original request.
|
void |
registerHandleNotUnderstood(Behavior behavior)
Registers a behavior to handle not-understood messages that are responses
to the original request.
|
void |
registerHandleOutOfSequence(Behavior behavior)
Registers a behavior to handle messages that arrive out of sequence of
the underlying protocol.
|
void |
registerHandleRefuse(Behavior behavior)
Registers a behavior to handle refuse messages that are responses to the
original request.
|
void |
registerPrepareRequest(Behavior behavior)
Registers a behavior to prepare request messages.
|
Result |
result()
Returns the result of the behavior.
|
void |
run()
The implementation of the actual behavior.
|
EventPattern |
waitingFor()
Defines the event pattern for re-scheduling.
|
public RequestInitiator(BehaviorController controller)
controller
- the controller of this behaviorpublic RequestInitiator(BehaviorController controller, ModifiableMessage request)
controller
- the controller of this behaviorrequest
- an initial request messagepublic ProtocolIdentifier getIdentifier()
Identifiable
getIdentifier
in interface Identifiable<ProtocolIdentifier>
public EventPattern waitingFor()
Behavior
waitingFor
in interface Behavior
null
if the behavior is finishedpublic void run()
Behavior
public boolean isFinished()
Behavior
isFinished
in interface Behavior
true
if the behavior is finished,
false
otherwisepublic Result result()
Behavior
Returns the result of the behavior.
Note that the result is only available if the behavior is finished. Otherwise, an illegal-state exception may be thrown.
public ModifiableMessage prepareRequest(ModifiableMessage request)
This method can be implemented in order to further prepare the request message provided in the constructor.
As an alternative to this call-back method, it is also possible to register a call-back behavior. This is particularly useful whenever more complex tasks are required (e.g., querying another agent). Please note that this call-back method will no longer be executed if a respective call-back behavior is registered.
request
- the request message provided in the constructorpublic void handleAgree(Message agree)
This method can be implemented in order to handle agree messages that are responses to the original request.
As an alternative to this call-back method, it is also possible to register a call-back behavior . This is particularly useful whenever more complex tasks are required (e.g., querying another agent). Please note that this call-back method will no longer be executed if a respective call-back behavior is registered.
agree
- the agree message to be handledpublic void handleRefuse(Message refuse)
This method can be implemented in order to handle refuse messages that are responses to the original request.
As an alternative to this call-back method, it is also possible to register a call-back behavior. This is particularly useful whenever more complex tasks are required (e.g., querying another agent). Please note that this call-back method will no longer be executed if a respective call-back behavior is registered.
refuse
- the refuse message to be handledpublic void handleNotUnderstood(Message notUnderstood)
This method can be implemented in order to handle not-understood messages that are responses to the original request.
As an alternative to this call-back method, it is also possible to register a call-back behavior. This is particularly useful whenever more complex tasks are required (e.g., querying another agent). Please note that this call-back method will no longer be executed if a respective call-back behavior is registered.
notUnderstood
- the not-understood message to be handledpublic void handleOutOfSequence(Message message)
This method can be implemented in order to handle messages that arrive out-of-sequence of the underlying protocol.
As an alternative to this call-back method, it is also possible to register a call-back behavior. This is particularly useful whenever more complex tasks are required (e.g., querying another agent). Please note that this call-back method will no longer be executed if a respective call-back behavior is registered.
message
- the out-of-sequence message to be handledpublic void handleAllResponses(List<Message> responses)
This method can be implemented in order to handle together all responses (agree, refuse, not-understood) that are responses to the original request.
As an alternative to this call-back method, it is also possible to register a call-back behavior. This is particularly useful whenever more complex tasks are required (e.g., querying another agent). Please note that this call-back method will no longer be executed if a respective call-back behavior is registered.
responses
- all responses to be handledpublic void handleInform(Message inform)
This method can be implemented in order to handle inform messages that are responses to the original request.
As an alternative to this call-back method, it is also possible to register a call-back behavior. This is particularly useful whenever more complex tasks are required (e.g., querying another agent). Please note that this call-back method will no longer be executed if a respective call-back behavior is registered.
inform
- the inform message to be handledpublic void handleFailure(Message failure)
This method can be implemented in order to handle failure messages that are responses to the original request.
As an alternative to this call-back method, it is also possible to register a call-back behavior. This is particularly useful whenever more complex tasks are required (e.g., querying another agent). Please note that this call-back method will no longer be executed if a respective call-back behavior is registered.
failure
- the failure message to be handledpublic void handleAllResultNotifications(List<Message> resultNotifications)
This method can be implemented in order to handle together all result notifications (inform, failure) that are responses to the original request.
As an alternative to this call-back method, it is also possible to register a call-back behavior. This is particularly useful whenever more complex tasks are required (e.g., querying another agent). Please note that this call-back method will no longer be executed if a respective call-back behavior is registered.
resultNotifications
- all result notifications to be handledpublic void registerPrepareRequest(Behavior behavior)
Registers a behavior to prepare request messages.
As an alternative to this call-back behavior, it is also possible to simply implement a call-back method. This is particularly convenient whenever only less complex tasks are required that can be solved in one method. Please note that the call-back method will no longer be executed if this call-back behavior is registered.
behavior
- a behavior to prepare request messagesgetMessageAccess()
public void registerHandleAgree(Behavior behavior)
Registers a behavior to handle agree messages that are responses to the original request.
As an alternative to this call-back behavior, it is also possible to simply implement a call-back method. This is particularly convenient whenever only less complex tasks are required that can be solved in one method. Please note that the call-back method will no longer be executed if this call-back behavior is registered.
behavior
- a behavior to handle agree messagesgetMessageAccess()
public void registerHandleRefuse(Behavior behavior)
Registers a behavior to handle refuse messages that are responses to the original request.
As an alternative to this call-back behavior, it is also possible to simply implement a call-back method. This is particularly convenient whenever only less complex tasks are required that can be solved in one method. Please note that the call-back method will no longer be executed if this call-back behavior is registered.
behavior
- a behavior to handle refuse messagesgetMessageAccess()
public void registerHandleNotUnderstood(Behavior behavior)
Registers a behavior to handle not-understood messages that are responses to the original request.
As an alternative to this call-back behavior, it is also possible to simply implement a call-back method. This is particularly convenient whenever only less complex tasks are required that can be solved in one method. Please note that the call-back method will no longer be executed if this call-back behavior is registered.
behavior
- a behavior to handle not-understood messagesgetMessageAccess()
public void registerHandleOutOfSequence(Behavior behavior)
Registers a behavior to handle messages that arrive out of sequence of the underlying protocol.
As an alternative to this call-back behavior, it is also possible to simply implement a call-back method. This is particularly convenient whenever only less complex tasks are required that can be solved in one method. Please note that the call-back method will no longer be executed if this call-back behavior is registered.
behavior
- a behavior to handle out-of-sequence messagesgetMessageAccess()
public void registerHandleAllResponses(Behavior behavior)
Registers a behavior to handle together all messages (agree, refuse, not-understood) that are responses to the original request.
As an alternative to this call-back behavior, it is also possible to simply implement a call-back method. This is particularly convenient whenever only less complex tasks are required that can be solved in one method. Please note that the call-back method will no longer be executed if this call-back behavior is registered.
behavior
- a behavior to handle all responsesgetMessageAccess()
public void registerHandleInform(Behavior behavior)
Registers a behavior to handle inform messages that are responses to the original request.
As an alternative to this call-back behavior, it is also possible to simply implement a call-back method. This is particularly convenient whenever only less complex tasks are required that can be solved in one method. Please note that the call-back method will no longer be executed if this call-back behavior is registered.
behavior
- a behavior to handle inform messagesgetMessageAccess()
public void registerHandleFailure(Behavior behavior)
Registers a behavior to handle failure messages that are responses to the original request.
As an alternative to this call-back behavior, it is also possible to simply implement a call-back method. This is particularly convenient whenever only less complex tasks are required that can be solved in one method. Please note that the call-back method will no longer be executed if this call-back behavior is registered.
behavior
- a behavior to handle failure messagesgetMessageAccess()
public void registerHandleAllResultNotifications(Behavior behavior)
Registers a behavior to handle together all result notifications (inform, failure) that are responses to the original request.
As an alternative to this call-back behavior, it is also possible to simply implement a call-back method. This is particularly convenient whenever only less complex tasks are required that can be solved in one method. Please note that the call-back method will no longer be executed if this call-back behavior is registered.
behavior
- a behavior to handle all result notificationsgetMessageAccess()
public RequestInitiator.MessageAccess getMessageAccess()
Copyright © Aimpulse Intelligent Systems GmbH
All rights reserved.