示例#1
0
 /**
  * Returns a set of resources that is a subset of the given set of resources and is reserved/could
  * be released by the given resource user.
  *
  * @param resources The set of resources to be filtered for resources that could be released.
  * @param resourceUser The resource user that should be able to release the returned resources.
  * @return A set of resources that is a subset of the given set of resources and is reserved/could
  *     be released by the given resource user.
  */
 private Set<TCSResource> getFreeableResources(
     Set<TCSResource> resources, ResourceUser resourceUser) {
   // Make sure we're freeing only resources that are allocated by us.
   final Set<TCSResource> freeableResources = new HashSet<>();
   for (TCSResource curRes : resources) {
     ReservationEntry entry = getReservationEntry(curRes);
     if (entry.isFree() || !entry.getResourceUser().equals(resourceUser)) {
       log.warning("Freed resource not reserved: " + entry.getResource());
     } else {
       freeableResources.add(curRes);
     }
   }
   return freeableResources;
 }
示例#2
0
  @Override
  public void allocateNow(ResourceUser resourceUser, Set<TCSResource> resources)
      throws ResourceAllocationException {
    Objects.requireNonNull(resourceUser, "resourceUser is null");
    Objects.requireNonNull(resources, "resources is null");

    synchronized (reservations) {
      // Check if all resources are available.
      final Set<TCSResource> availableResources = new HashSet<>();
      for (TCSResource curResource : resources) {
        ReservationEntry entry = getReservationEntry(curResource);
        if (!entry.isFree() && !entry.getResourceUser().equals(resourceUser)) {
          log.severe("Resource unavailable: " + curResource.getName());
          // XXX DO something about it?!
        } else {
          availableResources.add(curResource);
        }
      }
      // Allocate all requested resources that are available.
      for (TCSResource curResource : availableResources) {
        getReservationEntry(curResource).allocate(resourceUser);
      }
    }
  }