Subject: Problem with ReceiverBehaviour
From: David Grimshaw - Professor Emeritus (dgrimsha@scs.ryerson.ca)
Date: Tue Sep 03 2002 - 00:47:07 MET DST
Hello Jaders,
I have been playing around with jade.core.behaviours.ReceiveBehaviour but
I cannot get it to work. I tried this simple code:
package examples.simpleReceiver;
import jade.core.Agent;
import jade.core.behaviours.CyclicBehaviour;
import jade.core.behaviours.ReceiverBehaviour;
import jade.lang.acl.ACLMessage;
public class SimpleReceiverAgent extends Agent {
ReceiverBehaviour.Handle h;
ReceiverBehaviour rb;
public void setup() {
rb = new ReceiverBehaviour(this, -1, null);
addBehaviour(rb);
addBehaviour(new CyclicBehaviour(this) {
public void action() {
try {
ACLMessage incoming = rb.getMessage();
System.out.println("The messaga content is: " +
incoming.getContent());
rb.reset();
} catch(ReceiverBehaviour.NotYetReady e) {
System.out.println(e);
} catch(ReceiverBehaviour.TimedOut eo) {
System.out.println("timed out");
}
block();
} // end action()
});
} // end setup()
} // end SimpleReceive
I send this receiver a message from DummyAgent. The problem seems to be
with reset(). With the code as shown (with reset()). The message gets
printed once, and thereafter, the NotYetReady exception is thrown every
time I attempt to send a new message from DummyAgent.
If I comment out rb.reset() it appears to be ok. Every time I send a
message, its content is printed out. But .... . If I change the content of
the message, the old content is printed out. (Which is the correct result
I thhink.)
So how do I get the ReceiverBehaviour to accept a new message?
Any help would be appreciated.
Dave
============================================================
David Grimshaw
School of Computer Science
Ryerson University
350 Victoria Street
Toronto, Ontario, M5B 2K3, Canada
http://www.ryerson.ca/~dgrimsha
============================================================
This archive was generated by hypermail 2a22 : Tue Sep 03 2002 - 00:45:03 MET DST