获取所有JADE容器的列表 [英] Getting a list of all JADE containers

查看:80
本文介绍了获取所有JADE容器的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取当前平台中所有容器的列表。 这个问题类似,但答案已过时,方法是通过向AMS代理查询。除了通过ACL消息进行通信(我认为这很复杂)之外,还有什么更简单的出路,应该有一种获得简单容器列表的出路。感谢您的帮助

I want to get a list of all containers in the current platform. This question is similar, but the answer is obsolete and the method is by querying to the AMS agent. Is there any simpler way out than to communicate via ACL messages which I think is complex, there should be a way out to get a simple list of containers. Thanks for your help

推荐答案

您可以通过使用AMSSubscriber类来实现此目的,并在添加或删除容器时侦听事件。参见下面的示例代码:

You can achieve this by using the AMSSubscriber class and listen to the events when a container is added or removed. See sample code below:

public class myAgent extends Agent {

  private ArrayList<ContainerID> availableContainers = new ArrayList<ContainerID>();

  /**
   * Agent initializations
  **/
  protected void setup() {

    AMSSubscriber subscriber = new AMSSubscriber(){
      protected void installHandlers(Map handlers){
        EventHandler addedHandler = new EventHandler(){
          public void handle(Event event){
              AddedContainer addedContainer = (AddedContainer) event;
              availableContainers.add(addedContainer.getContainer());
          }
        };
    handlers.put(IntrospectionVocabulary.ADDEDCONTAINER,addedHandler);


        EventHandler removedHandler = new EventHandler(){
          public void handle(Event event){
              RemovedContainer removedContainer = (RemovedContainer) event;
              ArrayList<ContainerID> temp = new ArrayList<ContainerID>(availableContainers);
              for(ContainerID container : temp){
                  if(container.getID().equalsIgnoreCase(removedContainer.getContainer().getID()))
                      availableContainers.remove(container);
              }
          }
        };
        handlers.put(IntrospectionVocabulary.REMOVEDCONTAINER,removedHandler);
      }
    };
    addBehaviour(subscriber);
  }
}

参考:1)使用JADE开发多代理系统
作者:Fabio Luigi Bellifemine,乔瓦尼·凯尔,多米尼克·格林伍德(页111)
2) Jade API

Reference: 1) Developing multi-agent systems with JADE By Fabio Luigi Bellifemine, Giovanni Caire, Dominic Greenwood (page 111) 2) Jade API

这篇关于获取所有JADE容器的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆