如何从普通(非代理)java类执行JADE代理?

时间:2016-09-09 11:46:33

标签: java agent agents-jade multi-agent

我想从其他不是代理的类向代理发送消息。例如Servlet或主要的静态类。

1 个答案:

答案 0 :(得分:0)

这是一个oridnary类而不是代理:

        MainContainerAgentsRetriever retriever = new MainContainerAgentsRetriever();
        JadeGateway.execute(retriever);
        // At this point the retriever behaviour has been fully executed --> the list of 
        // agents running in the Main Container is available: get it and print it
        List agents = retriever.getAgents();

        if (agents != null) {
            System.out.println("Agents living in the Main Container: ");
            for (int i = 0; i < agents.size(); ++i) {
                System.out.println("- " + ((AID) agents.get(i)).getLocalName());

                ACLMessage msg = new ACLMessage();
                msg.addReceiver(((AID) agents.get(i)));
                msg.setContent("salam refigha");
                retriever.send(msg);



            }
        }