[英]Stop a JADE system (Java agents)
I run JADE embedded in a Java program, ie not with java jade.Boot...
.我运行嵌入在 Java 程序中的 JADE,即不使用
java jade.Boot...
Now I wanted to stop the JADE system, but I have found no nice way to do that.现在我想停止 JADE 系统,但我没有找到好的方法来做到这一点。 I can exit the whole program using System.exit(), but that's not what I want to do.
我可以使用 System.exit() 退出整个程序,但这不是我想要做的。
I tried several different things, and I succeeded stopping my agent behaviours, but a couple of Threads continue running: the AMS, the DF, a web server, the JADE Timer dispatcher, several Deliverer threads, etc.我尝试了几种不同的方法,并成功停止了我的代理行为,但有几个线程继续运行:AMS、DF、web 服务器、JADE Timer 调度程序、几个 Deliverer 线程等。
This is how my current shutdown method looks like:这是我当前的关闭方法的样子:
@Override
public void shutdown() {
// TODO This does not work yet..
try {
for (WeakReference<AgentController> acr : agents) {
AgentController ac = acr.get(); // jade.wrapper.AgentController
if ( ac != null ) ac.kill();
}
container.kill(); // jade.wrapper.AgentContainer
Runtime.instance().shutDown(); // jade.core.Runtime
} catch ( StaleProxyException e ) {
e.printStackTrace();
}
}
The reason I want to do that is that I have some JUnit tests for my agent system.我想这样做的原因是我的代理系统有一些 JUnit 测试。
Any ideas how to accomplish that?任何想法如何做到这一点?
You can request AMS to stop the platform in such way:您可以通过以下方式请求 AMS 停止平台:
Codec codec = new SLCodec();
Ontology jmo = JADEManagementOntology.getInstance();
getContentManager().registerLanguage(codec);
getContentManager().registerOntology(jmo);
ACLMessage msg = new ACLMessage(ACLMessage.REQUEST);
msg.addReceiver(getAMS());
msg.setLanguage(codec.getName());
msg.setOntology(jmo.getName());
try {
getContentManager().fillContent(msg, new Action(getAID(), new ShutdownPlatform()));
send(msg);
}
catch (Exception e) {}
You can shutdown the whole JADE platform with:您可以使用以下命令关闭整个 JADE 平台:
try {
this.getContainerController().getPlatformController().kill();
}
catch (final ControllerException e) {
System.out.println("Failed to end simulation.");
}
"this" refers to an Agent class object. “这个”是指代理 class object。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.