我正在使用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
如果我获得完整行为的源代码会更好 提前致谢
答案 0 :(得分:1)
这是启动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();
}
}