Re: [jade-develop] How do I block all subsequent behaviours whilst my agent receives anumber of incoming messages?


Subject: Re: [jade-develop] How do I block all subsequent behaviours whilst my agent receives anumber of incoming messages?
From: Giovanni Rimassa (rimassa@ce.unipr.it)
Date: Tue Mar 18 2003 - 16:22:09 MET


James Cole wrote:

> 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?
>
>
>
It is so good that it is already in JADE: see
jade.core.behaviours.ReceiverBehaviour.java
The only difference with respect to your example is that, being in the
JADE package, the ReceiverBehaviour class
cannot depend on specific message content. Instead, a Future
idiom/pattern is used to allow sharing the received ACLMessage
across behaviours, so that you can have a ReceiverBehaviour to fetch the
message and an application specific behaviour to process
it.
If you read the Javadoc for the class, you will see an example of how
this is handled, also including timeouts.

So, no, I don't see particular downsides in your solutions. You could
achieve a looser coupling between message handling and content
processing, i.e.
avoiding to hardcode the someHandling() method name and signature in the
action() code. There are several ways to achieve this (Java Dynamic Proxies
being perhaps the coolest), but it's not always necessary.

Hope this helps,

    Giovanni

> James
>
> ----- Original Message -----
>
> * From:* Steve <mailto:steven_george@hotmail.com>
>
> * To:* jade-develop@sharon.cselt.it
> <mailto: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
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>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
>

-- 
	         Giovanni Rimassa
     Dipartimento di Ingegneria dell'Informazione
         Universita` di Parma - Parma (ITALY)
    Phone: +39 0521 905712 -  Fax: +39 0521 905723

_______________________________________________ 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 - 16:20:52 MET