Beispiel #1
0
  public static void launch() {
    println("Launching sos test agents");
    try {

      int port =
          config.getIntValue(
              Constants.KERNEL_PORT_NUMBER_KEY, Constants.DEFAULT_KERNEL_PORT_NUMBER);
      String host =
          config.getValue(Constants.KERNEL_HOST_NAME_KEY, Constants.DEFAULT_KERNEL_HOST_NAME);

      ComponentLauncher launcher = new TCPComponentLauncher(host, port, config);
      connect(launcher, new MessageTestAgent(), config);
    } catch (ConnectionException e) {
      sosLogger.fatal("Error connecting agents", e);
      System.exit(-1);
    } catch (InterruptedException e) {
      sosLogger.fatal("Error connecting agents", e);
      System.exit(-1);
    } catch (ComponentConnectionException e) {
      if (e.getMessage() != null && e.getMessage().indexOf("No more agents") < 0)
        sosLogger.fatal(e.getMessage(), e);
      else {
        sosLogger.fatal("No more agents");
      }
      System.exit(-1);
    }
    System.out.println("============================================================");
  }
Beispiel #2
0
  private static void setConstantsFromConfig(String[] args) throws IOException {

    try {
      config = new Config(new File("sos.config"));
      CommandLineOptions.processArgs(args, config);
      // if(config.getIntValue("sos.password")==SOSConstant.PASSWORD)
      if (!SOSConstant.IS_CHALLENGE_RUNNING)
        SOSConstant.IS_CHALLENGE_RUNNING = config.getBooleanValue("sos.IS_CHALLENGE_RUNNING", true);
      if (!SOSConstant.NO_ANY_LOG)
        SOSConstant.NO_ANY_LOG = config.getBooleanValue("sos.NO_ANY_LOG", true);
    } catch (ConfigException e1) {
      sosLogger.error(e1.getMessage());
    }
  }
  @Override
  public void connect(ComponentLauncher launcher, Config config, AbstractLoader loader) {
    int count = config.getIntValue(ConfigKey.KEY_AMBULANCE_TEAM_COUNT, 0);
    int connected = 0;

    if (count == 0) {
      return;
    }

    /*
    String classStr = config.getValue(ConfigKey.KEY_AMBULANCE_TEAM_NAME);
    if (classStr == null)
    {
    	System.out.println("[ERROR] Cannot Load AmbulanceTeam Tactics !!");
    	return;
    }
    System.out.println("[START] Connect AmbulanceTeam (teamName:" + classStr + ")");
    System.out.println("[INFO ] Load AmbulanceTeam (teamName:" + classStr + ")");
    */

    try {
      if (loader.getTacticsAmbulance() == null) {
        System.out.println("[ERROR ] Cannot Load AmbulanceTeam Tactics !!");
        return;
      }
      for (int i = 0; i != count; ++i) {
        TacticsAmbulance tacticsAmbulance = loader.getTacticsAmbulance();
        boolean isPrecompute = config.getBooleanValue(ConfigKey.KEY_PRECOMPUTE, false);
        launcher.connect(new PlatoonAmbulance(tacticsAmbulance, isPrecompute));
        // System.out.println(name);
        connected++;
      }
    } catch (ComponentConnectionException | InterruptedException | ConnectionException e) {
      // e.printStackTrace();
      System.out.println("[ERROR ] Cannot Load AmbulanceTeam Tactics !!");
    }
    System.out.println("[FINISH] Connect AmbulanceTeam (success:" + connected + ")");
  }