Example #1
0
 @Override
 public int compare(Table one, Table two) {
   if (one.getState() != null && two.getState() != null) {
     if (!TableState.SIDEBOARDING.equals(one.getState())
         && !TableState.DUELING.equals(one.getState())) {
       if (one.getState().compareTo(two.getState()) != 0) {
         return one.getState().compareTo(two.getState());
       }
     } else if (!TableState.SIDEBOARDING.equals(two.getState())
         && !TableState.DUELING.equals(two.getState())) {
       if (one.getState().compareTo(two.getState()) != 0) {
         return one.getState().compareTo(two.getState());
       }
     }
   }
   if (two.getEndTime() != null) {
     if (one.getEndTime() == null) {
       return 1;
     } else {
       return two.getEndTime().compareTo(one.getEndTime());
     }
   }
   if (two.getStartTime() != null) {
     if (one.getStartTime() == null) {
       return 1;
     } else {
       return two.getStartTime().compareTo(one.getStartTime());
     }
   }
   if (two.getCreateTime() != null) {
     if (one.getCreateTime() == null) {
       return 1;
     } else {
       return two.getCreateTime().compareTo(one.getCreateTime());
     }
   }
   return 0;
 }
Example #2
0
 private void checkExpired() {
   debugServerState();
   Date now = new Date();
   List<UUID> toRemove = new ArrayList<>();
   for (Table table : tables.values()) {
     if (!table.getState().equals(TableState.FINISHED)) {
       // remove all not finished tables created more than expire_time ago
       long diff = (now.getTime() - table.getCreateTime().getTime()) / EXPIRE_TIME_UNIT_VALUE;
       if (diff >= EXPIRE_TIME) {
         logger.warn(
             "Table expired: id = "
                 + table.getId()
                 + ", created_by="
                 + table.getControllerName()
                 + ". Removing...");
         toRemove.add(table.getId());
       }
       // remove tables not valid anymore
       else if (!table.isTournament()) {
         TableController tableController = getController(table.getId());
         if (!tableController.isMatchTableStillValid()) {
           logger.warn(
               "Table with no active human player: id = "
                   + table.getId()
                   + ", created_by="
                   + table.getControllerName()
                   + ". Removing...");
           toRemove.add(table.getId());
         }
       }
     }
   }
   for (UUID tableId : toRemove) {
     try {
       removeTable(tableId);
     } catch (Exception e) {
       logger.error(e);
     }
   }
 }