public HeadlessGfsh(String name, int timeout, Properties envProps, String parentDir) throws ClassNotFoundException, IOException { this.timeout = timeout; System.setProperty("jline.terminal", GfshUnsupportedTerminal.class.getName()); this.shell = new HeadlessGfshShell(name, this, parentDir); this.shell.setEnvProperty(Gfsh.ENV_APP_RESULT_VIEWER, "non-basic"); if (envProps != null) { for (String key : envProps.stringPropertyNames()) { this.shell.setEnvProperty(key, envProps.getProperty(key)); } } // This allows us to avoid race conditions during startup - in particular a NPE on the // ConsoleReader which is // created in a separate thread during start() CountDownLatch shellStarted = new CountDownLatch(1); this.shell.addShellStatusListener((oldStatus, newStatus) -> { if (newStatus.getStatus() == Status.STARTED) { shellStarted.countDown(); } }); this.shell.start(); try { shellStarted.await(); } catch (InterruptedException e) { e.printStackTrace(System.out); } }
protected void setShellStatus(final Status shellStatus, final String msg, final ParseResult parseResult) { Assert.notNull(shellStatus, "Shell status required"); synchronized (this.shellStatus) { ShellStatus st; if (msg == null || msg.length() == 0) { st = new ShellStatus(shellStatus); } else { st = new ShellStatus(shellStatus, msg, parseResult); } if (this.shellStatus.equals(st)) { return; } for (ShellStatusListener listener : shellStatusListeners) { listener.onShellStatusChange(this.shellStatus, st); } this.shellStatus = st; } } }
public void onShellStatusChange(final ShellStatus oldStatus, final ShellStatus newStatus) { if (newStatus.getStatus().equals(Status.SHUTTING_DOWN)) { ansiOut.close(); } } };
public void run() { while (!shellStatus.getStatus().equals(Status.SHUTTING_DOWN) && !shutdownHookFired) { synchronized (flashInfoMap) { long now = System.currentTimeMillis(); Set<String> toRemove = new HashSet<String>(); for (String slot : flashInfoMap.keySet()) { FlashInfo flashInfo = flashInfoMap.get(slot); if (flashInfo.flashMessageUntil < now) { // Message has expired, so clear it toRemove.add(slot); doAnsiFlash(flashInfo.rowNumber, Level.ALL, ""); } else { // The expiration time for this message has not been reached, so preserve it doAnsiFlash(flashInfo.rowNumber, flashInfo.flashLevel, flashInfo.flashMessage); } } for (String slot : toRemove) { flashInfoMap.remove(slot); } } try { Thread.sleep(200); } catch (InterruptedException ignore) { } } } }, getProductName() + " JLine Flash Message Manager");