Exemplo n.º 1
0
 private int waitForData(final Session session, final long pollInterval) throws IOException {
   int condition;
   do {
     ThreadU.sleepMillis(pollInterval);
     condition = session.waitForCondition(Const.DATA, pollInterval);
   } while ((condition & Const.DATA) != 0);
   return condition;
 }
Exemplo n.º 2
0
 @SuppressWarnings({"PMD.GuardLogStatementJavaUtil", "PMD.GuardLogStatement"})
 private Integer monitorCommand(final CommandWork commandWork, final Session session)
     throws IOException {
   final ExecutorService executorStream = context.getExecutorStream();
   final long pollInterval = context.getPollInterval();
   final ByteBuffer bufferStdin = commandWork.getByteBufferStdin();
   final ByteBuffer bufferStdout = commandWork.getByteBufferStdout();
   final ByteBuffer bufferStderr = commandWork.getByteBufferStderr();
   final OutputStream stdin = session.getStdin();
   final InputStream stdout = session.getStdout();
   final InputStream stderr = session.getStderr();
   // allow for supplemental process input
   final OutputStreamRunnable runnableStdin =
       new OutputStreamRunnable(stdin, bufferStdin, pollInterval);
   executorStream.execute(runnableStdin);
   // monitor process
   final InputStreamRunnable runnableStdout =
       new InputStreamRunnable(stdout, bufferStdout, pollInterval);
   final InputStreamRunnable runnableStderr =
       new InputStreamRunnable(stderr, bufferStderr, pollInterval);
   final InputStreamRunnable[] streams = {runnableStdout, runnableStderr};
   for (final InputStreamRunnable stream : streams) {
     executorStream.execute(stream);
   }
   // monitor process
   final int conditionExit = session.waitForCondition(ChannelCondition.EXIT_STATUS, 0L);
   logger.finest("conditionExitStatus/" + conditionExit); // i18n log
   final int conditionData = waitForData(session, runnableStdout.getPollInterval());
   logger.finest("conditionData/" + conditionData); // i18n log
   final Integer exitValue = session.getExitStatus();
   // allow process complete
   runnableStdin.stop();
   for (final InputStreamRunnable stream : streams) {
     stream.waitForComplete();
   }
   // notify caller thread
   MutexU.notifyAll(this);
   return exitValue;
 }