Пример #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
 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();
   }
 }