/** * Returns the given set of resources after expansion (by resolution of blocks, for instance) by * the kernel. * * @param resources The set of resources to be expanded. * @return The given set of resources after expansion (by resolution of blocks, for instance) by * the kernel. */ private Set<TCSResource> expandResources(Set<TCSResource> resources) { assert resources != null; // Build a set of references Set<TCSResourceReference> refs = new HashSet<>(); for (TCSResource curResource : resources) { refs.add(curResource.getReference()); } // Let the kernel expand the resources for us. try { Set<TCSResource> result = localKernel.expandResources(refs); log.fine("Set " + resources + " expanded to " + result); return result; } catch (ObjectUnknownException exc) { throw new IllegalStateException("Unexpected exception", exc); } }
@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); } } }