Exemplo n.º 1
0
 /**
  * Waits fro the task to be running. If this does not happen within the timeout, then a
  * TimeoutException is thrown.
  *
  * @param timeout Timeout for the task to be running.
  * @throws Exception
  */
 public void waitForTaskRunning(long timeout) throws Exception {
   if (taskThread == null) {
     throw new IllegalStateException("Task thread was not started.");
   } else {
     if (taskThread.task instanceof StreamTask) {
       StreamTask<?, ?> streamTask = (StreamTask<?, ?>) taskThread.task;
       while (!streamTask.isRunning()) {
         Thread.sleep(100);
         if (!taskThread.isAlive()) {
           if (taskThread.getError() != null) {
             throw new Exception("Task Thread failed due to an error.", taskThread.getError());
           } else {
             throw new Exception("Task Thread unexpectedly shut down.");
           }
         }
       }
     } else {
       throw new IllegalStateException("Not a StreamTask");
     }
   }
 }