1

コンピュータ上で動作するメイン コンテナに作成されたエージェントに接続したい。メイン コンテナ ID が Main-Container@192.118.2.3 であると仮定すると、そのコンテナ内のエージェントに接続してデータを渡すにはどうすればよいですか? 前もって感謝します。

4

1 に答える 1

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

その後、getAgent()ContainerController のメソッドを使用して 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 ドキュメント

于 2013-12-09T06:18:57.587 に答える