0
我在使用一個Agent接收多個消息時遇到問題。 以下是我的代碼。 msg_r,代理收到的消息始終是第一條消息。我怎樣才能得到第二條消息getSender().getLocalName().equals("TeilsystemAgent")
Jade Agent無法接收多個消息
public class KomponenteAgent extends Agent {
static JTextArea txt = gui.gettxt();
private String AdminReceive = "";
private String KompCheckReceive = "";
private int Zaehler = 0;
JSONArray Admin = new JSONArray();
JSONArray KompCheck = new JSONArray();
protected void setup() {
Object[] arg = getArguments();
//frame = (IAPMS)arg[0];
addBehaviour(new SimpleBehaviour(this) {
private boolean finished = false;
public void action() {
ACLMessage msg_r = receive();
if (msg_r!= null){
if (msg_r.getSender().getLocalName().equals("KoordinatorAgent"))
//Bestaetigung
try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
AdminReceive = AdminReceive + msg_r.getContent();
try {
Admin = new JSONArray(AdminReceive);
System.out.println(getLocalName()+ Admin);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Zaehler = Zaehler + 1;
}
if (msg_r!= null){
if (msg_r.getSender().getLocalName().equals("TeilsystemAgent"))
//Bestaetigung
try {
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
KompCheckReceive = KompCheckReceive + msg_r.getContent();
System.out.println(getLocalName()+ KompCheckReceive);
try {
KompCheck = new JSONArray(KompCheckReceive);
System.out.println(getLocalName()+ KompCheck);
checkKomp(KompCheck);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (Zaehler == 1){
finished = true;
}
}
public boolean done(){
return finished;
}
});
}