public boolean start(Supplier<ProcessMonitor> commandLauncher) { if (!lifecycle.tryToMoveTo(Lifecycle.State.STARTING)) { // has already been started return false; } try { this.process = commandLauncher.get(); } catch (RuntimeException e) { LOG.error("Fail to launch process [{}]", processId.getKey(), e); lifecycle.tryToMoveTo(Lifecycle.State.STOPPED); throw e; } this.stdOutGobbler = new StreamGobbler(process.getInputStream(), processId.getKey()); this.stdOutGobbler.start(); this.stdErrGobbler = new StreamGobbler(process.getErrorStream(), processId.getKey()); this.stdErrGobbler.start(); this.stopWatcher.start(); this.eventWatcher.start(); // Could be improved by checking the status "up" in shared memory. // Not a problem so far as this state is not used by listeners. lifecycle.tryToMoveTo(Lifecycle.State.STARTED); return true; }
public boolean start(Supplier<ProcessMonitor> commandLauncher) { if (!lifecycle.tryToMoveTo(Lifecycle.State.STARTING)) { // has already been started return false; } try { this.process = commandLauncher.get(); } catch (RuntimeException e) { LOG.error("Fail to launch process [{}]", processId.getKey(), e); lifecycle.tryToMoveTo(Lifecycle.State.STOPPED); throw e; } this.stdOutGobbler = new StreamGobbler(process.getInputStream(), processId.getKey()); this.stdOutGobbler.start(); this.stdErrGobbler = new StreamGobbler(process.getErrorStream(), processId.getKey()); this.stdErrGobbler.start(); this.stopWatcher.start(); this.eventWatcher.start(); // Could be improved by checking the status "up" in shared memory. // Not a problem so far as this state is not used by listeners. lifecycle.tryToMoveTo(Lifecycle.State.STARTED); return true; }