Creata Jade Agent与另一个代理商

时间:2016-06-09 15:35:53

标签: agents-jade

拜托,我需要帮助。如何在另一个代理的主体中创建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();

1 个答案:

答案 0 :(得分: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);
    }
}