private boolean roleSettingOperation(
     TestPlanEntity testPlan, Host tester, List<Engine> idleEngines, List<Engine> engineOnTester) {
   Queue<Engine> engineQ = new ArrayDeque<>();
   engineQ.addAll(engineOnTester);
   boolean finished = setUpRemoteEngines(testPlan, engineQ);
   if (!finished) {
     if (engineQ.isEmpty()) {
       engineQ.addAll(idleEngines);
       finished = setUpRemoteEngines(testPlan, engineQ);
       if (!finished) {
         _logger.error(
             String.format(
                 "Testplan: %d can't init. Too many engine role faults", testPlan.getId()));
         return true;
       }
     } else {
       _logger.error(
           String.format(
               "Testplan: %d can't init. Not enough available engines", testPlan.getId()));
       return true;
     }
   } else {
     if (!engineQ.isEmpty()) {
       List<Engine> enginesToBeKicked = engineQ.stream().collect(Collectors.toList());
       _logger.warn(
           String.format("Host: %d has to many engines, should kickout some.", tester.getId()));
       if (!hostService.kickEnginesToRandomHost(enginesToBeKicked, tester)) {
         _logger.warn(String.format("Host: %d kick out failed. please retry", tester.getId()));
         return true;
       }
     }
   }
   return false;
 }
 /**
  * Retrieves and removes all items matching a given predicate from the collection.
  *
  * @param predicate
  * @return
  */
 public List<ServiceRequest> findAll(Predicate<ServiceRequest> predicate) {
   synchronized (this) {
     List<ServiceRequest> list = queue.stream().filter(predicate).collect(Collectors.toList());
     queue.removeAll(list);
     notifyAll();
     return list;
   }
 }
Example #3
0
 /**
  * Determines if an object exists in the game world
  *
  * @param id the identification value of the object
  * @param x the x location of the object
  * @param y the y location of the object
  * @param height the height location of the object
  * @return true if the object exists, otherwise false.
  */
 public boolean exists(int id, int x, int y, int height) {
   return objects
       .stream()
       .anyMatch(
           object ->
               object.getObjectId() == id
                   && object.getX() == x
                   && object.getY() == y
                   && object.getHeight() == height);
 }
Example #4
0
 public GlobalObject get(int id, int x, int y, int height) {
   Optional<GlobalObject> obj =
       objects
           .stream()
           .filter(
               object ->
                   object.getObjectId() == id
                       && object.getX() == x
                       && object.getY() == y
                       && object.getHeight() == height)
           .findFirst();
   return obj.orElse(null);
 }
Example #5
0
 /**
  * Removes a global object from the world. If the object is present in the game, we find the
  * reference to that object and add it to the remove list.
  *
  * @param id the identification value of the object
  * @param x the x location of the object
  * @param y the y location of the object
  * @param height the height of the object
  */
 public void remove(int id, int x, int y, int height) {
   Optional<GlobalObject> existing =
       objects
           .stream()
           .filter(
               o ->
                   o.getObjectId() == id
                       && o.getX() == x
                       && o.getY() == y
                       && o.getHeight() == height)
           .findFirst();
   if (!existing.isPresent()) {
     return;
   }
   remove(existing.get());
 }
Example #6
0
 /**
  * Updates all region objects for a specific player
  *
  * @param player the player were updating all objects for
  */
 public void updateRegionObjects(Player player) {
   objects
       .stream()
       .filter(Objects::nonNull)
       .filter(
           object ->
               player.distanceToPoint(object.getX(), object.getY()) <= 60
                   && object.getHeight() == player.heightLevel)
       .forEach(
           object ->
               player
                   .getPA()
                   .object(
                       object.getObjectId(),
                       object.getX(),
                       object.getY(),
                       object.getFace(),
                       object.getType()));
   loadCustomObjects(player);
 }
Example #7
0
 public String getNaturalOrder() {
   return Arrays.toString(pq.stream().sorted().toArray());
 }
Example #8
0
 /**
  * Attempts to remove any and all objects on a certain height that have the same object id.
  *
  * @param id the id of the object
  * @param height the height the object must be on to be removed
  */
 public void remove(int id, int height) {
   objects
       .stream()
       .filter(o -> o.getObjectId() == id && o.getHeight() == height)
       .forEach(this::remove);
 }