code: public List<Integer> getGrantsToPreempt(
        int maxGrantsToPreempt, long maxRunningTime, ResourceType type) {
      if (deleted) {
        LOG.warn("Attempt to preempt from deleted session " + getSessionId());
        return Collections.emptyList();
      }
      List<ResourceGrant> candidates = getGrantsYoungerThan(maxRunningTime, type);
      List<Integer> grantIds = new ArrayList<Integer>();
      if (candidates.size() <= maxGrantsToPreempt) {
        // In this case, we can return the whole list without sorting
        for (ResourceGrant grant : candidates) {
          grantIds.add(grant.id);
        }
      } else {
        sortGrantsByStartTime(candidates);
        for (ResourceGrant grant : candidates) {
          grantIds.add(grant.id);
          if (grantIds.size() == maxGrantsToPreempt) {
            break;
          }
        }
      }
      LOG.info("Found " + grantIds.size() + " " + type +
          " grants younger than " + maxRunningTime + " ms to preempt in " +
          getSessionId());
      return grantIds;
    }
docs: Obtain a list of grants to be preempted
  @param maxGrantsToPreempt The maximum number of grants to preempt
  @param maxRunningTime The running time of the preempted grants cannot be
  larger than this number (in ms)
  @param type The task type of the grants
  @return The list of grant id to be preempted