Committed by
Gerrit Code Review
Add a method to get resource allocation of the given resource
Change-Id: I06b2f83b5a07a1bcbada9db5263abd2e1a4a4d17
Showing
2 changed files
with
17 additions
and
0 deletions
... | @@ -125,6 +125,15 @@ public interface ResourceService { | ... | @@ -125,6 +125,15 @@ public interface ResourceService { |
125 | boolean release(ResourceConsumer consumer); | 125 | boolean release(ResourceConsumer consumer); |
126 | 126 | ||
127 | /** | 127 | /** |
128 | + * Returns resource allocation of the specified resource. | ||
129 | + * | ||
130 | + * @param resource resource to check the allocation | ||
131 | + * @return allocation information enclosed by Optional. | ||
132 | + * If the resource is not allocated, the return value is empty. | ||
133 | + */ | ||
134 | + Optional<ResourceAllocation> getResourceAllocation(ResourcePath resource); | ||
135 | + | ||
136 | + /** | ||
128 | * Returns allocated resources being as children of the specified parent and being the specified resource type. | 137 | * Returns allocated resources being as children of the specified parent and being the specified resource type. |
129 | * | 138 | * |
130 | * @param parent parent resource path | 139 | * @param parent parent resource path | ... | ... |
... | @@ -91,6 +91,14 @@ public final class ResourceManager implements ResourceService, ResourceAdminServ | ... | @@ -91,6 +91,14 @@ public final class ResourceManager implements ResourceService, ResourceAdminServ |
91 | } | 91 | } |
92 | 92 | ||
93 | @Override | 93 | @Override |
94 | + public Optional<ResourceAllocation> getResourceAllocation(ResourcePath resource) { | ||
95 | + checkNotNull(resource); | ||
96 | + | ||
97 | + Optional<ResourceConsumer> consumer = store.getConsumer(resource); | ||
98 | + return consumer.map(x -> new ResourceAllocation(resource, x)); | ||
99 | + } | ||
100 | + | ||
101 | + @Override | ||
94 | public <T> Collection<ResourceAllocation> getResourceAllocations(ResourcePath parent, Class<T> cls) { | 102 | public <T> Collection<ResourceAllocation> getResourceAllocations(ResourcePath parent, Class<T> cls) { |
95 | checkNotNull(parent); | 103 | checkNotNull(parent); |
96 | checkNotNull(cls); | 104 | checkNotNull(cls); | ... | ... |
-
Please register or login to post a comment