示例#1
0
  /**
   * Waits for the task completion. If this does not happen within the timeout, then a
   * TimeoutException is thrown.
   *
   * @param timeout Timeout for the task completion
   * @throws Exception
   */
  public void waitForTaskCompletion(long timeout) throws Exception {
    if (taskThread == null) {
      throw new IllegalStateException("Task thread was not started.");
    }

    taskThread.join(timeout);
    if (taskThread.getError() != null) {
      throw new Exception("error in task", taskThread.getError());
    }
  }
示例#2
0
  /** Clears the error status. */
  public synchronized void doClearError(StaplerRequest req, StaplerResponse rsp)
      throws IOException, ServletException {
    getACL().checkPermission(getPermission());

    if (workerThread != null && !workerThread.isRunning()) workerThread = null;
    rsp.sendRedirect(".");
  }
示例#3
0
  /**
   * Invoke the Task. This resets the output of any previous invocation. This will start a new
   * Thread to execute the Task in. Use {@link #waitForTaskCompletion()} to wait for the Task thread
   * to finish running.
   *
   * <p>Variant for providing a custom environment.
   */
  public void invoke(StreamMockEnvironment mockEnv) throws Exception {
    this.mockEnv = mockEnv;

    task.setEnvironment(mockEnv);

    initializeInputs();
    initializeOutput();

    taskThread = new TaskThread(task);
    taskThread.start();
  }
示例#4
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");
     }
   }
 }
 @Override
 public void onResume() {
   super.onResume();
   if (taskThread == null) {
     taskThread = new TaskThread();
   }
   HashMap<String, String> hashMap = new HashMap<>();
   hashMap.put("cellphone", Setting.getInstance().getUserPhone());
   // TODO 如果分页做,这里要改
   Integer integer = 1;
   Integer pageSize = 99;
   hashMap.put("pageIndex", integer.toString());
   hashMap.put("pageSize", pageSize.toString());
   taskThread.addTask(
       new HttpTask(
           Global.GET_FAVORITE_DESIGN, Global.MSG_FAVORITE, CollectionActivity.this, hashMap));
 }
示例#6
0
  /**
   * Invoke the Task. This resets the output of any previous invocation. This will start a new
   * Thread to execute the Task in. Use {@link #waitForTaskCompletion()} to wait for the Task thread
   * to finish running.
   */
  public void invoke() throws Exception {
    mockEnv =
        new StreamMockEnvironment(
            jobConfig,
            taskConfig,
            executionConfig,
            memorySize,
            new MockInputSplitProvider(),
            bufferSize);
    task.setEnvironment(mockEnv);

    initializeInputs();
    initializeOutput();

    taskThread = new TaskThread(task);
    taskThread.start();
  }
示例#7
0
  /** This only returns after all input queues are empty. */
  public void waitForInputProcessing() {

    // first wait for all input queues to be empty
    try {
      Thread.sleep(1);
    } catch (InterruptedException ignored) {
    }

    while (true) {
      boolean allEmpty = true;
      for (int i = 0; i < numInputGates; i++) {
        if (!inputGates[i].allQueuesEmpty()) {
          allEmpty = false;
        }
      }
      try {
        Thread.sleep(10);
      } catch (InterruptedException ignored) {
      }

      if (allEmpty) {
        break;
      }
    }

    // then wait for the Task Thread to be in a blocked state
    // Check whether the state is blocked, this should be the case if it cannot
    // read more input, i.e. all currently available input has been processed.
    while (true) {
      Thread.State state = taskThread.getState();
      if (state == Thread.State.BLOCKED
          || state == Thread.State.TERMINATED
          || state == Thread.State.WAITING
          || state == Thread.State.TIMED_WAITING) {
        break;
      }

      try {
        Thread.sleep(1);
      } catch (InterruptedException ignored) {
      }
    }
  }