blob: 7280b60183578bfb25ba504ecec0344500dd9c6f [file] [log] [blame]
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -07001package org.onosproject.net.newresource;
2
3import com.google.common.annotations.Beta;
4
5import java.util.Collection;
6import java.util.List;
7import java.util.Optional;
8
9/**
10 * Service for storing resource and consumer information.
11 */
12@Beta
13public interface ResourceStore {
14 /**
15 * Allocates the specified resources to the specified consumer in transactional way.
16 * The state after completion of this method is all the resources are allocated to the consumer,
17 * or no resource is allocated to the consumer. The whole allocation fails when any one of
18 * the resource can't be allocated.
19 *
20 * @param resources resources to be allocated
21 * @param consumer resource consumer which the resources are allocated to
22 * @return true if the allocation succeeds, false otherwise.
23 */
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070024 boolean allocate(List<ResourcePath> resources, ResourceConsumer consumer);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070025
26 /**
27 * Releases the specified resources allocated to the specified corresponding consumers
28 * in transactional way. The state after completion of this method is all the resources
29 * are released from the consumer, or no resource is released. The whole release fails
30 * when any one of the resource can't be released. The size of the list of resources and
31 * that of consumers must be equal. The resource and consumer with the same position from
32 * the head of each list correspond to each other.
33 *
34 * @param resources resources to be released
35 * @param consumers resource consumers to whom the resource allocated to
36 * @return true if succeeds, otherwise false
37 */
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070038 boolean release(List<ResourcePath> resources, List<ResourceConsumer> consumers);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070039
40 /**
41 * Returns the resource consumer to whom the specified resource is allocated.
42 *
43 * @param resource resource whose allocated consumer to be returned
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070044 * @return resource consumer who are allocated the resource
45 */
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070046 Optional<ResourceConsumer> getConsumer(ResourcePath resource);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070047
48 /**
49 * Returns a collection of the resources allocated to the specified consumer.
50 *
51 * @param consumer resource consumer whose allocated resource are searched for
52 * @return a collection of the resources allocated to the specified consumer
53 */
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070054 Collection<ResourcePath> getResources(ResourceConsumer consumer);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070055
56 /**
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070057 * Returns a collection of the resources which are children of the specified parent and
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070058 * whose type is the specified class.
59 *
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070060 * @param parent parent of the resources to be returned
61 * @param cls class instance of the children
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070062 * @param <T> type of the resource
63 * @return a collection of the resources which belongs to the specified subject and
64 * whose type is the specified class.
65 */
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070066 <T> Collection<ResourcePath> getAllocatedResources(ResourcePath parent, Class<T> cls);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070067}