0

我无法在用 Java 实现的 JADE 中部署代理,还有其他选择吗?

package package1;

import jade.core.Agent;

public class JadePFE extends Agent {
    @Override
    protected void setup() {
        System.out.println("Hello agent 007");
    }

}
4

2 回答 2

1

我认为您的意思是启动 JADE 平台,这是启动整个事物的 my main 方法的内容。希望能帮助到你

public class main {
public static void main(String[] args) {
    // TODO Auto-generated method stub
    String[] args1 = new String[3];
    args1[0] = "-gui";
    args1[1] = "-agents";
    args1[2] = "agentName:package.agentClassName";
    jade.Boot.main(args1);  

}

}

于 2014-12-21T15:19:20.913 回答
0

如果我了解,您想知道如何直接从代码部署代理(并可能启动平台)。

我向你展示如何:

import jade.core.Runtime;
import jade.core.Profile;
import jade.core.ProfileImpl;
import jade.wrapper.*;

public class Start {

    public static void main(String args[]) throws InterruptedException, StaleProxyException {

        // Get a hold on JADE runtime
        Runtime runTime = Runtime.instance();

        // Exit the JVM when there are no more containers around
        runTime.setCloseVM(true);

        // Create a profile and the main container and start RMA
        Profile mainProfile = new ProfileImpl(true);
        AgentContainer mainContainer = runTime.createMainContainer(mainProfile);
        AgentController rma = mainContainer.createNewAgent("rma", "jade.tools.rma.rma", null);
        rma.start();
        Thread.sleep(500);

        // Create a Sniffer
        AgentController sniffer = mainContainer.createNewAgent(
                "mySniffer", "jade.tools.sniffer.Sniffer",
                new Object[]{"BuyerAgent1;BuyerAgent2;ShipperAgent1;ShipperAgent2"});
        sniffer.start();
        Thread.sleep(500);

        // Create a Introspector
        AgentController introspector = mainContainer.createNewAgent(
                "myIntrospector", "jade.tools.introspector.Introspector",
                null);
        introspector.start();
        Thread.sleep(500);

        // Prepare for create and fire new agents:
        Profile anotherProfile;
        AgentContainer anotherContainer;
        AgentController agent;

        /*  Create a new profile and a new non-main container, connecting to the
            default main container (i.e. on this host, port 1099)
            NB. Two containers CAN'T share the same Profile object: create a new one. */

        anotherProfile = new ProfileImpl(false);
        anotherContainer = runTime.createAgentContainer(anotherProfile);
        System.out.println("Starting up a BuyerAgent...");
        agent = anotherContainer.createNewAgent("BuyerAgent1", "transfersimulation.BuyerAgent", new Object[0]);
        agent.start();
        Thread.sleep(900);

        anotherProfile = new ProfileImpl(false);
        anotherContainer = runTime.createAgentContainer(anotherProfile);
        System.out.println("Starting up a BuyerAgent...");
        agent = anotherContainer.createNewAgent("BuyerAgent2", "transfersimulation.BuyerAgent", new Object[0]);
        agent.start();
        Thread.sleep(900);

        anotherProfile = new ProfileImpl(false);
        anotherContainer = runTime.createAgentContainer(anotherProfile);
        System.out.println("Starting up a ShipperAgent...");
        agent = anotherContainer.createNewAgent("ShipperAgent1", "transfersimulation.ShipperAgent", new Object[0]);
        agent.start();
        Thread.sleep(900);

        return;
    }
}

如果没有其他 JADE 平台已在运行,则此方法有效。

于 2014-12-24T12:32:26.523 回答