gpt4 book ai didi

java - JADE 中间件的移动性

转载 作者:行者123 更新时间:2023-12-01 11:56:07 25 4
gpt4 key购买 nike

我正在使用 JADE(Java 代理开发框架),我正在尝试编写一种行为,使代理从容器移动到另一个容器。我尝试了这个命令:

public void action() {
ACLMessage msg = myAgent.receive(template);
if (msg != null) {
moveRequest = msg;
String destination =
doMove(new ContainerID(destination, null));
}
else {
block();
}
}

但是我好像移动失败了:

jade.core.mobility.AgentMobilityService$CommandSourceSink handleInformMoved Grave: Mobility protocol not supported. Aborting transfer

如果我能得到完整行为的源代码会更好。
提前致谢

最佳答案

这是启动jade平台的代码:

import jade.core.Profile;
import jade.core.ProfileImpl;
import jade.core.Runtime;
import jade.wrapper.AgentContainer;
import jade.wrapper.AgentController;


public class Run {

public Run() {
Runtime rt = Runtime.instance();
rt.setCloseVM(true);
AgentContainer mc = rt.createMainContainer(new ProfileImpl());

Profile p = new ProfileImpl();
p.setParameter("container-name", "Foo");
AgentContainer ac = rt.createAgentContainer(p);

try{
AgentController rma = mc.createNewAgent("rma", "jade.tools.rma.rma", null);
rma.start();
AgentController ma = mc.createNewAgent("MA", "MobileAgent", null);
ma.start();
}
catch(Exception e){
e.printStackTrace();
}
}

public static void main(String[] args) {
new Run();
}
}

这是移动代理的代码。创建后,代理立即移动到容器 Foo 中。

import jade.core.Agent;
import jade.core.Location;

public class MobileAgent extends Agent {

private static final long serialVersionUID = 1L;

@Override
protected void setup() {
System.out.println("Hello World");
Location destination = new jade.core.ContainerID("Foo", null);
doMove(destination);
super.setup();
}

@Override
protected void beforeMove() {
System.out.println("Preparing to move");
super.beforeMove();
}

@Override
protected void afterMove() {
System.out.println("Arrived to destination");
super.afterMove();
}
}

关于java - JADE 中间件的移动性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28438323/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com