玉器容器 [英] Jade Agent Containers

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

问题描述

谁能告诉我如何通过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的Behavior。为AddedContainer事件注册一个处理程序,您将可以访问新可用容器的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天全站免登陆