|
Messaging
The following examples show how to make JADE agents communicate by exchanging ACL messages
PingAgent | |
Description: | |
This example shows an agent able to respond to other agents wishing
to know if it is alive. More in details we use a
CyclicBehaviour that receives only messages of type
QUERY_IF and using the presence ontology.
All other messages are ignored. This is acheved by specifying a
proper MessageTemplate . Whenever such a message is
received an INFORM message is sent back as reply.
In order to run this example, start the JADE runtime (with the management GUI) and launch a PingAgent on it. Then starts the DummyAgent from the JADE management GUI. From the DummyAgent send a message of type QUERY_IF with ontology "presence" and "alive" as
content to the PingAgent. Use the DummyAgent again to inspect the response.
. |
|
Jade classes used: | |
Agent, ACLMessage, MessageTemplate, CyclicBehaviour | |
Source | |
\src\examples\messaging\PingAgent.java |
BlockingReceiveAgent | |
Description: | |
This example shows how to receive messages in blocking mode
by means of the blockingReceive() method. Note that
this method blocks the whole agent. If you call it from within
a behaviour you have to take into account that all other behaviours
will not be able to run until the call to blockingReceive()
returns.
In order to run this example, start the JADE runtime (with the management GUI) and launch a BlockingReceiveAgent on it. Then starts the DummyAgent from the JADE management GUI. From the DummyAgent send a message of type REQUEST to the BlockingReceiveAgent.
Use the DummyAgent again to inspect the response.
|
|
Jade classes used: | |
Agent, ACLMessage, MessageTemplate | |
Source | |
\src\examples\messaging\BlockingReceiveAgent.java |
CustomTemplateAgent | |
Description: | |
This example shows how to create a custom MessageTemplate .
In this case in particular we define a template matching only REQUEST
messages where the ontology starts with "X".
In order to run this example, start the JADE runtime (with the management GUI) and launch a CustomTemplateAgent on it. Then starts the DummyAgent from the JADE management GUI. From the DummyAgent send a message of type REQUEST to the CustomTemplateAgent specifying a value starting with "X" (e.g.
"X-onto") in the :ontology slot: the CustomTemplateAgent
will catch the message. Then try to send another message with a value not
starting with "X" in the ontology field: the CustomTemplateAgent will
ignore the message.
|
|
Jade classes used: | |
Agent, ACLMessage, MessageTemplate, MessageTemplate.MatchExpression | |
Source | |
\src\examples\messaging\CustomTemplateAgent.java |
JADE
is a trademark of TILAB (formerly CSELT).
JADE has been developed jointly by TILAB
(formerly CSELT)
and the Computer
Engineering Group of the University
of Parma