Creata Jade代理与另一个代理 [英] Creata Jade Agent with another agent
本文介绍了Creata Jade代理与另一个代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请,我需要帮助。如何在另一个代理的主体中创建JADE代理?
please , I need help. How to create a JADE agent in the body of another agent ?
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();
推荐答案
尝试类似的方法( agent是当前从鞭子中创建其他代理)
try something like this ("agent" is you current agent from whitch you create other agent):
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);
}
}
这篇关于Creata Jade代理与另一个代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文