代理之间发送对象

时间:2016-06-03 20:02:22

标签: agents-jade

我有两个jade代理,我想从一个代理向另一个代理发送一个对象,我使用了setContentObject()getContentObject()方法,第二个代理收到对象时工作正常,但我可以似乎找不到获取对象变量的方法,例如:

public class Person implements Serializable{
  private String firstName;
  private String lastName;
  public String getFirstName(){
     return firstName;
  }
  public void setFirstName(String fName){
     this.firstName=fName;
  }
  public String getLastName(){
     return lastName;
  }
  public void setFirstName(String lName){
     this.lastName=lName;
  }
}

剂1:

public class Agent1 extends Agent{
  @Override
    protected void setup() {
        addBehaviour(new OneShotBehaviour(this) {
          @Override
          public void action(){
          ACLMessage aclmsg = new ACLMessage(ACLMessage.REQUEST);
          aclmsg.addReceiver(new AID("Agent2", AID.ISLOCALNAME));
          aclmsg.setContentObject(Person);
          send(aclmsg);
          });
        }
    }
}

Agent2

public class Agent2 extends Agent{
      @Override
        protected void setup() {
            addBehaviour(new CyclicBehaviour(this) {
            @Override
            public void action(){
             ACLMessage msg = receive();
             if(msg!=null){
               //Here i want to get the first name of the object Person
             }             
            });

           }
        }
}

所以我的问题是如何检索发送对象Person的firstName?

1 个答案:

答案 0 :(得分:3)

((Person)msg.getContentObject()).getFirstName()

阅读this