一些有用的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(); }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章