【问题标题】:How to send a message to an Agent in Main Container via http in Jade?如何通过 Jade 中的 http 向主容器中的代理发送消息?
【发布时间】:2013-09-16 17:13:18
【问题描述】:

我想连接到在计算机上运行的主容器中创建的代理。假设主容器 ID 是 Main-Container@192.118.2.3 我如何连接到该容器内的代理并传递数据?提前致谢。

【问题讨论】:

    标签: java javaagents agents-jade


    【解决方案1】:

    您需要一个 ContainerController(无论是主容器还是代理容器都无关紧要),它是您关注的代理平台的一部分。

    一个简单的方法是创建一个新的代理容器并将其连接到平台。

    import jade.core.Runtime;
    import jade.core.Profile;
    import jade.core.ProfileImpl;
    
    ...
    
    Runtime myRuntime = Runtime.instance();
    
    // prepare the settings for the platform that we're going to connect to
    Profile myProfile = new ProfileImpl();
    myProfile.setParameter(Profile.MAIN_HOST, "myhost");
    myProfile.setParameter(Profile.MAIN_PORT, "1099");
    
    // create the agent container
    ContainerController myContainer = myRuntime.createAgentContainer(myProfile);
    

    那么,你可以使用ContainerController的getAgent()方法来获取一个AgentController。

    AgentController myAgentController = myContainer.getAgent("agent-local-name");
    

    最后,如果您想将数据传递给代理,您可以使用 O2A(对象 2 代理)消息来实现。这基本上允许您通过代理控制器将任何对象传递给代理。

    Object myObject = "Real-Object-Would-Go-Here";
    myAgentController.putO2AObject(myObject, false);
    

    在代理中(最好在行为中),您可以像这样监听该对象:

    // start accepting O2A communications
    setEnabledO2ACommunication(true, 0);
    // start monitoring them
    addBehaviour(new CyclicBehaviour(this) {
        @Override
        public void action() {
            // get an object from the O2A mailbox
            Object myObject = myAgent.getO2AObject();
    
            // if we actually got one
            if(myObject != null) {
                // do something with it
            } else {
                block();
            }
        }
    });
    

    来源:JADE 文档

    【讨论】:

      猜你喜欢
      • 2021-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多