Talking to the NodeAgent

Todd Wright twright at bbn.com
Thu Oct 21 15:18:23 EDT 2004


On Thursday 21 October 2004 14:52, Matt Abrams wrote:
> Do you have the following component on your NodeAgent?
>
> <component
>         name='org.cougaar.core.mobility.service.RootMobilityPlugin()'
>         class='org.cougaar.core.mobility.service.RootMobilityPlugin'
>         priority='COMPONENT'
>         insertionpoint='Node.AgentManager.Agent.PluginManager.Plugin'>
> </component>

Right, this subscribes to AgentControl blackboard objects on the NodeAgent's 
blackboard, then calls the node's NodeControlService's AgentContainer's 
"addAgent(..)" for any publishAdd'ed AgentControl "AddTicket" requests.

Here's the RootMobilityPlugin code that does the "addAgent(..)" call:
http://cougaar.org/cgi-bin/viewcvs.cgi/core/src/org/cougaar/core/mobility/service/RootMobilityPlugin.java?annotate=1.20&cvsroot=core#267

>
> And this component on the agent where you are publishing the AgentControl?
>
> <component
>           name='org.cougaar.core.mobility.service.RedirectMovePlugin()'
>           class='org.cougaar.core.mobility.service.RedirectMovePlugin'
>           priority='COMPONENT'
>           insertionpoint='Node.AgentManager.Agent.PluginManager.Plugin'>
> </component>

Yes, this is only necessary if you're publishing the object in an agent other 
than the NodeAgent.

>
> Also, here is some sample code for adding an agent control to an agents
> blackboard.
>
> private void addAgent(String agentName, MessageAddress nodeAgentId,
> 			ComponentDescription compDescription) {
> 		if (logging.isDebugEnabled()) {
> 			logging.debug("Add agent " + agentName);
> 		}
> 		MobilityFactory mobilityFactory = (MobilityFactory)
> domainService.getFactory("mobility");
> 		MessageAddress mobileAgentAddress = MessageAddress
> 				.getMessageAddress(agentName);
> 		//String destNode= this.nodeAgentId.toString();
> 		MessageAddress destNodeAddress = nodeAgentId;
> 		//Create ticket id
> 		TicketIdentifier ticketIdentifier =
> (TicketIdentifier)mobilityFactory
> 				.createTicketIdentifier();
> 		//Create add ticket
> 		StateTuple st = null;
> 		AddTicket addticket = new AddTicket(ticketIdentifier,
> mobileAgentAddress,
> 				destNodeAddress, compDescription, st);
> 		//Create Add Agent control
> 		AgentControl addControl =
> 			mobilityFactory.createAgentControl(null,
> 				destNodeAddress, addticket);
> 		getBlackboardService().publishAdd(addControl);
> 		if (logging.isDebugEnabled()) {
> 			logging
> 					.debug("Just sent Message thru
> MessageTransport to NodeAgent to load agent - "
> 							+ agentName);
> 		}
> 	}

Right, that should work.  Not exactly pretty!

As Matt suggests, you can also write a NodeAgent plugin to call "addAgent(..)" 
directly.  The only thing to watch out for is to do this "addAgent(..)" call 
in a separate thread (e.g. using the ThreadService), otherwise you can get a 
"nested transaction" exception:
  http://bugs.cougaar.org/show_bug.cgi?id=1750

..
> The easiest way, and the way I've been using, is that I include some
> details
> (not the StateTuple itself, I'm desperately hoping that interface will
> change/improve soon) of the agent I want in an asset, and set it as the
> direct object of a task.

Right, probably just the new agent's MessageAddress.  Everything else is 
usually boilerplate:
http://cougaar.org/cgi-bin/viewcvs.cgi/core/src/org/cougaar/core/mobility/AddTicket.java?annotate=1.10&cvsroot=core#79

> Then all I have to do is allocate that task to the
> node agent for the desired node, from anywhere in the society. A single
> plugin in the NodeAgent subscribes to the task, builds the StateTuple, and
> calls addAgent.

Sure, but see the above bug 1750 caveat.

Todd


More information about the Cougaar-developers mailing list