我想从不是代理的其他类向代理发送消息。例如Servlet或主要的静态类。
最佳答案
这是普通类,不是代理:
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);
}
}