public void run() { running = true; while (running) { lock.block(); if (!running) return; if (commandQueue.size() > 0) { console.disableEditing(); console.consoleOutputStream.enable(); boolean completeCommand = true; int completeCommandStartOffset = -1; do { Command command = commandQueue.remove(0); if (completeCommandStartOffset == -1) completeCommandStartOffset = command.commandStartOffset; try { Timing tm = new Timing(); tm.start(); completeCommand = console.interpreter.execute(command.command); long duration = tm.duration(); if (completeCommand) { console.printOutput(console.interpreter.getOutput()); if (PRINTCOMMANDTIME) { console.printOutput("Time taken: " + duration + "ms.\n"); } completeCommandStartOffset = -1; // Reset offset. } else { console.printOutput(); } } catch (CommandExecutionException ceex) { console.printOutput(ceex.getMessage()); int errorOffset = ceex.getOffset(); int errorLength = ceex.getLength(); if (errorOffset != -1 && errorLength != -1) { console.setError(completeCommandStartOffset + errorOffset, errorLength); } completeCommand = true; } catch (TerminationException tex) { // Roll over and die. console.terminate(); return; } } while (commandQueue.size() > 0); if (!running) return; console.consoleOutputStream.disable(); if (completeCommand) { console.emitPrompt(); } else { console.emitContinuationPrompt(); } console.enableEditing(); } } }
public void terminate() { running = false; lock.wakeUp(); }
public void execute() { lock.wakeUp(); }