public class ContractNetResponder extends Object implements Behavior, Protocol
An implementation of a responder in the FIPA Contract Net Interaction Protocol. The contract net enables agents to negotiate about a task to be performed. A more detailed description of the protocol flow can be found in the Aimpulse Spectrum documentation and in the FIPA specification.
The preparation of proposal 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 call-for-proposals 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.
ContractNetInitiator
,
FIPA Contract
Net Interaction Protocol SpecificationModifier and Type | Class and Description |
---|---|
static interface |
ContractNetResponder.MessageAccess
An interface to access the messages handled by a contract net responder.
|
Constructor and Description |
---|
ContractNetResponder(BehaviorController controller)
Creates the contract-net responder with the default message pattern for
the FIPA Contract Net Interaction protocol.
|
ContractNetResponder(BehaviorController controller,
MessagePattern pattern)
Creates the contract-net responder with an individual message pattern.
|
Modifier and Type | Method and Description |
---|---|
ProtocolIdentifier |
getIdentifier()
Returns the identifier of this identifiable object.
|
ContractNetResponder.MessageAccess |
getMessageAccess()
Returns an interface to access the messages handled by this contract net
responder.
|
ModifiableMessage |
handleAcceptProposal(Message cfp,
Message propose,
Message accept)
This method can be implemented in order to prepare result notifications
after the initiator has accepted a previous proposal.
|
ModifiableMessage |
handleCfp(Message cfp)
This method can be implemented in order to handle incoming
call-for-proposals.
|
void |
handleRejectProposal(Message cfp,
Message propose,
Message reject)
This method can be implemented in order to handle rejections by the
initiator.
|
boolean |
isFinished()
Indicates whether the behavior is finished or requires re-scheduling.
|
void |
registerHandleAcceptProposal(Behavior behavior)
Registers a behavior to handle incoming accept-proposal messages by
creating a result notification.
|
void |
registerHandleCfp(Behavior behavior)
Registers a behavior to handle incoming call-for-proposal messages by
creating a propose message.
|
void |
registerHandleRejectProposal(Behavior behavior)
Registers a behavior to handle incoming reject-proposal 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 ContractNetResponder(BehaviorController controller)
controller
- the controller of this behaviorpublic ContractNetResponder(BehaviorController controller, MessagePattern pattern)
controller
- the controller of this behaviorpattern
- the individual message patternpublic 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 handleCfp(Message cfp) throws RefuseException, NotUnderstoodException
This method can be implemented in order to handle incoming
call-for-proposals. The method returns the response to be sent back to
the sender of the original call-for-proposal (or the reply-tos,
respectively). If null
is returned, no message is sent (note
that it is usually good style to send at least a refuse message because
the initiator might wait for a response). Returning null
is
also the default behavior if the method is not implemented by inheriting
behaviors.
If the call-for-proposal 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.
cfp
- the original call-for-proposalNotUnderstoodException
- if the call-for-proposal is not understoodRefuseException
- if the call-for-proposal is to be refusedpublic ModifiableMessage handleAcceptProposal(Message cfp, Message propose, Message accept) throws FailureException
This method can be implemented in order to prepare result notifications
after the initiator has accepted a previous proposal. The method is
called with the original call-for-proposals by the initiator, the
proposal sent by the responder, and the acceptance of the initiator. The
method returns the result notification. If null
is returned
(the default behavior if the method is not implemented), no message is
sent (note that it is usually good style to send at least a failure
message because the initiator waits for a response).
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.
cfp
- the original call-for-proposalpropose
- the proposal sent to the initiatoraccept
- the acceptance of the initiatorFailureException
- if a failure occurs while preparing the result notificationpublic void handleRejectProposal(Message cfp, Message propose, Message reject)
This method can be implemented in order to handle rejections by the initiator. The method is called with the original call-for-proposals by the initiator, the proposal sent by the responder, and the rejection of the initiator.
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.
cfp
- the original call-for-proposalpropose
- the proposal sent to the initiatorreject
- the rejection of the initiatorpublic void registerHandleCfp(Behavior behavior)
Registers a behavior to handle incoming call-for-proposal messages by creating a propose message.
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 call-for-proposal messagesgetMessageAccess()
,
ContractNetResponder.MessageAccess.getCfp()
,
ContractNetResponder.MessageAccess.setProposal(ModifiableMessage)
public void registerHandleAcceptProposal(Behavior behavior)
Registers a behavior to handle incoming accept-proposal messages by creating a result notification.
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 accept-proposal messagesgetMessageAccess()
,
ContractNetResponder.MessageAccess.getCfp()
,
ContractNetResponder.MessageAccess.getProposal()
,
ContractNetResponder.MessageAccess.getAcceptance()
,
ContractNetResponder.MessageAccess.setResultNotification(ModifiableMessage)
public void registerHandleRejectProposal(Behavior behavior)
Registers a behavior to handle incoming reject-proposal 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 handle incoming reject-proposal messagesgetMessageAccess()
,
ContractNetResponder.MessageAccess.getCfp()
,
ContractNetResponder.MessageAccess.getProposal()
,
ContractNetResponder.MessageAccess.getAcceptance()
public ContractNetResponder.MessageAccess getMessageAccess()
Copyright © Aimpulse Intelligent Systems GmbH
All rights reserved.