// Return the service configuration file if there is one
 // and only one file that matches the static-svcname.properties pattern.
 private static String lookForConfigFile() {
   File configDir = ReplicatorRuntimeConf.locateReplicatorConfDir();
   FilenameFilter propFileFilter =
       new FilenameFilter() {
         public boolean accept(File fdir, String fname) {
           if (fname.startsWith("static-") && fname.endsWith(".properties")) return true;
           else return false;
         }
       };
   File[] propertyFiles = configDir.listFiles(propFileFilter);
   if (propertyFiles.length == 1) return propertyFiles[0].getAbsolutePath();
   else return null;
 }
  /**
   * Read command line arguments in run the Loader process
   *
   * @param argv
   */
  public static void main(String[] argv) {
    LoaderCtrl loaderCtrl = null;
    THLManagerCtrl thlManager = null;

    try {
      String configFile = null;
      String service = null;
      TungstenProperties tempProperties = new TungstenProperties();

      // Parse command line arguments.
      ArgvIterator argvIterator = new ArgvIterator(argv);
      String curArg = null;
      while (argvIterator.hasNext()) {
        curArg = argvIterator.next();
        if ("-conf".equals(curArg)) configFile = argvIterator.next();
        else if ("-service".equals(curArg)) service = argvIterator.next();
        else if ("-chunk-size".equals(curArg)) {
          tempProperties.setProperty("replicator.extractor.loader.chunkSize", argvIterator.next());
        } else if (curArg.startsWith("-")) {
          String key = curArg.substring(1);
          String curValue = argvIterator.next();

          if ("extractor".equals(key)) {
            key = "replicator.extractor.loader";
          } else if (key.startsWith("extractor.")) {
            key = "replicator.extractor.loader." + key.substring(10);
          }

          tempProperties.setProperty(key, curValue);
        } else fatal("Unrecognized option: " + curArg, null);
      }

      // Use default configuration file in case user didn't specify one.
      if (configFile == null) {
        if (service == null) {
          configFile = lookForConfigFile();
          if (configFile == null) {
            fatal(
                "You must specify either a config file or a service name (-conf or -service)",
                null);
          }
        } else {
          ReplicatorRuntimeConf runtimeConf = ReplicatorRuntimeConf.getConfiguration(service);
          configFile = runtimeConf.getReplicatorProperties().getAbsolutePath();
        }
      }

      loaderCtrl = new LoaderCtrl(configFile, tempProperties);
      loaderCtrl.prepare();

      loaderCtrl.loadEvents();
    } catch (Throwable t) {
      t.printStackTrace();
      fatal("Fatal error: " + t.getMessage(), t);
    } finally {
      if (loaderCtrl != null) {
        loaderCtrl.release();
      }

      if (thlManager != null) {
        thlManager.release();
      }
    }

    succeed();
  }