jade.core.behaviours
Class ReceiverBehaviour
java.lang.Object
|
+--jade.core.behaviours.Behaviour
|
+--jade.core.behaviours.ReceiverBehaviour
- public final class ReceiverBehaviour
- extends Behaviour
Behaviour for receiving an ACL message. This class encapsulates a
receive() as an atomic operation. This behaviour
terminates when an ACL message is received. If no suitable message
is present, action() calls block() and
returns.
- Author:
- Giovanni Rimassa - Universita` di Parma
- See Also:
SenderBehaviour,
Agent.receive(),
ACLMessage, Serialized Form
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
ReceiverBehaviour
public ReceiverBehaviour(Agent a,
ACLMessage msg,
MessageTemplate mt)
- Receive a matching ACL message. This constructor creates a
ReceiverBehaviour object that ends as soon as an ACL
message matching a given MessageTemplate arrives.
- Parameters:
a - The agent this behaviour belongs to, and that will
receive() the message.msg - An ACL message where the received message will be
copied.mt - A Message template to match incoming messages against.
ReceiverBehaviour
public ReceiverBehaviour(Agent a,
ACLMessage msg)
- Receive any ACL message. This constructor creates a
ReceiverBehaviour object that ends as soon as any
ACL message is received.
- Parameters:
a - The agent this behaviour belongs to, and that will
receive() the message.msg - An ACL message where the received message will be
copied.
ReceiverBehaviour
public ReceiverBehaviour(Agent a,
ReceiverBehaviour.Handle h,
long millis)
- Receive any ACL message, waiting at most
millis
milliseconds.
When calling this constructor, a suitable Handle
must be created and passed to it. When this behaviour ends, some
other behaviour will try to get the ACL message out of the
handle, and an exception will be thrown in case of a time out.
The following example code explains this:
// ReceiverBehaviour creation, e.g. in agent setup() method
h = ReceiverBehaviour.newHandle(); // h is an agent instance variable
addBehaviour(new ReceiverBehaviour(this, h, 10000); // Wait 10 seconds
...
// Some other behaviour, later, tries to read the ACL message
// in its action() method
try {
ACLMessage msg = h.getMessage();
// OK. Message received within timeout.
}
catch(ReceiverBehaviour.TimedOut rbte) {
// Receive timed out
}
catch(ReceiverBehaviour.NotYetReady rbnyr) {
// Message not yet ready, but timeout still active
}
- Parameters:
a - The agent this behaviour belongs to.h - An Handle representing the message to receive.millis - The maximum amount of time to wait for the message,
in milliseconds.- See Also:
ReceiverBehaviour.Handle,
newHandle()
ReceiverBehaviour
public ReceiverBehaviour(Agent a,
ReceiverBehaviour.Handle h,
long millis,
MessageTemplate mt)
newHandle
public static ReceiverBehaviour.Handle newHandle()
- Factory method for message handles. This method returns a new
Handle object, which can be used to retrieve an ACL
message out of a ReceiverBehaviour object.
- Returns:
- A new
Handle object. - See Also:
ReceiverBehaviour.Handle
action
public void action()
- Actual behaviour implementation. This method receives a suitable
ACL message and copies it into the message provided by the
behaviour creator. It blocks the current behaviour if no suitable
message is available.
- Overrides:
- action in class Behaviour
done
public boolean done()
- Checks whether this behaviour ended.
- Returns:
true when an ACL message has been received.- Overrides:
- done in class Behaviour
reset
public void reset()
- Resets this behaviour. This method allows to receive another
ACLMessage with the same
ReceiverBehaviour without creating a new object.
- Overrides:
- reset in class Behaviour