Subject: Re: [jade-develop] How do I block all subsequent behaviours whilst my agent receives anumber of incoming messages?
From: James Cole (james@cs.keele.ac.uk)
Date: Tue Mar 18 2003 - 14:53:34 MET
Hi Steve,
There seem to be two issues here.
1.
Wait until all 8 messages have been received.
All my agents have a thread where agent actions are initiated. This thread loops continually, and, being state controlled, will branch when certain criteria are fulfilled.
This could work well for you. When a message arrives, it could increment a variable. This variable will eventually reach a point where it equals the desired number of messages. The loop, which will be testing for this (e.g. messagesReceived == numberOfMessages) could initiate subsequent operations.
Inner class of MyAgent:
public class AgentLoop extends Thread{
public boolean FINISHED = false;
private MyAgent myAgent;
AgentLoop(){
myAgent = getReference();
start();
}
public void run(){
while(!FINISHED){
if(messagesReceived == numberOfMessages){
//initiate operations here... add behaviours etc...
}
}
}
}
2.
How to implement a more effective and elegant receive behaviour.
I'm not sure if this is good JADE but I create a ReceiveBehaviour that I add in setup():
class ReceiveBehaviour extends SimpleBehaviour{
MyAgent myAgent;
ReceiveBehaviour(MyAgent myAgent){
super(myAgent);
this.myAgent = myAgent;
}
public boolean done(){
return false;
}
public void action(){
ACLMessage msg = myAgent.receive();
if (msg == null){
block();
}
else{
switch (msg.getPerformative()){
case ACLMessage.AGREE:
if(msg.getContent().equals("WHATEVER")){
myAgent.someHandlingMethod(msg);
break;
.......
}
}
}
}
It will receive all messages and filters them according to the message performative.
This seems to be quite a good solution, can anyone identify any downsides?
James
----- Original Message -----
From: Steve
To: jade-develop@sharon.cselt.it
Sent: Tuesday, March 18, 2003 1:06 PM
Subject: [jade-develop] How do I block all subsequent behaviours whilst my agent receives anumber of incoming messages?
Hi Jaders
Im trying to understand agent behaviours and have come across a problem...
I send about 8 messages to an agent. It is vital that the agent receive all 8 messages before it does anything else. I need a way of blocking all subsequent behaviours until all messages have arrived and their content data stored. Is there an elegant way of doing this? So far I call my receiver behaviour (SimpleBehaviour()) 8 times. It works but I am sure this is not the best approach.
Any help would be much appreciated
PS. Many thanks to James and David for the previous help
Steve.
------------------------------------------------------------------------------
_______________________________________________
jade-develop mailing list
jade-develop@sharon.cselt.it
http://sharon.cselt.it/mailman/listinfo/jade-develop
UNSUBSCRIBE INSTRUCTIONS AT http://jade.cselt.it/mailing.htm#unsubscribe
----- Original Message -----From: SteveSent: Tuesday, March 18, 2003 1:06 PMSubject: [jade-develop] How do I block all subsequent behaviours whilst my agent receives anumber of incoming messages?Hi Jaders
Im trying to understand agent behaviours and have come across a problem...
I send about 8 messages to an agent. It is vital that the agent receive all 8 messages before it does anything else. I need a way of blocking all subsequent behaviours until all messages have arrived and their content data stored. Is there an elegant way of doing this? So far I call my receiver behaviour (SimpleBehaviour()) 8 times. It works but I am sure this is not the best approach.
Any help would be much appreciated
PS. Many thanks to James and David for the previous help
Steve.
_______________________________________________
jade-develop mailing list
jade-develop@sharon.cselt.it
http://sharon.cselt.it/mailman/listinfo/jade-develop
UNSUBSCRIBE INSTRUCTIONS AT http://jade.cselt.it/mailing.htm#unsubscribe
_______________________________________________
jade-develop mailing list
jade-develop@sharon.cselt.it
http://sharon.cselt.it/mailman/listinfo/jade-develop
UNSUBSCRIBE INSTRUCTIONS AT http://jade.cselt.it/mailing.htm#unsubscribe
This archive was generated by hypermail 2a22 : Tue Mar 18 2003 - 15:24:34 MET