Esempio n. 1
0
  @Override
  public Mission getMission(Sergeant s) {
    if (this.isEmpty()) return null;

    PriorityBlockingQueue<Mission> relevantQueue;
    Vector<Mission> temp = new Vector<Mission>();

    if (s.getPriority().equals(Sergeant.SHORTEST)) relevantQueue = this.minLength;
    else if (s.getPriority().equals(Sergeant.LONGEST)) relevantQueue = this.maxLength;
    else if (s.getPriority().equals(Sergeant.MINITEMS)) relevantQueue = this.minItems;
    else relevantQueue = this.maxItems;
    while (!relevantQueue.isEmpty()) {
      Mission candidate = relevantQueue.poll();
      temp.add(candidate);
      WarSim.LOG.fine("Testing Mission " + candidate.getName() + "(" + candidate.getSkill() + ")");
      if (s.getSkills().contains(candidate.getSkill())) {
        for (Mission tm : temp) relevantQueue.put(tm);
        return candidate;
      } else
        WarSim.LOG.fine(
            "The sergeant " + s.getName() + " can't execute mission " + candidate.getName());
    }
    for (Mission tm : temp) relevantQueue.put(tm);

    return null;
  }
  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;
  }
Esempio n. 3
0
 public void putEvent(GameEvent gameEvent) {
   try {
     queue.put(gameEvent);
   } catch (Exception e) {
     logger.error("<putEvent> but catch exception " + e.toString(), e);
   }
 }
Esempio n. 4
0
 public void makeRequest(final CacheRequest request) {
   requests.put(request);
 }
Esempio n. 5
0
 private synchronized void startSplit(PrioritizedSplitRunner split) {
   allSplits.add(split);
   pendingSplits.put(split);
 }