|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--jade.core.behaviours.Behaviour
|
+--jade.core.behaviours.SimpleBehaviour
|
+--jade.proto.FipaContractNetInitiatorBehaviour
Behaviour class for fipa-contract-net
Initiator role. This abstract behaviour implements the
fipa-contract-net interaction protocol from the point
of view of the agent initiating the protocol, that is the agent that
sends the cfp message (Call for Proposal) to a
set of agents. In order to use correctly this behaviour, the
programmer should do the following:
FipaContractNetInitiatorBehaviour. This class must
implement four methods that are called by
FipaContractNetInitiatorBehaviour:
public Vector handleProposeMessages(Vector proposals)
to evaluate all the received proposals and to return a vector of
ACLMessage objects to be sent in response to the
proposals (return null to terminate the protocol).
public void handleOtherMessages(ACLMessage msg)
to handle all received messages different from propose
public Vector handleFinalMessages(Vector
messages) to evaluate the messages received in the last state
of the protocol, that is inform Done and
failure messages, and to return a Vector
of ACLMessages to be sent before terminating the
behaviour (return null to terminate the protocol).
public String createCfpContent(String cfpContent, AID receiver)
to return the cfp content for each receiver.
Agent.addBehaviour() method.
This behaviour can be hot reset, i.e. it is sensitive to the call of
the reset method and it is able to react in every state of the
protocol.
For this reason, this class can also be used to implement the FIPA-ITERATED-CONTRACT-NET PROTOCOL. In such a case, the following should be done:
cfp parameter,
that has to be passed both in the
constructor of this class and in the reset method,
should be set to the constant string "Fipa-Iterated-Contract-Net"
(actually this value increase the level of compatibility to the FIPA
specifications but it is not strictly necessary for the execution of
the behaviour);
handleProposeMessages
by calling the method reset(newcfp,newagentlist)
(eventually updating the cfp
message and the agent group); the vector of ACLMessages returned by the
handleProposeMessages method are still sent by this class,
so that the
previous iteration can be appropriately closed with the right number
of reject-proposal messages.
FipaContractNetResponderBehaviour, Serialized Form| Inner classes inherited from class jade.core.behaviours.Behaviour |
Behaviour.RunnableChangedEvent |
| Field Summary | |
protected ACLMessage |
cfpMsg
This is the cfpMsg sent in the first state of the protocol |
protected boolean |
finished
This boolean should be set to true in order to finish abnormally the protocol. |
| Fields inherited from class jade.core.behaviours.Behaviour |
myAgent,
myEvent,
NOTIFY_DOWN,
NOTIFY_UP,
parent |
| Constructor Summary | |
FipaContractNetInitiatorBehaviour(Agent a,
ACLMessage msg)
constructor of the behaviour. |
|
FipaContractNetInitiatorBehaviour(Agent a,
ACLMessage msg,
java.util.List responders)
constructor of the behaviour. |
|
| Method Summary | |
void |
action()
Action method of the behaviour. |
java.lang.String |
createCfpContent(java.lang.String cfpContent,
AID receiver)
Some content languages require that the name of the actor be included within the proposed action itself. |
boolean |
done()
This method is called by the JADE scheduler of agent behaviours and it should usually be ignored by application code. |
abstract java.util.Vector |
handleFinalMessages(java.util.Vector messages)
After having sent the messages returned by handleProposeMessages(),
the protocol waits for the expiration of the
maximum timeout specified in those messages
(reply-by parameter), or until all the answers are received. |
abstract void |
handleOtherMessages(ACLMessage msg)
This method must be implemented by all subclasses. |
abstract java.util.Vector |
handleProposeMessages(java.util.Vector proposals)
This method is called after all the propose messages
have been collected or after the timeout has expired. |
void |
reset()
This method resets this behaviour object so that it restarts from the initial state of the protocol. |
void |
reset(ACLMessage msg,
java.util.List responders)
|
| Methods inherited from class jade.core.behaviours.Behaviour |
block,
block,
handle,
isRunnable,
restart,
root |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Field Detail |
protected ACLMessage cfpMsg
protected boolean finished
| Constructor Detail |
public FipaContractNetInitiatorBehaviour(Agent a,
ACLMessage msg,
java.util.List responders)
a - is the current agent. The protected variable
Agent myAgent contains then the pointer to the agent class.
A common usage of this variable is to cast it to the actual type of
Agent class and use the methods of the extended class.
For instance
appointments = (AppointmentAgent)myAgent.getAppointments() msg - is the Call for Proposal message to be sent. If not set
already in the parameter, the protocol is set to the value
FIPA-Contract-Netresponders - is the group of agents to which the cfp must be sent
sintactically it is a List of AID
public FipaContractNetInitiatorBehaviour(Agent a,
ACLMessage msg)
FipaContractNetInitiatorBehaviour(Agent a, ACLMessage msg, List responders)| Method Detail |
public final void action()
public boolean done()
public abstract void handleOtherMessages(ACLMessage msg)
cfp message, this
method is called
everytime a new message arrives that is different from a
propose message. The method should react to this message
in an application-dependent way.
The class variable myAgent can be
used to send messages or, after casting, to execute other
application-dependent methods that belongs to the Agent
object.
msg - is the ACLMessage just arrivedpublic abstract java.util.Vector handleProposeMessages(java.util.Vector proposals)
propose messages
have been collected or after the timeout has expired.
By default an infinite timeout is used.
That default is overriden by
the reply-by parameter of the cfp message, if set.proposals - is the Vector that contains the received
propose ACL messages.Vector of ACLMessages to be sent in the
next phase of the protocol. Usually, these messages should be of
type accept-proposal or
reject-proposal. If null is returned instead,
then the protocol is prematurely terminated.
REMEMBER to set the
value of :in-reply-to parameter in all the returned
messages of this vector. This implementation of the protocol is
not able to set that value on your behalf because it implements a
one-to-many protocol and, unfortunately, each of the many might
use a different value of :in-reply-to.
NOTICE that all the returned messages are sent even if
the reset method is called. That allows the implementation
of the FIPA-Iterated-Contract-Net protocol. See at the top for
some usefull instructions.
public abstract java.util.Vector handleFinalMessages(java.util.Vector messages)
handleProposeMessages(),
the protocol waits for the expiration of the
maximum timeout specified in those messages
(reply-by parameter), or until all the answers are received.
If no reply-by parameter was set, an infinite timeout
is used, instead.
After this timeout, this method is called to react to all the received
messages. At the next state of the protocol, all the returned messages
are sent and then the protocol terminates.messages - is the Vector of ACL messages received so farVector of ACL messages to be sent in the next state of the
protocol. return null to terminate the protocol
REMEMBER to set the value of :in-reply-to parameter
in all the returned messages of this vector. This implementation of
the protocol is not able to set that value on your behalf because
it implements a one-to-many protocol and, unfortunately,
each of the many might
use a different value of :in-reply-to.
public java.lang.String createCfpContent(java.lang.String cfpContent,
AID receiver)
cfpContent argument without any modification at all.cfpContent - this is the content of the cfp message that was passed
in the constructor of the behaviourreceiver - this is the AID of the receiver agent to which this
content is destinatedpublic void reset()
Care must be taken to where this method is called because, in some intermediate states of the contract net protocol, restarting may cause unwanted side effects (e.g. not receiving some propose messages that refers to the previous cfp message).
public void reset(ACLMessage msg,
java.util.List responders)
msg - updates the cfp message to be sentresponders - updates the group of agents to which the cfp message should be sentreset()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||