@Override public boolean hasFailed() { if (!isFinished()) { throw new IllegalStateException("Process " + processName + " is not yet finished, cannot determine whether it failed."); } // check whether we have specified exit value and if not adhere to defaults if (allowedExitCodes.isEmpty()) { return processReference.getProcess().exitValue() != 0; } return !allowedExitCodes.contains(processReference.getProcess().exitValue()); }
@Override public Execution<RESULT> terminate() throws ExecutionException { // if process has not yet started, terminate Future that would lead to its creation if (!processReference.isInitialized()) { processFutureExecution.terminate(); return markAsFinished(); } processReference.getProcess().destroy(); try { processReference.getProcess().waitFor(); } catch (InterruptedException e) { log.log(Level.WARNING, "Ignoring Interuption Exception while terminating the process {0}", processName); } // close STDIN of the process, if any OutputStream ostream = processReference.getProcess().getOutputStream(); try { if (ostream != null) { ostream.flush(); ostream.close(); } } catch (IOException e) { log.log(Level.WARNING, "Ignoring IO exception while terminating the process {0}", processName); } return this; }
@Override public boolean isFinished() { // if process is marked as finished, consider it so if (isMarkedAsFinished()) { return true; } try { if (!processReference.isInitialized()) { return false; } processReference.getProcess().exitValue(); return true; } catch (IllegalThreadStateException e) { return false; } }