Exemplo n.º 1
0
 protected Task schedule(SpoutTask task) {
   ParallelTaskInfo info = new ParallelTaskInfo(task);
   if (task.getPeriod() > 0) {
     activeTasks.put(task.getTaskId(), info);
   }
   newTasks.add(task);
   return task;
 }
Exemplo n.º 2
0
 public void heartbeat(long delta) {
   if (engine != null) {
     TickStage.checkStage(TickStage.TICKSTART);
   } else {
     TickStage.checkStage(TickStage.STAGE1);
   }
   SpoutRegion region;
   SpoutTask task;
   while ((task = newTasks.poll()) != null) {
     int taskId = task.getTaskId();
     ParallelTaskInfo info = activeTasks.get(taskId);
     if (info == null) {
       info = new ParallelTaskInfo(task);
       ParallelTaskInfo previous = activeTasks.putIfAbsent(taskId, info);
       if (previous != null) {
         info = previous;
       }
       task.setParallelInfo(info);
     }
     Collection<? extends World> worlds = (this.world == null) ? engine.getWorlds() : world;
     for (World w : worlds) {
       SpoutWorld sw = (SpoutWorld) w;
       for (Region r : sw.getRegions()) {
         info.add((SpoutRegion) r);
       }
     }
   }
   while ((region = newRegions.poll()) != null) {
     for (ParallelTaskInfo info : activeTasks.values(ParallelTaskInfo.EMPTY_ARRAY)) {
       info.add(region);
     }
   }
   while ((region = deadRegions.poll()) != null) {
     while (newRegions.remove(region)) {;
     }
     for (ParallelTaskInfo info : activeTasks.values(ParallelTaskInfo.EMPTY_ARRAY)) {
       while (info.remove(region)) {;
       }
     }
   }
 }