public class RequestResponder extends Object
An implementation of a responder in the FIPA Request Interaction Protocol. The preparation of response messages and result notification can be implemented by means of call-back methods.
The implementation of the responder 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 handling requests and preparing 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.
RequestInitiator
,
FIPA Request
Interaction Protocol SpecificationModifier and Type | Class and Description |
---|---|
static interface |
RequestResponder.MessageAccess
An interface to access the messages handled by a request responder.
|
Constructor and Description |
---|
RequestResponder(BehaviorController controller)
Creates the request responder with the default message pattern for the
FIPA Request Interaction protocol.
|
RequestResponder(BehaviorController controller,
MessagePattern pattern)
Creates the request responder with an individual message pattern.
|
Modifier and Type | Method and Description |
---|---|
ProtocolIdentifier |
getIdentifier()
Returns the identifier of this identifiable object.
|
RequestResponder.MessageAccess |
getMessageAccess()
Returns an interface to access the messages handled by this request
responder.
|
ModifiableMessage |
handleRequest(Message request)
This method can be implemented in order to handle incoming requests.
|
boolean |
isFinished()
Indicates whether the behavior is finished or requires re-scheduling.
|
ModifiableMessage |
prepareResultNotification(Message request,
Message response)
This method can be implemented in order to prepare result notifications
for incoming requests.
|
void |
registerHandleRequest(Behavior behavior)
Registers a behavior to handle incoming requests.
|
void |
registerPrepareResultNotification(Behavior behavior)
Registers a behavior to prepare result notifications for incoming
requests.
|
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 RequestResponder(BehaviorController controller)
controller
- the controller of this behaviorpublic RequestResponder(BehaviorController controller, MessagePattern pattern)
controller
- the controller of this behaviorpattern
- the individual message patternpublic ProtocolIdentifier getIdentifier()
Identifiable
public ModifiableMessage handleRequest(Message request) throws NotUnderstoodException, RefuseException
This method can be implemented in order to handle incoming requests. The
method returns the response to be sent back to the sender of the original
request (or the reply-tos, respectively). If null
is
returned, no message is sent (the protocol allows to send only a result
notification without preceding response). Returning null
is
also the default behavior if the method is not implemented by inheriting
behaviors.
If the request is not understood or to be refused, it suffices to throw respective exceptions. The behavior then creates respective response messages automatically.
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 original requestNotUnderstoodException
- if the request is not understoodRefuseException
- if the request is to be refusedpublic ModifiableMessage prepareResultNotification(Message request, Message response) throws FailureException
This method can be implemented in order to prepare result notifications
for incoming requests. The method is called with the original request and
the response that has already been sent (null if not sent). The method
returns the result notification. If null
is returned (the
default behavior if the method is not implemented), no message is sent.
This method is only called if no not-understood or refuse message has been sent as a response before.
If a failure arises, it suffices to throw a failure exception. The behavior then creates respective message automatically.
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 original requestresponse
- the response to the original requestFailureException
- if a failure occurs while preparing the result notificationpublic void registerHandleRequest(Behavior behavior)
Registers a behavior to handle incoming requests.
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 incoming requestsgetMessageAccess()
public RequestResponder.MessageAccess getMessageAccess()
public boolean isFinished()
Behavior
isFinished
in interface Behavior
true
if the behavior is finished,
false
otherwisepublic void run()
Behavior
public EventPattern waitingFor()
Behavior
waitingFor
in interface Behavior
null
if the behavior is finishedpublic 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 void registerPrepareResultNotification(Behavior behavior)
Registers a behavior to prepare result notifications for incoming requests.
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 result notifications for incoming
requestsgetMessageAccess()
Copyright © Aimpulse Intelligent Systems GmbH
All rights reserved.