MTS or Ping Example
Todd Wright
twright at bbn.com
Tue Aug 7 18:48:10 EDT 2007
Einhuf wrote:
> Hi again,
> I only want to send messages from a sender to a receiver agent
> (currently inside one node on one computer). I only found the ping
> example to send messages and the MTS Service. But the documentation
> doesn´t include themes like "how to use" or examples. And the api
> Message Transport Service online manuel isn´t reachable ( The requested
> URL
> /software/latest/javadoc/mtsstd/doc/OnlineManual/MessageTransport/index.html
Here's a link to the online copy:
http://cougaar.cougaar.org/software/latest/OnlineManual/MessageTransport/
> was not found on this server.) Has anybody a link or code for the usage
> of that service. Or would you use the ping example via blackboard to
> communicate with other agents?
I recommend using the blackboard, as discussed in the overview slides:
http://cougaar.org/docman/view.php/17/196/CougaarOverview.ppt
and in the example code:
http://build.cougaar.org/auto/HEAD/latest_success/demo-ping.zip
Blackboard relays are analogous to inter-agent messages.
However, if you prefer, you can use raw messaging. Your component can
get the agent's MessageSwitchService:
http://cougaar.cougaar.org/software/latest/javadoc/core/doc/api/org/cougaar/core/agent/service/MessageSwitchService.html
The "sendMessage" method is easy to use. Receiving messages is more
complicated -- you must add a "MessageHandler" that processes the
messages on a separate thread, to avoid blocking the Message Transport.
The code should look similar to:
public boolean handleMessage(Message m) {
if (!(m instanceof MyMessage)) return false;
synchronized (queue) { queue.add(m); }
schedulable.start(); // ThreadService pooled thread for our "run()"
return true;
}
...
public void run() {
synchronized (queue) { tmp.addAll(queue); queue.clear(); }
for (Message m : tmp) {
// process the message!
}
tmp.clear();
}
I can provide a complete example if you're interested. However, I think
that the blackboard approach is both easier to use and more flexible.
Todd
>
>
> Thanks,
> Thomas
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Cougaar-developers mailing list
> Cougaar-developers at cougaar.org
> http://cougaar.org/mailman/listinfo/cougaar-developers
More information about the Cougaar-developers
mailing list