Пример #1
0
 private void checkDoneActors() {
   synchronized (TimelineEngine.LOCK) {
     for (Iterator<TimelineScenarioActor> itRunning = this.runningActors.iterator();
         itRunning.hasNext(); ) {
       TimelineScenarioActor stillRunning = itRunning.next();
       if (stillRunning.isDone()) {
         itRunning.remove();
         this.doneActors.add(stillRunning);
       }
     }
   }
 }
Пример #2
0
 public void playLoop() {
   for (TimelineScenarioActor actor : this.waitingActors) {
     if (!actor.supportsReplay())
       throw new UnsupportedOperationException(
           "Can't loop scenario with actor(s) that don't support replay");
   }
   this.isLooping = true;
   this.state = TimelineScenarioState.PLAYING;
   TimelineEngine.getInstance()
       .runTimelineScenario(
           this,
           new Runnable() {
             @Override
             public void run() {
               TimelineEngine.getInstance().playScenario(TimelineScenario.this);
             }
           });
 }
Пример #3
0
  Set<TimelineScenarioActor> getReadyActors() {
    synchronized (TimelineEngine.LOCK) {
      if (this.state == TimelineScenarioState.SUSPENDED)
        return new HashSet<TimelineScenarioActor>();

      this.checkDoneActors();

      Set<TimelineScenarioActor> result = new HashSet<TimelineScenarioActor>();
      for (Iterator<TimelineScenarioActor> itWaiting = this.waitingActors.iterator();
          itWaiting.hasNext(); ) {
        TimelineScenarioActor waitingActor = itWaiting.next();
        boolean canRun = true;
        Set<TimelineScenarioActor> toWaitFor = this.dependencies.get(waitingActor);
        if (toWaitFor != null) {
          for (TimelineScenarioActor actorToWaitFor : toWaitFor) {
            if (!doneActors.contains(actorToWaitFor)) {
              canRun = false;
              break;
            }
          }
        }
        if (canRun) {
          runningActors.add(waitingActor);
          itWaiting.remove();
          result.add(waitingActor);
        }
      }

      if (this.waitingActors.isEmpty() && this.runningActors.isEmpty()) {
        if (!this.isLooping) {
          this.state = TimelineScenarioState.DONE;
        } else {
          for (TimelineScenarioActor done : this.doneActors) done.resetDoneFlag();
          this.waitingActors.addAll(this.doneActors);
          this.doneActors.clear();
        }
      }

      return result;
    }
  }
Пример #4
0
 public void addScenarioActor(TimelineScenarioActor actor) {
   if (actor.isDone()) {
     throw new IllegalArgumentException("Already finished");
   }
   this.waitingActors.add(actor);
 }