public class ContractNetInitiator extends Object implements Behavior, Protocol
An implementation of an initiator role 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 the call-for-proposals 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 call-for-proposals 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.
ContractNetResponder
,
FIPA Contract
Net Interaction Protocol SpecificationModifier and Type | Class and Description |
---|---|
static interface |
ContractNetInitiator.MessageAccess
An interface to access the messages handled by a contract net initiator.
|
Constructor and Description |
---|
ContractNetInitiator(BehaviorController controller)
Creates the contract-net initiator for the FIPA Contract Net Interaction Protocol.
|
ContractNetInitiator(BehaviorController controller,
ModifiableMessage cfp)
Creates the contract-net initiator for the FIPA Contract Net Interaction Protocol.
|
Modifier and Type | Method and Description |
---|---|
ProtocolIdentifier |
getIdentifier()
Returns the identifier of this identifiable object.
|
ContractNetInitiator.MessageAccess |
getMessageAccess()
Returns an interface to access the messages handled by this contract net
initiator.
|
void |
handleAllResponses(List<Message> responses,
List<ModifiableMessage> acceptances)
This method can be implemented in order to handle together all responses
(propose, refuse, not-understood) to the original call-for-proposals.
|
void |
handleAllResultNotifications(List<Message> resultNotifications)
This method can be implemented in order to handle together all result
notifications (inform, failure) to accepted proposals.
|
void |
handleFailure(Message failure)
This method can be implemented in order to handle failure messages that
are result notifications to accepted proposals.
|
void |
handleInform(Message inform)
This method can be implemented in order to handle inform messages that
are result notifications to accepted proposals.
|
void |
handleNotUnderstood(Message notUnderstood)
This method can be implemented in order to handle not-understood messages
that are responses to the original call-for-proposals.
|
void |
handleOutOfSequence(Message message)
This method can be implemented in order to handle messages that arrive
out-of-sequence of the underlying protocol.
|
void |
handlePropose(Message propose,
List<ModifiableMessage> acceptances)
This method can be implemented in order to handle propose messages that
are responses to the original call-for-proposals.
|
void |
handleRefuse(Message refuse)
This method can be implemented in order to handle refuse messages that
are responses to the original call-for-proposals.
|
boolean |
isFinished()
Indicates whether the behavior is finished or requires re-scheduling.
|
ModifiableMessage |
prepareCfp(ModifiableMessage cfp)
This method can be implemented in order to further prepare the
call-for-proposals message provided in the constructor.
|
void |
registerHandleAllResponses(Behavior behavior)
Registers a behavior to handle together all responses (including propose,
refuse, and not-understood) to the original call-for-proposals.
|
void |
registerHandleAllResultNotifications(Behavior behavior)
Registers a behavior to handle together all result notifications (inform,
failure) to acceptances of proposals.
|
void |
registerHandleFailure(Behavior behavior)
Registers a behavior to handle failure messages that are result
notifications to acceptances of proposals.
|
void |
registerHandleInform(Behavior behavior)
Registers a behavior to handle inform messages that are result
notifications to acceptances of proposals.
|
void |
registerHandleNotUnderstood(Behavior behavior)
Registers a behavior to handle not-understood messages that are responses
to the original call-for-proposals.
|
void |
registerHandleOutOfSequence(Behavior behavior)
Registers a behavior to handle messages that arrive out of sequence of
the underlying protocol.
|
void |
registerHandlePropose(Behavior behavior)
Registers a behavior to handle propose messages that are responses to the
original call-for-proposals.
|
void |
registerHandleRefuse(Behavior behavior)
Registers a behavior to handle refuse messages that are responses to the
original call-for-proposals.
|
void |
registerPrepareCfp(Behavior behavior)
Registers a behavior to prepare call-for-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 ContractNetInitiator(BehaviorController controller)
controller
- the controller of this behaviorpublic ContractNetInitiator(BehaviorController controller, ModifiableMessage cfp)
controller
- the controller of this behaviorcfp
- an initial call-for-proposals 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 prepareCfp(ModifiableMessage cfp)
This method can be implemented in order to further prepare the call-for-proposals 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.
cfp
- the call-for-proposals message provided in the constructorpublic void handlePropose(Message propose, List<ModifiableMessage> acceptances)
This method can be implemented in order to handle propose messages that are responses to the original call-for-proposals.
The method gets access to a list of all acceptances of proposals that will be sent to the respective responders. Actually, these messages can be either an accept-proposal or a reject-proposal message. Agents may add further messages and modify or remove existing ones.
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.
propose
- the propose message to be handledacceptances
- modifiable list of all acceptances of proposals that will be
sent to the respective responderspublic void handleRefuse(Message refuse)
This method can be implemented in order to handle refuse messages that are responses to the original call-for-proposals.
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 call-for-proposals.
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, List<ModifiableMessage> acceptances)
This method can be implemented in order to handle together all responses (propose, refuse, not-understood) to the original call-for-proposals.
The method gets access to a list of all acceptances of proposals that will be sent to the respective responders. Actually, these messages can be either an accept-proposal or a reject-proposal message. Agents may add further messages and modify or remove existing ones.
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
- an unmodifiable list of all responses to be handledacceptances
- modifiable list of all acceptances of proposals that will be
sent to the respective responderspublic void handleInform(Message inform)
This method can be implemented in order to handle inform messages that are result notifications to accepted proposals.
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 result notifications to accepted proposals.
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) to accepted proposals.
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
- an unmodifiable list of all result notifications to be handledpublic void registerPrepareCfp(Behavior behavior)
Registers a behavior to prepare call-for-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 prepare call-for-proposal messagesgetMessageAccess()
,
ContractNetInitiator.MessageAccess.getCfp()
,
ContractNetInitiator.MessageAccess.setCfp(ModifiableMessage)
public void registerHandlePropose(Behavior behavior)
Registers a behavior to handle propose messages that are responses to the original call-for-proposals.
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 propose messagesgetMessageAccess()
,
ContractNetInitiator.MessageAccess.getMessage()
public void registerHandleRefuse(Behavior behavior)
Registers a behavior to handle refuse messages that are responses to the original call-for-proposals.
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()
,
ContractNetInitiator.MessageAccess.getMessage()
public void registerHandleNotUnderstood(Behavior behavior)
Registers a behavior to handle not-understood messages that are responses to the original call-for-proposals.
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()
,
ContractNetInitiator.MessageAccess.getMessage()
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()
,
ContractNetInitiator.MessageAccess.getMessage()
public void registerHandleAllResponses(Behavior behavior)
Registers a behavior to handle together all responses (including propose, refuse, and not-understood) to the original call-for-proposals.
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()
,
ContractNetInitiator.MessageAccess.getAllResponses()
,
ContractNetInitiator.MessageAccess.getAllAcceptances()
public void registerHandleInform(Behavior behavior)
Registers a behavior to handle inform messages that are result notifications to acceptances of proposals.
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()
,
ContractNetInitiator.MessageAccess.getMessage()
public void registerHandleFailure(Behavior behavior)
Registers a behavior to handle failure messages that are result notifications to acceptances of proposals.
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()
,
ContractNetInitiator.MessageAccess.getMessage()
public void registerHandleAllResultNotifications(Behavior behavior)
Registers a behavior to handle together all result notifications (inform, failure) to acceptances of proposals.
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()
,
ContractNetInitiator.MessageAccess.getAllResultNotifications()
public ContractNetInitiator.MessageAccess getMessageAccess()
Copyright © Aimpulse Intelligent Systems GmbH
All rights reserved.