@Override
  public TaskRunResult run(Task task) {

    OperationResult result =
        task.getResult().createSubresult(WaitForTasksTaskHandler.class.getName() + ".run");
    result.recordInProgress();

    LOGGER.info("WaitForTasksTaskHandler run starting; in task " + task.getName());
    try {
      // todo resolve this brutal hack
      taskManagerImpl.pauseTask(task, TaskWaitingReason.OTHER, result);
      task.startWaitingForTasksImmediate(result);
    } catch (SchemaException e) {
      throw new SystemException(
          "Couldn't mark task as waiting for prerequisite tasks",
          e); // should not occur; will be handled by task runner
    } catch (ObjectNotFoundException e) {
      throw new SystemException(
          "Couldn't mark task as waiting for prerequisite tasks",
          e); // should not occur; will be handled by task runner
    }
    LOGGER.info("WaitForTasksTaskHandler run finishing; in task " + task.getName());

    result.computeStatus();

    TaskRunResult runResult = new TaskRunResult();
    runResult.setOperationResult(result);
    runResult.setProgress(task.getProgress()); // not to overwrite task's progress
    runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
    return runResult;
  }
Exemplo n.º 2
0
  public Object runTaskNow(Task task) {
    boolean pauseThread;

    synchronized (m_lock) {
      pauseThread = m_state != STATE_STOPPED && m_state != STATE_PAUSED;

      // Wait for the worker thread to first terminate its job
      if (pauseThread) {
        // System.out.println("MainThread: Pausing WorkerThread");
        m_state = STATE_PAUSE;
        // Wait for worker thread to notify it is paused
        try {
          m_lock.wait();
        } catch (InterruptedException e) {
        }
        // if (m_state != STATE_PAUSED) {
        // System.err.println("ERROR: WorkerThread notified but not paused !!");
        // }
        // System.out.println("MainThread: WorkerThread paused");
      }
    }

    // Run the given task
    boolean retry;
    do {
      task.setState(Task.STATE_RUNNING);
      retry = false;
      try {
        task.doTheJob();
        task.setState(Task.STATE_FINISHED);
        task.onSuccess();
      } catch (Exception e) {
        task.setState(Task.STATE_ERROR);
        retry = task.onError(e);
      }
    } while (retry);

    // if we paused the worker thread, restart it
    if (pauseThread) {
      // System.out.println("MainThread: restart WorkerThread ");
      synchronized (m_lock) {
        m_state = STATE_WORK;
        m_lock.notify();
      }
    }

    return task.getResult();
  }
Exemplo n.º 3
0
 public Task then(Task task)
     throws Exception
 {
     task = (ParsePin)task.getResult();
     return val$store.findAsync(ParseQuery.this, val$user, task, val$includeIsDeletingEventually, val$ignoreACLs);
 }