Ejemplo n.º 1
0
  public static void main(String[] args) {
    int counter = 10000;
    Product product = null;

    Options options = new Options();
    options.addOption("p", "product", true, "Class name of the product to use for benchmark");
    options.addOption("n", true, "Number of repetitions");

    Parser parser = new PosixParser();
    try {
      CommandLine commandLine = parser.parse(options, args);
      if (commandLine.hasOption('p')) {
        product = (Product) Class.forName(commandLine.getOptionValue('p')).newInstance();
      }
      if (commandLine.hasOption('n')) {
        counter = Integer.parseInt(commandLine.getOptionValue('n'));
      }
    } catch (ParseException e) {
      e.printStackTrace();
    } catch (InstantiationException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    }

    Harness harness = new Harness();
    // harness.addMetric(new SerializationSpeedMetric(1) {
    // public String toString() {
    // return "Initial run serialization";
    // }
    // });
    // harness.addMetric(new DeserializationSpeedMetric(1, false) {
    // public String toString() {
    // return "Initial run deserialization";
    // }
    // });
    harness.addMetric(new SerializationSpeedMetric(counter));
    harness.addMetric(new DeserializationSpeedMetric(counter, false));
    if (product == null) {
      harness.addProduct(new NoCache());
      harness.addProduct(new Cache122());
      harness.addProduct(new RealClassCache());
      harness.addProduct(new SerializedClassCache());
      harness.addProduct(new AliasedAttributeCache());
      harness.addProduct(new DefaultImplementationCache());
      harness.addProduct(new NoCache());
    } else {
      harness.addProduct(product);
    }
    harness.addTarget(new BasicTarget());
    harness.addTarget(new ExtendedTarget());
    harness.addTarget(new ReflectionTarget());
    harness.addTarget(new SerializableTarget());
    harness.run(new TextReporter(new PrintWriter(System.out, true)));
    System.out.println("Done.");
  }
Ejemplo n.º 2
0
  public static final void main(String args[]) throws Exception {
    Parser parser = new GnuParser();
    Options opts = getOptions();
    CommandLine cmdl = null;
    try {
      cmdl = parser.parse(opts, args);
    } catch (Exception e) {
      printHelp(opts);
      System.exit(1);
    }

    MetadataImporter mi = new MetadataImporter();
    mi.setConnectionURL(cmdl.getOptionValue('c', "http://demo.crt.realtors.org:6103/login"));
    mi.setUsername(cmdl.getOptionValue('u', "Joe"));
    mi.setPassword(cmdl.getOptionValue('p', "Schmoe"));
    if (cmdl.hasOption('f')) {
      mi.setFile(cmdl.getOptionValue('f'));
    }
    mi.doIt();
  }
  public void run(String[] args) throws Exception {
    if (args.length == 0 || CommandLineInterfaceLibrary.wantsHelp(args)) {
      printUsage();
      System.exit(-1);
    }

    Options options = new Options();
    buildOptions(options);
    Daemonizer.buildOptions(options);
    Parser parser = new GnuParser();
    final CommandLine cli = parser.parse(options, args);
    Daemonizer.handleDaemonization(cli);

    Set<Module> modules = new HashSet<>();
    WMATARealtimeModule.addModuleAndDependencies(modules);

    _injector =
        Guice.createInjector(
            new URLConverter(),
            new FileConverter(),
            new PropertiesConverter(),
            new ConfigurationModule() {
              @Override
              protected void bindConfigurations() {
                bindEnvironmentVariables();
                bindSystemProperties();

                if (cli.hasOption(ARG_CONFIG_FILE)) {
                  bindProperties(new File(cli.getOptionValue(ARG_CONFIG_FILE)));
                }
              }
            },
            Rocoto.expandVariables(modules));

    _injector.injectMembers(this);

    _tripUpdatesUrl = getConfigurationValue(URL.class, "tripUpdates.url");
    if (_tripUpdatesUrl != null) {
      GtfsRealtimeServlet servlet = _injector.getInstance(GtfsRealtimeServlet.class);
      servlet.setUrl(_tripUpdatesUrl);
      servlet.setSource(_tripUpdatesExporter);
    }

    _tripUpdatesPath = getConfigurationValue(File.class, "tripUpdates.path");
    if (_tripUpdatesPath != null) {
      GtfsRealtimeFileWriter writer = _injector.getInstance(GtfsRealtimeFileWriter.class);
      writer.setPath(_tripUpdatesPath);
      writer.setSource(_tripUpdatesExporter);
    }

    _vehiclePositionsUrl = getConfigurationValue(URL.class, "vehiclePositions.url");
    if (_vehiclePositionsUrl != null) {
      GtfsRealtimeServlet servlet = _injector.getInstance(GtfsRealtimeServlet.class);
      servlet.setUrl(_vehiclePositionsUrl);
      servlet.setSource(_vehiclePositionsExporter);
    }

    _vehiclePositionsPath = getConfigurationValue(File.class, "vehiclePositions.path");
    if (_vehiclePositionsPath != null) {
      GtfsRealtimeFileWriter writer = _injector.getInstance(GtfsRealtimeFileWriter.class);
      writer.setPath(_vehiclePositionsPath);
      writer.setSource(_vehiclePositionsExporter);
    }

    _alertsUrl = getConfigurationValue(URL.class, "alerts.url");
    if (_alertsUrl != null) {
      GtfsRealtimeServlet servlet = _injector.getInstance(GtfsRealtimeServlet.class);
      servlet.setUrl(_alertsUrl);
      servlet.setSource(_alertsExporter);
    }

    _alertsPath = getConfigurationValue(File.class, "alerts.path");
    if (_alertsPath != null) {
      GtfsRealtimeFileWriter writer = _injector.getInstance(GtfsRealtimeFileWriter.class);
      writer.setPath(_alertsPath);
      writer.setSource(_alertsExporter);
    }

    _lifecycleService.start();
  }
Ejemplo n.º 4
0
  @SuppressWarnings("unchecked")
  public static void main(String... args) throws ParseException, JoranException, IOException {
    Parser parser = new BasicParser();
    CommandLine cl = null;
    try {
      cl = parser.parse(OPTS, args);
    } catch (ParseException e) {
      HelpFormatter help = new HelpFormatter();
      help.printHelp("dlog", OPTS, true);
      System.exit(-1);
    }

    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
    loggerContext.reset();

    if (cl.hasOption("config")) {
      // Read Logback configuration
      JoranConfigurator configurator = new JoranConfigurator();
      configurator.setContext(loggerContext);

      configurator.doConfigure(cl.getOptionValue("file", "logback.xml"));

      StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext);
    } else {
      BasicConfigurator.configure(loggerContext);
    }

    Appender appender = null;
    if (cl.hasOption("output")) {
      String outputAppender = cl.getOptionValue("output", "console");
      appender = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME).getAppender(outputAppender);
    }

    ChronicleTools.warmup();
    Chronicle chronicle = new IndexedChronicle(cl.getOptionValue("path"), ChronicleConfig.DEFAULT);
    ExcerptTailer ex = chronicle.createTailer();

    Level level = Level.valueOf(cl.getOptionValue("level", "TRACE"));

    if (cl.hasOption("head")) {
      int lines = Integer.parseInt(cl.getOptionValue("head", "10"));
      for (int i = 0; i < lines; i++) {
        LoggingEvent evt = readLoggingEvent(ex, loggerContext);
        if (evt.getLevel().isGreaterOrEqual(level)) {
          writeEvent(evt, appender);
        }
      }
    } else if (cl.hasOption("tail")) {
      int lines = Integer.parseInt(cl.getOptionValue("tail", "10"));
      Queue<LoggingEvent> tail = new LinkedBlockingQueue<LoggingEvent>(lines);
      while (ex.nextIndex()) {
        LoggingEvent evt = readLoggingEvent(ex, loggerContext);
        if (!tail.offer(evt)) {
          tail.poll();
          tail.add(evt);
        }
      }
      LoggingEvent evt;
      while (null != (evt = tail.poll())) {
        if (evt.getLevel().isGreaterOrEqual(level)) {
          writeEvent(evt, appender);
        }
      }
    } else if (cl.hasOption("search")) {
      String regex = cl.getOptionValue("search");
      Pattern regexPatt = Pattern.compile(regex);
      while (ex.nextIndex()) {
        LoggingEvent evt = readLoggingEvent(ex, loggerContext);
        if (null != evt && evt.getLevel().isGreaterOrEqual(level)) {
          if (regexPatt.matcher(evt.getFormattedMessage()).matches()) {
            writeEvent(evt, appender);
          }
        }
      }
    }

    loggerContext.stop();
    chronicle.close();
  }
  public void run(String[] args) throws Exception {

    try {
      Parser parser = new GnuParser();

      Options options = new Options();
      buildOptions(options);

      CommandLine commandLine = parser.parse(options, args);

      String[] remainingArgs = commandLine.getArgs();

      if (remainingArgs.length < 2) {
        printUsage();
        System.exit(-1);
      }

      FederatedTransitDataBundleCreator creator = new FederatedTransitDataBundleCreator();

      Map<String, BeanDefinition> beans = new HashMap<String, BeanDefinition>();
      creator.setContextBeans(beans);

      List<GtfsBundle> gtfsBundles = new ArrayList<GtfsBundle>();
      List<String> contextPaths = new ArrayList<String>();

      for (int i = 0; i < remainingArgs.length - 1; i++) {
        File path = new File(remainingArgs[i]);
        if (path.isDirectory() || path.getName().endsWith(".zip")) {
          GtfsBundle gtfsBundle = new GtfsBundle();
          gtfsBundle.setPath(path);
          gtfsBundles.add(gtfsBundle);
        } else {
          contextPaths.add("file:" + path);
        }
      }

      if (!gtfsBundles.isEmpty()) {
        BeanDefinitionBuilder bean = BeanDefinitionBuilder.genericBeanDefinition(GtfsBundles.class);
        bean.addPropertyValue("bundles", gtfsBundles);
        beans.put("gtfs-bundles", bean.getBeanDefinition());
      }

      if (commandLine.hasOption(ARG_USE_DATABASE_FOR_GTFS)) {
        contextPaths.add("classpath:org/onebusaway/gtfs/application-context.xml");
      } else {
        BeanDefinitionBuilder bean =
            BeanDefinitionBuilder.genericBeanDefinition(GtfsRelationalDaoImpl.class);
        beans.put("gtfsRelationalDaoImpl", bean.getBeanDefinition());
      }

      if (commandLine.hasOption(ARG_DATASOURCE_URL)) {
        String dataSourceUrl = commandLine.getOptionValue(ARG_DATASOURCE_URL);
        BeanDefinitionBuilder bean =
            BeanDefinitionBuilder.genericBeanDefinition(DriverManagerDataSource.class);
        bean.addPropertyValue("url", dataSourceUrl);
        if (commandLine.hasOption(ARG_DATASOURCE_DRIVER_CLASS_NAME))
          bean.addPropertyValue(
              "driverClassName", commandLine.getOptionValue(ARG_DATASOURCE_DRIVER_CLASS_NAME));
        if (commandLine.hasOption(ARG_DATASOURCE_USERNAME))
          bean.addPropertyValue("username", commandLine.getOptionValue(ARG_DATASOURCE_USERNAME));
        if (commandLine.hasOption(ARG_DATASOURCE_PASSWORD))
          bean.addPropertyValue("password", commandLine.getOptionValue(ARG_DATASOURCE_PASSWORD));
        beans.put("dataSource", bean.getBeanDefinition());
      }

      if (commandLine.hasOption(ARG_OSM)) {
        File osmPath = new File(commandLine.getOptionValue(ARG_OSM));
        BeanDefinitionBuilder bean =
            BeanDefinitionBuilder.genericBeanDefinition(FileBasedOpenStreetMapProviderImpl.class);
        bean.addPropertyValue("path", osmPath);
        beans.put("osmProvider", bean.getBeanDefinition());
      }

      File outputPath = new File(remainingArgs[remainingArgs.length - 1]);

      if (commandLine.hasOption(ARG_ONLY_IF_DNE) && outputPath.exists()) {
        System.err.println("Bundle path already exists.  Exiting...");
        System.exit(0);
      }

      if (commandLine.hasOption(ARG_RANDOMIZE_CACHE_DIR)) creator.setRandomizeCacheDir(true);

      if (commandLine.hasOption(ARG_BUNDLE_KEY)) {
        String key = commandLine.getOptionValue(ARG_BUNDLE_KEY);
        creator.setBundleKey(key);
      }

      /**
       * Optionally override any system properties (ok this duplicates existing functionality, yes,
       * but it allows for -D arguments after the main class)
       */
      if (commandLine.hasOption("D")) {
        Properties props = commandLine.getOptionProperties("D");
        for (Object key : props.keySet()) {
          String propName = (String) key;
          String propValue = props.getProperty(propName);
          System.setProperty(propName, propValue);
        }
      }

      /**
       * Optionally override any system properties (ok this duplicates existing functionality, yes,
       * but it allows for -D arguments after the main class)
       */
      if (commandLine.hasOption("P")) {
        Properties props = commandLine.getOptionProperties("P");
        creator.setAdditionalBeanPropertyOverrides(props);
      }

      setStagesToSkip(commandLine, creator);

      creator.setOutputPath(outputPath);
      creator.setContextPaths(contextPaths);

      try {

        if (commandLine.hasOption(ARG_ADDITIONAL_RESOURCES_DIRECTORY)) {
          File additionalResourceDirectory =
              new File(commandLine.getOptionValue(ARG_ADDITIONAL_RESOURCES_DIRECTORY));
          copyFiles(additionalResourceDirectory, outputPath);
        }

        creator.run();
      } catch (Exception ex) {
        _log.error("error building transit data bundle", ex);
        System.exit(-1);
      }
    } catch (ParseException ex) {
      System.err.println(ex.getLocalizedMessage());
      printUsage();
      System.exit(-1);
    }

    System.exit(0);
  }