示例#1
0
  public static void main(String args[]) throws Exception {
    IAFProperties.setGraphicsOn(false);

    new Thread() {
      public void run() {
        String[] args1 = new String[4];
        args1[0] = "-port";
        args1[1] = "60000";
        args1[2] = "-file-dir";
        args1[3] = "jade/";
        jade.Boot.main(args1);
      }
    }.start();

    // Get a hold on JADE runtime
    jade.core.Runtime rt = jade.core.Runtime.instance();

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

    // Create a default profile
    Profile p = new ProfileImpl();
    p.setParameter("preload", "a*");
    p.setParameter(Profile.MAIN_PORT, "60000");
    p.setParameter(Profile.FILE_DIR, "jade/");

    // Waits for JADE to start
    boolean notConnected = true;

    while (notConnected) {
      try {
        Socket s = new Socket("localhost", Integer.parseInt("60000"));
        notConnected = false;
      } catch (NumberFormatException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IOException e) {

        System.err.println("Error: " + e.getMessage());
        System.err.println("Reconnecting in one second");
        try {
          Thread.currentThread().sleep(1000);
        } catch (InterruptedException e1) {
          // TODO Auto-generated catch block
          e1.printStackTrace();
        }
      }
    }

    // Create a new non-main container, connecting to the default
    // main container (i.e. on this host, port 1099)
    final jade.wrapper.AgentContainer ac = rt.createAgentContainer(p);

    {
    }
    MainInteractionManager.getInstance().setTitle("node ");
  }
示例#2
0
  /**
   * from: Luis Lezcano Airaldi <*****@*****.**> to: [email protected] date: Sat,
   * Jun 7, 2014 at 3:10 PM
   *
   * <p>Hello! It's very easy to use Jade as a library. Here's an example from a small application I
   * made:
   */
  public void testJade1() {
    // This is the important method. This launches the jade platform.
    final Runtime rt = Runtime.instance();

    final Profile profile = new ProfileImpl();

    // With the Profile you can set some options for the container
    profile.setParameter(Profile.PLATFORM_ID, "Platform Name");
    profile.setParameter(Profile.CONTAINER_NAME, "Container Name");

    // Create the Main Container
    final AgentContainer mainContainer = rt.createMainContainer(profile);
    final String agentName = "manager";
    final String agentType = "ia.main.AgentManager"; // FIXME
    final Object[] agentArgs = {};

    try {
      // Here I create an agent in the main container and start it.
      final AgentController ac = mainContainer.createNewAgent(agentName, agentType, agentArgs);
      ac.start();
    } catch (final StaleProxyException e) {
      LOG.error(
          String.format(
              "Problem creating/starting Jade agent '%s'" + " of type: %s with args: %s",
              agentName, agentType, Arrays.asList(agentArgs)),
          e);
    }
  }
 public void addOrganization(String key, Organization organization) {
   organizations.put(key, organization);
   Runtime runtime = Runtime.instance();
   try {
     AgentController controller = organization.getContainer().acceptNewAgent(key, organization);
     controller.start();
   } catch (Exception exception) {
     exception.printStackTrace();
   }
 }
  public Environment(String name, String host, String port) {
    this.name = name;
    this.host = host;
    this.port = port;

    try {
      Runtime runtime = Runtime.instance();
      profile = new ProfileImpl(host, Integer.valueOf(port), name);
      mainConteiner = runtime.createMainContainer(profile);
      AgentController rma =
          mainConteiner.createNewAgent("rma", "jade.tools.rma.rma", new Object[0]);
      rma.start();
    } catch (ControllerException exception) {
      exception.printStackTrace();
    }
  }
示例#5
0
  /**
   * Create an empty platform composed of 1 main container and 3 containers.
   *
   * @return a ref to the platform and update the containerList
   */
  private static Runtime emptyPlatform(HashMap<String, ContainerController> containerList) {

    Runtime rt = Runtime.instance();

    // 1) create a platform (main container+DF+AMS)
    Profile pMain = new ProfileImpl(hostname, 8888, null);
    System.out.println("Launching a main-container..." + pMain);
    AgentContainer mainContainerRef = rt.createMainContainer(pMain); // DF and AMS are include

    // 2) create the containers
    containerList.putAll(createContainers(rt));

    // 3) create monitoring agents : rma agent, used to debug and monitor the platform; sniffer
    // agent, to monitor communications;
    createMonitoringAgents(mainContainerRef);

    System.out.println("Plaform ok");
    return rt;
  }
示例#6
0
文件: Main.java 项目: escalope/IDK
  public static void main(String args[]) throws Exception {

    // Get a hold on JADE runtime
    jade.core.Runtime rt = jade.core.Runtime.instance();

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

    // Create a default profile
    Profile p = new ProfileImpl();
    p.setParameter("preload", "a*");
    p.setParameter(Profile.MAIN_PORT, "60000");
    p.setParameter(Profile.FILE_DIR, "jade/");

    // Create a new non-main container, connecting to the default
    // main container (i.e. on this host, port 1099)
    final jade.wrapper.AgentContainer ac = rt.createAgentContainer(p);

    {
    }
    MainInteractionManager.getInstance().setTitle("node ");
  }
  public void init(Properties params, AServProtocolManager manager) throws AServException {
    int port = 8888;
    Object args[] = new Object[2];

    // set up the manager as an argument to pass to the JADEFIPAAServiceAgent
    args[0] = manager;

    // set up the Parameters as an argument to pass to the JADEFIPAServiceAgent
    args[1] = params;

    if (params.getProperty("jade") != null) port = Integer.parseInt(params.getProperty("jade"));

    // Properties props = new Properties();
    try {
      // Get a hold on JADE runtime
      Runtime rt = Runtime.instance();

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

      /**
       * Profile with no MTP( Message Transfer Protocol props.setProperty("nomtp", "true"); Profile
       * pMain = new ProfileImpl(props);
       */
      // create a default Profile
      Profile pMain = new ProfileImpl(null, port, null);

      // logger.trace( "Launching a whole in-process platform... {}", pMain );
      mc = rt.createMainContainer(pMain);
      algagentcontroller =
          mc.createNewAgent("JadeFIPAAServiceAgent", JadeFIPAAServiceAgent.class.getName(), args);
      algagentcontroller.start();
    } catch (Exception ex) {
      throw new AServException("Cannot launch Jade Server", ex);
    }
  }
示例#8
0
  public boolean connect() {
    try {
      // Initialize the BackEndManager if required
      if (myProfile.getBooleanProperty(USE_BACKEND_MANAGER, false)) {
        theBEManager = initBEManager();
      }

      Vector agentSpecs =
          Specifier.parseSpecifierList(myProfile.getParameter(Profile.AGENTS, null));
      myProfile.setParameter(Profile.AGENTS, null);

      myFrontEnd = myConnectionManager.getFrontEnd(this, null);
      myLogger.log(
          Logger.FINE,
          "BackEnd container "
              + myProfile.getParameter(Profile.CONTAINER_NAME, null)
              + " joining the platform ... (FrontEnd version: "
              + myProfile.getParameter(JICPProtocol.VERSION_KEY, "not available")
              + ")");

      Runtime.instance().beginContainer();
      boolean connected = joinPlatform();
      if (connected) {
        myLogger.log(Logger.FINE, "Join platform OK");
        AID amsAID = getAMS();
        myProfile.setParameter(Profile.PLATFORM_ID, amsAID.getHap());
        String[] addresses = amsAID.getAddressesArray();
        if (addresses != null) {
          StringBuffer sb = new StringBuffer();
          for (int i = 0; i < addresses.length; i++) {
            sb.append(addresses[i]);
            if (i < addresses.length - 1) {
              sb.append(';');
            }
          }
          myProfile.setParameter(MicroRuntime.PLATFORM_ADDRESSES_KEY, sb.toString());
        }
        if ("true".equals(myProfile.getParameter(RESYNCH, "false"))) {
          myLogger.log(
              Logger.INFO,
              "BackEnd container "
                  + myProfile.getParameter(Profile.CONTAINER_NAME, null)
                  + " activating re-synch ...");
          resynch();
        } else {
          // Notify the main container about bootstrap agents on the FE.
          for (int i = 0; i < agentSpecs.size(); i++) {
            Specifier sp = (Specifier) agentSpecs.elementAt(i);
            try {
              String name = bornAgent(sp.getName());
              sp.setClassName(name);
              sp.setArgs(null);
            } catch (Exception e) {
              myLogger.log(Logger.SEVERE, "Error creating agent " + sp.getName(), e);
              sp.setClassName(e.getClass().getName());
              sp.setArgs(new Object[] {e.getMessage()});
            }
          }
          myProfile.setParameter(Profile.AGENTS, Specifier.encodeSpecifierList(agentSpecs));
        }
      }
      return connected;
    } catch (Exception e) {
      // Should never happen
      e.printStackTrace();
      return false;
    }
  }
示例#9
0
  public static void main(String args[]) throws Exception {

    // Get a hold on JADE runtime
    jade.core.Runtime rt = jade.core.Runtime.instance();

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

    // Create a default profile
    Profile p = new ProfileImpl();
    p.setParameter("preload", "a*");
    p.setParameter(Profile.MAIN_PORT, "60000");
    if (args.length == 2 && args[1].equalsIgnoreCase("pause")) {
      ingenias.jade.graphics.MainInteractionManager.goManual();
    }
    if (new File("target/jade").exists() && new File("target/jade").isDirectory())
      p.setParameter(Profile.FILE_DIR, "target/jade/");
    else {
      // from http://stackoverflow.com/questions/617414/create-a-temporary-directory-in-java
      final File temp;
      temp = File.createTempFile("jade", Long.toString(System.nanoTime()));

      if (!(temp.delete())) {
        throw new IOException("Could not delete temp file: " + temp.getAbsolutePath());
      }

      if (!(temp.mkdir())) {
        throw new IOException("Could not create temp directory: " + temp.getAbsolutePath());
      }
      p.setParameter(Profile.FILE_DIR, temp.getAbsolutePath() + "/");
    }

    // Create a new non-main container, connecting to the default
    // main container (i.e. on this host, port 1099)
    final jade.wrapper.AgentContainer ac = rt.createAgentContainer(p);

    {
      // Create a new agent
      final jade.wrapper.AgentController agcGUIAgent_0DeploymentUnitByType0 =
          ac.createNewAgent(
              "GUIAgent_0DeploymentUnitByType0",
              "ingenias.jade.agents.GUIAgentJADEAgent",
              new Object[0]);

      new Thread() {
        public void run() {
          try {
            System.out.println("Starting up GUIAgent_0DeploymentUnitByType0...");
            agcGUIAgent_0DeploymentUnitByType0.start();
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
      }.start();

      // Create a new agent
      final jade.wrapper.AgentController agcGUIAgent_1DeploymentUnitByType0 =
          ac.createNewAgent(
              "GUIAgent_1DeploymentUnitByType0",
              "ingenias.jade.agents.GUIAgentJADEAgent",
              new Object[0]);

      new Thread() {
        public void run() {
          try {
            System.out.println("Starting up GUIAgent_1DeploymentUnitByType0...");
            agcGUIAgent_1DeploymentUnitByType0.start();
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
      }.start();

      // Create a new agent
      final jade.wrapper.AgentController agcGUIAgent_2DeploymentUnitByType0 =
          ac.createNewAgent(
              "GUIAgent_2DeploymentUnitByType0",
              "ingenias.jade.agents.GUIAgentJADEAgent",
              new Object[0]);

      new Thread() {
        public void run() {
          try {
            System.out.println("Starting up GUIAgent_2DeploymentUnitByType0...");
            agcGUIAgent_2DeploymentUnitByType0.start();
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
      }.start();
    }
    MainInteractionManager.getInstance().setTitle("node SampleDeployment");
  }
示例#10
0
  public void startContainer() throws SlickException {
    // ----------JADE start
    // Get a hold of JADE runtime
    Runtime runtime = Runtime.instance();
    // Create a default profile
    ProfileImpl profile = new ProfileImpl();
    // Create a new non-main container, connecting to the default
    // main container (i.e. on this host, port 1099)
    ContainerController cc = runtime.createMainContainer(profile);
    AgentController rma = null;
    AgentController player1 = null;
    AgentController player2 = null;
    AgentController player3 = null;
    AgentController player4 = null;
    ArrayList<AgentController> landmarks = new ArrayList<AgentController>();
    Object[] arguments = new Object[3];
    arguments[0] = this.map;
    arguments[1] = "team1-luffy";
    arguments[2] = map.getAvatars().get(1);
    Object[] argumentsChief = new Object[3];
    argumentsChief[0] = this.map;
    argumentsChief[1] = "team1-luffy";
    argumentsChief[2] = map.getAvatars().get(0);
    Object[] arguments2 = new Object[3];
    arguments2[0] = this.map;
    arguments2[1] = "team2-roronoa";
    arguments2[2] = map.getAvatars().get(2);
    Object[] argumentsChief2 = new Object[3];
    argumentsChief2[0] = this.map;
    argumentsChief2[1] = "team2-roronoa";
    argumentsChief2[2] = map.getAvatars().get(3);
    try {
      rma = cc.createNewAgent("rma", "jade.tools.rma.rma", null);
      player1 =
          cc.createNewAgent(
              ((Avatar) arguments[2]).getName(), "agents.TickerExplorerRandomPlayer", arguments);
      player2 =
          cc.createNewAgent(
              ((Avatar) arguments2[2]).getName(), "agents.TickerExplorerRandomPlayer", arguments2);
      player3 =
          cc.createNewAgent(
              "Chiefteam1-luffy", "agents.TickerExplorerRandomPlayer", argumentsChief);
      player4 =
          cc.createNewAgent(
              "Chiefteam2-roronoa", "agents.TickerExplorerRandomPlayer", argumentsChief2);
      for (int i = 0; i < map.getLandmarks().size(); i++) {
        Object[] landmarkArgs = new Object[4];
        landmarkArgs[0] = "Landmark" + i;
        landmarkArgs[1] = this.map;
        landmarkArgs[2] = map.getLandmarks().get(i);
        landmarkArgs[3] = map.getLandmarks().get(i).getMessage();
        landmarks.add(
            cc.createNewAgent(
                map.getLandmarks().get(i).getName(), "agents.LandmarkAgent", landmarkArgs));
      }
      System.out.println("Agent created \n");

    } catch (StaleProxyException ex) {
      System.out.println("here is problem");
    }
    try {
      // rma.start();
      player1.start();
      player2.start();
      player3.start();
      player4.start();
      for (int i = 0; i < map.getLandmarks().size(); i++) {
        landmarks.get(i).start();
      }
      System.out.println("Agent started \n");
    } catch (StaleProxyException ex) {
      System.out.println("Stale Proxy pointer ex");
    } catch (NullPointerException ex) {
      System.out.println("Null pointer ex");
      ex.printStackTrace();
    }
    //	            //----------JADE end
  }