Sho SHIMIZU
Committed by Gerrit Code Review

Add a method to get resource allocation of the given resource

Change-Id: I06b2f83b5a07a1bcbada9db5263abd2e1a4a4d17
......@@ -125,6 +125,15 @@ public interface ResourceService {
boolean release(ResourceConsumer consumer);
/**
* Returns resource allocation of the specified resource.
*
* @param resource resource to check the allocation
* @return allocation information enclosed by Optional.
* If the resource is not allocated, the return value is empty.
*/
Optional<ResourceAllocation> getResourceAllocation(ResourcePath resource);
/**
* Returns allocated resources being as children of the specified parent and being the specified resource type.
*
* @param parent parent resource path
......
......@@ -91,6 +91,14 @@ public final class ResourceManager implements ResourceService, ResourceAdminServ
}
@Override
public Optional<ResourceAllocation> getResourceAllocation(ResourcePath resource) {
checkNotNull(resource);
Optional<ResourceConsumer> consumer = store.getConsumer(resource);
return consumer.map(x -> new ResourceAllocation(resource, x));
}
@Override
public <T> Collection<ResourceAllocation> getResourceAllocations(ResourcePath parent, Class<T> cls) {
checkNotNull(parent);
checkNotNull(cls);
......