翡翠代理容器 [英] Jade Agent Containers

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

问题描述

谁能告诉我如何通过 java 代码找到可用的代理容器?我正在使用 JADE 代理框架,我已经弄清楚如何创建新容器但找不到现有容器(以便可以在其中部署代理).

Can anyone tell me how to find available agent containers through java code? I am using the JADE agent framework and I have figured out how to create new containers but not find existing containers (so that agents can be deployed in them).

推荐答案

有两种方法可以做到这一点,具体取决于您是希望通过正在进行的服务还是通过消息中的当前快照接收信息.

There are two ways of doing this, depending on whether you want to receive the information via an ongoing service or the current snapshot in a message.

要获取当前可用代理容器的 ID 快照,请向代理管理服务 (AMS) 发送请求消息并等待其回复.使用 JADE 管理本体和 QueryPlatformLocationsAction 术语,发送和接收方法将是:

To get a snapshot of the IDs of the currently available agent containers, send a Request message to the Agent Management Service (AMS) and wait for its reply. Using the JADE Management Ontology and the QueryPlatformLocationsAction term, the sending and receiving methods would be:

private void queryAMS() throws CodecException, OntologyException {
    QueryPlatformLocationsAction query = new QueryPlatformLocationsAction();
    Action action = new Action(myAgent.getAID(), query);

    ACLMessage message = new ACLMessage(ACLMessage.REQUEST);
    message.addReceiver(myAgent.getAMS());
    message.setLanguage(FIPANames.ContentLanguage.FIPA_SL);
    message.setOntology(JADEManagementOntology.getInstance().getName());
    myAgent.getContentManager().fillContent(message, action);
    myAgent.send(message);
}
private void listenForAMSReply() throws UngroundedException, CodecException, 
OntologyException {
    ACLMessage receivedMessage = myAgent.blockingReceive(MessageTemplate
            .MatchSender(myAgent.getAMS()));
    ContentElement content = myAgent.getContentManager().extractContent(
        receivedMessage);

    // received message is a Result object, whose Value field is a List of
    // ContainerIDs
    Result result = (Result) content;
    List listOfPlatforms = (List) result.getValue();

    // use it
    Iterator iter = listOfPlatforms.iterator();
    while (iter.hasNext()) {
        ContainerID next = (ContainerID) iter.next();
        System.out.println(next.getID());
    }
}

要作为持续服务获取此信息,并在每个容器向 AMS 注册时接收它的 ContainerID,请创建一个扩展 AMSSubscriber 的行为.为 AdditionalContainer 事件注册一个处理程序,您将能够访问新可用容器的 ContainerID:

To get this information as an ongoing service, and to receive the ContainerID of each container as it registers with the AMS, create a Behaviour that extends the AMSSubscriber. Register a handler for the AddedContainer event and you will be able to access the ContainerID of the newly available container:

public class AMSListenerBehaviour extends AMSSubscriber {
@Override
public void installHandlers(Map handlersTable) {
    handlersTable.put(AddedContainer.NAME, addedContainerHandler);
}

public final class AddedContainerHandler implements EventHandler {
@Override
public void handle(Event ev) {
    AddedContainer event = (AddedContainer) ev;
    ContainerID addedContainer = event.getContainer();
    System.out.println(addedContainer.getID());
}

希望这会有所帮助,

罗斯

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

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