void open()

in samza-sql-shell/src/main/java/org/apache/samza/sql/client/cli/CliShell.java [125:208]


  void open(String message) {
    // Remember we cannot enter alternate screen mode here as there is only one alternate
    // screen and we need it to show streaming results. Clear the screen instead.
    clearScreen();
    writer.write(CliConstants.WELCOME_MESSAGE);
    printVersion();
    if (!CliUtil.isNullOrEmpty(message)) {
      writer.println(message);
    }
    writer.println();

    try {
      // Check if jna.jar exists in class path
      try {
        ClassLoader.getSystemClassLoader().loadClass("com.sun.jna.NativeLibrary");
      } catch (ClassNotFoundException e) {
        // Something's wrong. It could be a dumb terminal if neither jna nor jansi lib is there
        writer.write("Warning: jna.jar does NOT exist. It may lead to a dumb shell or a performance hit.\n");
      }

      while (keepRunning) {
        String line;
        try {
          line = lineReader.readLine(firstPrompt);
        } catch (UserInterruptException e) {
          continue;
        } catch (EndOfFileException e) {
          keepRunning = false;
          break;
        }

        if (CliUtil.isNullOrEmpty(line))
          continue;

        String helpCmdText = CliCommandType.HELP.getCommandName();
        if (line.toUpperCase().startsWith(helpCmdText)) {
          if (line.toLowerCase().trim().equals(helpCmdText)) {
            printHelpMessage();
          } else {
            CommandAndHandler commandAndHandler = findHandlerForCommand(line.substring(helpCmdText.length()));
            if (commandAndHandler.handler != null) {
              commandAndHandler.handler.handleCommand(commandAndHandler.handler.parseLine(line));
            } else {
              printHelpMessage();
            }
          }
          continue;
        }

        CommandAndHandler commandAndHandler = null;
        try {
          commandAndHandler = findHandlerForCommand(line);
          if (commandAndHandler.handler == null) {
            LOG.info("no commandHandler found for command {}", line);
            printHelpMessage();
            continue;
          }
          keepRunning = commandAndHandler.handler.handleCommand(commandAndHandler.command);
        } catch (CommandHandlerException e) {
          writer.println("Error: " + e);
          LOG.error("Error in {}: ", commandAndHandler.command.getCommandType(), e);
          writer.flush();
        }
      }
    } catch (Exception e) {
      writer.print(e.getClass().getSimpleName());
      writer.print(". ");
      writer.println(e.getMessage());
      e.printStackTrace(writer);
      writer.println();
      writer.println("We are sorry but SamzaSqlShell has encountered a problem and must stop.");
    }

    writer.write("Cleaning up... ");
    writer.flush();
    try {
      executor.stop(exeContext);
      writer.write("Done.\nBye.\n\n");
      writer.flush();
      terminal.close();
    } catch (IOException | ExecutorException e) {
      // Doesn't matter
    }
  }