Ejemplo n.º 1
0
  public static void addImage(BufferedImage img, UtmPose pose) {

    if (imagesDir != null) {
      try {
        File outputfile =
            new File(
                imagesDir.getAbsolutePath() + File.separator + "BoatImg" + (new Date()) + ".png");
        System.out.println("Writing to " + outputfile + " " + pose);
        ImageIO.write(img, "png", outputfile);
      } catch (IOException e) {
        System.out.println("Failed to write image to file: " + e);
      }
    } else {
      System.out.println("Do not know where to save images");
    }

    if (queue.size() > 100) {
      int v = rateS.getValue();
      int nv = Math.min(100, Math.max(v, (rateS.getValue() / 10)));
      if (v != nv) {
        rateS.setValue(nv);
      }
    }

    if (queue.size() < 1000) {
      queue.offer(new BufferedImageWithPose(img, pose));
      queueP.setValue(Math.min(100, queue.size()));
    } else {
      System.out.println("No longer queuing images, queue is full");
    }
  }
  private DataNodeIdentifier pickHeaviestLoad(DataNodeIdentifier otherNode) {
    DataNodeIdentifier replacementNode = null;

    PriorityBlockingQueue<DataNodeStatusPair> invertedStatusQueue =
        new PriorityBlockingQueue<DataNodeStatusPair>(
            datanodeStatuses.size(),
            new Comparator<DataNodeStatusPair>() {
              public int compare(DataNodeStatusPair a, DataNodeStatusPair b) {
                return -1 * a.compareTo(b);
              }
            });

    for (DataNodeStatusPair each : datanodeStatuses) {
      invertedStatusQueue.put(each);
    }

    while (replacementNode == null) {
      DataNodeStatusPair next = invertedStatusQueue.poll();
      DataNodeIdentifier nextId = next.getIdentifier();
      if (!nextId.equals(otherNode)) {
        replacementNode = nextId;
      }
    }

    return replacementNode;
  }
 public static void submitTask(String fileUrl, ImageLoadTask task) {
   Log.e(TAG, "execute a ImageLoadTask ! sWorkQueue.size() = " + mWorkQueue.size());
   if (mHashMap.get(fileUrl) == null) {
     mHashMap.put(fileUrl, task);
     mExecutor.execute(task);
   } else {
     Log.e(TAG, "there is already a task running !");
   }
 }
Ejemplo n.º 4
0
 public static BufferedImage getImage() {
   try {
     BufferedImage b = queue.take().img;
     queueP.setValue(Math.min(100, queue.size()));
     return b;
   } catch (InterruptedException e) {
   }
   return null;
 }
Ejemplo n.º 5
0
 @Override
 public synchronized String toString() {
   return Objects.toStringHelper(this)
       .add("runnerThreads", runnerThreads)
       .add("allSplits", allSplits.size())
       .add("pendingSplits", pendingSplits.size())
       .add("runningSplits", runningSplits.size())
       .add("blockedSplits", blockedSplits.size())
       .toString();
 }
  public static void main(String[] args) {

    PriorityBlockingQueue<Event> queue = new PriorityBlockingQueue<Event>();

    Thread[] taskThreads = new Thread[5];

    // 初始这 5 个任务线程。
    for (int i = 0; i < taskThreads.length; i++) {
      Task task = new Task(i, queue);
      taskThreads[i] = new Thread(task);
    }

    // 启动这 5 个任务线程。
    for (Thread t : taskThreads) {
      t.start();
    }

    // 使用 join() 方法,让 main 线程等待 5 个任务线程结束。
    for (Thread t : taskThreads) {
      try {
        t.join();
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }

    System.out.printf("Main: Queue Size: %d\n", queue.size());

    for (int i = 0; i < taskThreads.length * 1000; i++) {
      Event event = queue.poll();
      System.out.printf("Thread %s: Priority %d\n", event.getThread(), event.getPriority());
    }

    System.out.printf("Main: Queue Size: %d\n", queue.size());
    System.out.printf("Main: End of the program\n");
  }
Ejemplo n.º 7
0
  /**
   * Submit a MeasurementTask to the scheduler. Caller of this method can broadcast an intent with
   * MEASUREMENT_ACTION to start the measurement immediately.
   */
  public boolean submitTask(MeasurementTask task) {
    try {
      // Immediately handles measurements created by user
      if (task.getDescription().priority == MeasurementTask.USER_PRIORITY) {
        return this.taskQueue.add(task);
      }

      if (taskQueue.size() >= Config.MAX_TASK_QUEUE_SIZE
          || pendingTasks.size() >= Config.MAX_TASK_QUEUE_SIZE) {
        return false;
      }
      // Automatically notifies the scheduler waiting on taskQueue.take()
      return this.taskQueue.add(task);
    } catch (NullPointerException e) {
      Logger.e("The task to be added is null");
      return false;
    } catch (ClassCastException e) {
      Logger.e("cannot compare this task against existing ones");
      return false;
    }
  }
Ejemplo n.º 8
0
 @Managed
 public int getPendingSplits() {
   return pendingSplits.size();
 }
Ejemplo n.º 9
0
 @Override
 public int getDbQueueLength() {
   return dbManagerQueue.size();
 }