Example #1
0
 public static ProcessTimer createTimer(TimerListener listener, double timeInSeconds) {
   ProcessTimer timer = new ProcessTimer(listener, timeInSeconds);
   timers.add(timer);
   timer.start();
   logAliveTimersCount();
   return timer;
 }
Example #2
0
 public static void removeTimer(ProcessTimer timer) {
   if (timer != null) {
     timer.close();
     timers.remove(timer);
   }
   logAliveTimersCount();
 }
Example #3
0
 /**
  * Waits until the process is terminated or the timeout is elapsed.
  *
  * @return The exit code of the process
  */
 public int waitFor() {
   int exitCode = -1;
   if (process != null) {
     try {
       exitCode = process.waitFor();
       logger.debug("Closing errorStream...");
       errorStream.close();
       logger.debug("Closing outputStream...");
       outputStream.close();
     } catch (InterruptedException e) {
       e.printStackTrace();
     }
     ProcessTimer.removeTimer(timer);
     logger.debug("TProcess ended: exitCode = " + exitCode);
   } else {
     ErrorsAndWarnings.addError("Cannot call waitFor() on a null TProcess");
   }
   return exitCode;
 }
Example #4
0
 /** Destroys the process */
 public void stop() {
   ProcessTimer.removeTimer(timer);
   try {
     Thread.sleep(StreamListener.PRINTING_PERIOD_IN_MILLIS);
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
   if (errorStream != null) {
     logger.debug("Closing errorStream...");
     errorStream.close();
   }
   if (outputStream != null) {
     logger.debug("Closing outputStream...");
     outputStream.close();
   }
   if (process != null) {
     logger.debug("destroying TProcess...");
     process.destroy();
     logger.debug("TProcess destroyed");
   }
 }
Example #5
0
 /**
  * Creates a TProcess, composed by the Process and one timer. Call waitFor() to wait until the
  * process returns.
  *
  * @param processToManage The process to destroy after timeout
  * @param timeoutInSeconds The timeout in seconds (precision is millisecond)
  */
 public TProcess(Process processToManage, double timeoutInSeconds) {
   process = processToManage;
   timer = ProcessTimer.createTimer(this, timeoutInSeconds);
 }