/**
   * @param args
   * @throws InterruptedException
   */
  public static void main(String[] args) throws InterruptedException {

    String conf = "spring.xml";
    AbstractApplicationContext context = new ClassPathXmlApplicationContext(conf);
    ConfigurableEnvironment configurableEnvironment = new StandardEnvironment();
    boolean testMode = false;

    if (args != null && args.length > 0) {
      if ("-test".equals(args[0])) {
        configurableEnvironment.setActiveProfiles("TEST");
        testMode = true;
      } else {
        configurableEnvironment.setActiveProfiles("PROD");
      }
    } else {
      configurableEnvironment.setActiveProfiles("PROD");
    }
    context.setEnvironment(configurableEnvironment);

    PropertyConfigurator.configure("resources/log4j.properties");

    logger.info("Starting launcher...");

    int iteration = 0;

    Launcher launcher = context.getBean("launcher", Launcher.class);

    while (true) {

      iteration++;

      logger.info("Iteration #" + iteration + " at " + new Date());

      logger.info(" Launching zezo automatic routing...");
      launcher.runZezoAutoRouting(testMode);

      /*
       * logger.info(" Launching waypoints..."); launcher.runWaypoints();
       *
       * logger.info(" Launching speed regulation...");
       * launcher.speedRegulation();
       */

      Date nextIteration = getNextIteration();
      long msToSleep = getSecondRemainingBefore(nextIteration);
      logger.info("Waiting for next iteration at " + nextIteration + "\n\n\n");
      Thread.sleep(msToSleep);
    }
  }
 private void prependProfile(ConfigurableEnvironment environment, String profile) {
   Set<String> profiles = new LinkedHashSet<String>();
   environment.getActiveProfiles(); // ensure they are initialized
   // But this one should go first (last wins in a property key clash)
   profiles.add(profile);
   profiles.addAll(Arrays.asList(environment.getActiveProfiles()));
   environment.setActiveProfiles(profiles.toArray(new String[profiles.size()]));
 }
 private void applySpringProfiles(
     ConfigurableEnvironment environment, ServletContext servletContext) {
   if (environment.containsProperty("spring_profiles")) {
     String profiles = environment.getProperty("spring_profiles");
     servletContext.log("Setting active profiles: " + profiles);
     environment.setActiveProfiles(StringUtils.commaDelimitedListToStringArray(profiles));
   }
 }
 @Override
 public void initialize(ConfigurableWebApplicationContext ctx) {
   ConfigurableEnvironment environment = ctx.getEnvironment();
   environment.setActiveProfiles("prod");
 }
 @Override
 public void initialize(ConfigurableApplicationContext applicationContext) {
   ConfigurableEnvironment environment = applicationContext.getEnvironment();
   environment.setActiveProfiles("alarms-" + environment.getProperty("httpd.alarms.db.type"));
 }