@Override public void shutdown() { if (closed.compareAndSet(false, true)) { if (scheduler != null) { logger.debug("Shutting down the scheduler"); scheduler.shutdown(); } shellScope.closeAllResources(); shellHttpClient.shutdown(); console.println(); console.println(MessagesProvider.getMessage(ShellSettings.BYE_MESSAGE)); console.shutdown(); } }
protected void doRun() { while (true) { CompilableSource source = null; try { source = compilableSourceReader.read(getPrompt()); } catch (Exception e) { logger.error(e.getMessage(), e); console.println("Error while checking the input: " + e.toString()); } if (source != null) { Object jsResult = scriptExecutor.execute(source); Object javaResult = unwrap(jsResult); if (javaResult instanceof ExitSignal) { shutdown(); return; } if (javaResult != null) { console.println(javaToString(javaResult)); } } } }
protected void enablePlaygroundMode() { console.print("Enabling playground mode"); final StringBuilder messageBuilder = new StringBuilder(); new ExecutorWithProgress<Void>( console, new ExecutorWithProgress.ActionCallback<Void>() { @Override public Void execute() { Node<ShellNativeClient, JsonInput, JsonOutput> node = nodeFactory.newLocalNode(); shellScope.registerJavaObject("node", node); messageBuilder.append(node.toString()).append(" available as node").append("\n"); ShellNativeClient shellNativeClient = node.client(); shellScope.registerJavaObject("es", shellNativeClient); messageBuilder.append(shellNativeClient.toString()).append(" available as es"); return null; } }) .execute(); console.println(messageBuilder.toString()); }
protected void printLogoAndWelcomeMessage() { StringBuilder logoBuilder = new StringBuilder(); logoBuilder.append(" ___ \n"); logoBuilder.append(" // \\\\ \n"); logoBuilder .append(" (( (( )) ") .append(MessagesProvider.getMessage(ShellSettings.WELCOME_MESSAGE)); logoBuilder.append(" (( \\\\___// \n"); logoBuilder.append(" {{ // \n"); logoBuilder.append(" (( // )) \n"); logoBuilder.append(" (( // }} \n"); logoBuilder.append(" ((_______)) \n"); console.println(logoBuilder.toString()); }
/** Loads the optional startup script */ void loadStartupScript() { final String startupScript = shellSettings.settings().get(ShellSettings.STARTUP_SCRIPT); if (startupScript != null) { console.print("Loading startup script " + startupScript); new ExecutorWithProgress<Void>( console, new ExecutorWithProgress.ActionCallback<Void>() { @Override public Void execute() { try { scriptLoader.loadScript(startupScript); } catch (Throwable t) { logger.error("Error loading the startup script [{}]", startupScript, t); } return null; } }) .execute(); } }
protected void registerClient(ShellNativeClient shellNativeClient) { shellScope.registerJavaObject("es", shellNativeClient); console.println(shellNativeClient.toString() + " available as es"); }