コード例 #1
0
  public TaskInfo getTaskToExecute(Spec<TaskInfo> criteria) {
    lock.lock();
    try {

      TaskInfo nextMatching;
      while ((nextMatching = getNextReadyAndMatching(criteria)) != null) {
        while (!nextMatching.allDependenciesComplete()) {
          try {
            condition.await();
          } catch (InterruptedException e) {
            throw new RuntimeException(e);
          }
        }

        // The task state could have been modified while we waited for dependency completion. Check
        // that it is still 'ready'.
        if (!nextMatching.isReady()) {
          continue;
        }

        if (nextMatching.allDependenciesSuccessful()) {
          nextMatching.startExecution();
          return nextMatching;
        } else {
          nextMatching.skipExecution();
          condition.signalAll();
        }
      }

      return null;

    } finally {
      lock.unlock();
    }
  }
コード例 #2
0
 private void abortExecution() {
   // Allow currently executing tasks to complete, but skip everything else.
   for (TaskInfo taskInfo : executionPlan.values()) {
     if (taskInfo.isReady()) {
       taskInfo.skipExecution();
     }
   }
 }
コード例 #3
0
 private TaskInfo getNextReadyAndMatching(Spec<TaskInfo> criteria) {
   for (TaskInfo taskInfo : executionPlan.values()) {
     if (taskInfo.isReady() && criteria.isSatisfiedBy(taskInfo)) {
       return taskInfo;
     }
   }
   return null;
 }
コード例 #4
0
 public TaskInfo getTaskToExecute() {
   lock.lock();
   try {
     while (true) {
       TaskInfo nextMatching = null;
       boolean allTasksComplete = true;
       for (TaskInfo taskInfo : executionPlan.values()) {
         allTasksComplete = allTasksComplete && taskInfo.isComplete();
         if (taskInfo.isReady()
             && taskInfo.allDependenciesComplete()
             && !runningProjects.contains(taskInfo.getTask().getProject().getPath())) {
           nextMatching = taskInfo;
           break;
         }
       }
       if (allTasksComplete) {
         return null;
       }
       if (nextMatching == null) {
         try {
           condition.await();
         } catch (InterruptedException e) {
           throw new RuntimeException(e);
         }
       } else {
         if (nextMatching.allDependenciesSuccessful()) {
           nextMatching.startExecution();
           runningProjects.add(nextMatching.getTask().getProject().getPath());
           return nextMatching;
         } else {
           nextMatching.skipExecution();
           condition.signalAll();
         }
       }
     }
   } finally {
     lock.unlock();
   }
 }