public static void updateWorkQueue(ArrayList<String> newTaskUrl) {
   for (ImageLoadTask task : mHashMap.values()) {
     if (!newTaskUrl.contains(task.mImageUrl)) {
       mWorkQueue.remove(task);
       mHashMap.remove(task.mImageUrl);
     }
   }
 }
Exemple #2
0
    public void run() {
      while (stillAlive.get()) {
        synchronized (this) {
          try {
            ScheduledJob job = schedule.peek();

            if (job == null) {
              // If null, wake up every minute or so to see if there's something to do.
              // Most likely there will not be.
              try {
                this.wait(TIMEOUT_MS);
              } catch (InterruptedException e) {
                // interruption should occur when items are added or removed from the queue.
              }
            } else {
              // We've passed the job execution time, so we will run.
              if (!job.getScheduledExecution().isAfterNow()) {
                // Run job. The invocation of jobs should be quick.
                ScheduledJob runningJob = schedule.poll();
                logger.info("Scheduler attempting to run " + runningJob.getId());

                // Execute the job here
                try {
                  executionManager.execute(runningJob.getId(), runningJob.isDependencyIgnored());
                } catch (JobExecutionException e) {
                  logger.info("Could not run job. " + e.getMessage());
                }
                schedule.remove(job);

                // Immediately reschedule if it's possible. Let the execution manager
                // handle any duplicate runs.
                if (runningJob.updateTime()) {
                  schedule.add(runningJob);
                }
                saveSchedule();
              } else {
                // wait until job run
                long millisWait =
                    Math.max(
                        0, job.getScheduledExecution().getMillis() - (new DateTime()).getMillis());
                try {
                  this.wait(Math.min(millisWait, TIMEOUT_MS));
                } catch (InterruptedException e) {
                  // interruption should occur when items are added or removed from the queue.
                }
              }
            }
          } catch (Exception e) {
            logger.error("Unexpected exception has been thrown in scheduler", e);
          } catch (Throwable e) {
            logger.error("Unexpected throwable has been thrown in scheduler", e);
          }
        }
      }
    }
Exemple #3
0
  private synchronized void splitFinished(PrioritizedSplitRunner split) {
    allSplits.remove(split);
    pendingSplits.remove(split);

    TaskHandle taskHandle = split.getTaskHandle();
    taskHandle.splitComplete(split);

    wallTime.add(System.nanoTime() - split.createdNanos);

    scheduleTaskIfNecessary(taskHandle);

    addNewEntrants();
  }
Exemple #4
0
  public void trouverVoisinEtMaj(Vecteur point) {
    /* Autour du point (i,j) */
    int x = (int) point.getX();
    int y = (int) point.getY();
    /* Boucle: pour di allant de -1 à 1 et dj allant de -1 à 1 */
    for (int di = -1; di <= 1; di++) {
      for (int dj = -1; dj <= 1; dj++) {
        Vecteur d = new Vecteur(x + di, y + dj);
        /* Eliminer les indices inintéressants (continue) */
        if (di == 0 && dj == 0) {
          continue;
        }
        /* Eliminer les mauvais voisins */
        if (!ToolsTerrain.isRunnable(circuit.getTerrain(d))) {
          continue;
        }

        if ((di + x >= circuit.getHeight())
            || (dj + y >= circuit.getWidth())
            || (di + x < 0)
            || (dj + y < 0)) {
          continue;
        }
        if (dist[x][y] == 0) {
          if (VTools.prodScal(circuit.getDirectionArrivee(), new Vecteur(di, dj)) > 0) {
            continue;
          }
        }
        /* Compare la nouvelle distance avec la distance actuelle */
        int poids = poids(di, dj);
        if (dist[x + di][y + dj] > dist[x][y] + poids) {
          q.remove(d);
          dist[x + di][y + dj] = dist[x][y] + poids;
          q.add(d);
        }
      }
    }
  }
  private void updateStatus(DataNodeIdentifier oldNode, DataNodeIdentifier replacementNode) {
    int segmentsPerSegmentGroup = coordinator.getSegmentsPerSegmentGroup();

    DataNodeStatusPair oldPair = null;
    DataNodeStatusPair newPair = null;

    for (DataNodeStatusPair eachPair : datanodeStatuses) {
      if (oldNode.equals(eachPair.getIdentifier())) {
        oldPair = eachPair;
      } else if (replacementNode.equals(eachPair.getIdentifier())) {
        newPair = eachPair;
      }
    }

    oldPair.getStatus().addStoredSegments(-1 * segmentsPerSegmentGroup);
    newPair.getStatus().addStoredSegments(segmentsPerSegmentGroup);

    datanodeStatuses.remove(oldPair);
    datanodeStatuses.remove(newPair);

    datanodeStatuses.add(oldPair);
    datanodeStatuses.add(newPair);
  }
 /**
  * Remove scheduled jobs. Does not interrupt.
  *
  * @param job
  */
 public synchronized void removeScheduledJob(ScheduledJob job) {
   logger.info("Removing " + job + " from the schedule.");
   schedule.remove(job);
   // Don't need to interrupt, because if this is originally on the top of the queue,
   // it'll just skip it.
 }
Exemple #7
0
 public static void cancelRendering(JobRequester requester) {
   // Remove all previous jobs requested by this same requester
   for (JobRequest j : renderQ.toArray(new JobRequest[0])) {
     if (j.requester == requester) renderQ.remove(j);
   }
 }