2016-06-09 1 views
0

, пожалуйста, мне нужна помощь. Как создать агент JADE в теле другого агента?Creata Jade Агент с другим агентом

Profile p = new ProfileImpl(); 

    p.setParameter(Profile.MAIN_HOST, "localhost"); 

    p.setParameter(Profile.MAIN_PORT, "1099"); 

    AgentContainer ac = rt.createMainContainer(p); 
    AgentController agent ac.createNewAgent ("agentBD", "agents.AgentBD"); 

    agent.start(); 

ответ

0

попробовать что-то вроде этого («агент» вам текущий агент из ведьма создания другого агента):

private static Codec codec = new SLCodec(); 
private static ContentManager cm = new ContentManager(); 
static 
{ 
    cm.registerLanguage(codec, FIPANames.ContentLanguage.FIPA_SL0); 
    cm.registerOntology(FIPAManagementOntology.getInstance()); 
    cm.registerOntology(JADEManagementOntology.getInstance()); 
} 

public static AID createNewAgent(Agent agent, String name, String className) 
{ 
    CreateAgent ca = new CreateAgent(); 
    ca.setAgentName(name); 
    ca.setClassName(className); 
    ca.setContainer((ContainerID) agent.here()); 

    ACLMessage request = new ACLMessage(ACLMessage.REQUEST); 
    request.addReceiver(agent.getAMS()); 
    request.setOntology(JADEManagementOntology.getInstance().getName()); 
    request.setLanguage(FIPANames.ContentLanguage.FIPA_SL0); 
    request.setReplyWith("new-agent-" + agent.getName() + System.currentTimeMillis()); 

    try 
    { 
     cm.fillContent(request, new Action(agent.getAMS(), ca)); 
     agent.send(request); 

     MessageTemplate mt = MessageTemplate.MatchInReplyTo(request.getReplyWith()); 
     ACLMessage reply = agent.blockingReceive(mt, 10000); 
     if(reply == null) 
      throw new RuntimeException("cannot create agent [" + name + "; " + className + "]"); 

     return new AID(name, AID.ISLOCALNAME); 
    } 
    catch (Codec.CodecException e) 
    { 
     throw new RuntimeException(e); 
    } 
    catch (OntologyException e) 
    { 
     throw new RuntimeException(e); 
    } 
}