public static void main()

in samza-sql-shell/src/main/java/org/apache/samza/sql/client/cli/Main.java [38:107]


  public static void main(String[] args) {
    // Get configuration file path
    String configFilePath = null;
    for (int i = 0; i < args.length; ++i) {
      switch (args[i]) {
        case "-conf":
          if (i + 1 < args.length) {
            configFilePath = args[i + 1];
            i++;
          }
          break;
        default:
          LOG.warn("Unknown parameter {}", args[i]);
          break;
      }
    }

    CliEnvironment environment = new CliEnvironment();
    StringBuilder messageBuilder = new StringBuilder();

    if (!CliUtil.isNullOrEmpty(configFilePath)) {
      LOG.info("Configuration file path is: {}", configFilePath);
      try {
        FileReader fileReader = new FileReader(configFilePath);
        BufferedReader bufferedReader = new BufferedReader(fileReader);
        String line;
        while ((line = bufferedReader.readLine()) != null) {
          if (line.startsWith("#") || line.startsWith("[")) {
            continue;
          }
          String[] strs = line.split("=");
          if (strs.length != 2) {
            continue;
          }
          String key = strs[0].trim().toLowerCase();
          String value = strs[1].trim();
          try {
            LOG.info("Configuration: setting {} = {}", key, value);
            int result = environment.setEnvironmentVariable(key, value);
            if (result == -1) { // CliEnvironment doesn't recognize the key.
              LOG.warn("Unknowing shell environment variable: {}", key);
            } else if (result == -2) { // Invalid value
              LOG.warn("Unknowing shell environment value: {}", value);
            }
          } catch (ExecutorException e) {
            messageBuilder.append("Warning: Failed to create executor: ").append(value).append('\n');
            messageBuilder.append("Warning: Using default executor " + CliConstants.DEFAULT_EXECUTOR_CLASS);
            LOG.error("Failed to create user specified executor {}", value, e);
          } catch (CommandHandlerException e) {
            messageBuilder.append("Warning: Failed to create CommandHandler: ").append(value).append('\n');
            LOG.error("Failed to create user specified CommandHandler {}", value, e);
          }
        }
      } catch (IOException e) {
        LOG.error("Error in opening and reading the configuration file {}", e.toString());
      }
    }

    environment.finishInitialization();
    CliShell shell;
    try {
      shell = new CliShell(environment);
    } catch (ExecutorException e) {
      System.out.println("Unable to initialize executor. Shell must exit. ");
      LOG.error("Unable to initialize executor.", e);
      return;
    }

    shell.open(messageBuilder.toString());
  }