翡翠代理容器

发布于 2024-07-13 07:26:07 字数 86 浏览 5 评论 0原文

谁能告诉我如何通过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).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生生不灭 2024-07-20 07:26:07

有两种方法可以执行此操作,具体取决于您是希望通过正在进行的服务还是消息中的当前快照接收信息。

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

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 的行为。 为 AddedContainer 事件注册一个处理程序,您将能够访问新可用容器的 ContainerID:

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());
}

希望这有帮助,

Russ

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.

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());
    }
}

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());
}

Hope this helps,

Russ

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文