一些有用的JADE代码 - MiTKooK‘s Technical Blog - CSDN...

来源:百度文库 编辑:神马文学网 时间:2024/07/03 08:32:31
 一些有用的JADE代码
Naming a new container
Runtime rt = Runtime.instance(); // Get a hold on JADE runtime
Profile p = new ProfileImpl();   // Create a default profile
p.setParameter(Profile.CONTAINER_NAME, "your-container-name-goes-here");
AgentContainer ac;
if (MainContainer)  ac = rt.createMainContainer(p);
else                ac = rt.createAgentContainer(p);
ac.createNewAgent(... 
Request the AMS to Perform the CreateAgent action
/**//*to REQUEST AMS agent to launch mobile agents*/
         // Get a hold on JADE runtime        Object[] args=getArguments();
         AgentContainer mc = (AgentContainer) args[0];
                  CreateAgent ca=new CreateAgent();
                  ca.setClassName("sma.MobileAgent");
                   ca.setAgentName("AM_0");

                  ContainerID id=new ContainerID();
                  id.setName(mc.getName());
                     ca.setContainer(id);
                  ACLMessage request = new ACLMessage(ACLMessage.REQUEST);
request.setLanguage(FIPANames.ContentLanguage.FIPA_SL);
         request.setOntology(JADEManagementOntology.NAME);
         Action action=new Action();
         action.setActor(getAMS());
         action.setAction(ca);
         try ...{
         getContentManager().fillContent(request,  action);

         send(request);
         }
         catch (Exception ex) ...{ ex.printStackTrace(); }