JADE ACL-Message

时间:2017-04-21 18:12:17

标签: java agents-jade

我需要在接收代理中获取“a”和“b”的值,请该怎么做?

public class EnvoiMessage extends CyclicBehaviour {

    private boolean finished = false;

    public void action() {
        ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
        msg.setContent(+a + "" + b);
        AID receiver1 = new AID("B", AID.ISLOCALNAME);
        AID receiver2 = new AID("C", AID.ISLOCALNAME);
        AID receiver3 = new AID("D", AID.ISLOCALNAME);
        AID receiver4 = new AID("E", AID.ISLOCALNAME);
        msg.addReceiver(receiver1);
        msg.addReceiver(receiver2);
        msg.addReceiver(receiver3);
        msg.addReceiver(receiver4);
        send(msg);
        finished = true;

    }
}

1 个答案:

答案 0 :(得分:0)

如果我对问题的权利不知情,只要没有收到请求就会使用行为(例如周期行为),如下所示:

public void action() { 
   ACLMessage msg = myAgent.receive(); 
   if (msg != null) {
       Message received. Process it ... 
       msg.getContent();
   } else {
       block(); 
}