blob: b711f398a60cff3fefc821123a6b999e8c3380c2 [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 {
Sho SHIMIZUba41fc12015-08-12 15:43:22 -070014
15 /**
16 * Registers the resources as children of the parent resource in transactional way.
17 * Resource registration is must be done before resource allocation. The state after completion
18 * of this method is all the resources are registered, or no resource is registered.
19 * The whole registration fails when any one of the resource can't be registered.
20 *
21 * @param parent resource which is the parent of the resource to be registered
22 * @param children resources to be registered
23 * @return true if the registration succeeds, false otherwise
24 */
25 boolean register(ResourcePath parent, List<ResourcePath> children);
26
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070027 /**
28 * Allocates the specified resources to the specified consumer in transactional way.
29 * The state after completion of this method is all the resources are allocated to the consumer,
30 * or no resource is allocated to the consumer. The whole allocation fails when any one of
31 * the resource can't be allocated.
32 *
33 * @param resources resources to be allocated
34 * @param consumer resource consumer which the resources are allocated to
35 * @return true if the allocation succeeds, false otherwise.
36 */
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070037 boolean allocate(List<ResourcePath> resources, ResourceConsumer consumer);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070038
39 /**
40 * Releases the specified resources allocated to the specified corresponding consumers
41 * in transactional way. The state after completion of this method is all the resources
42 * are released from the consumer, or no resource is released. The whole release fails
43 * when any one of the resource can't be released. The size of the list of resources and
44 * that of consumers must be equal. The resource and consumer with the same position from
45 * the head of each list correspond to each other.
46 *
47 * @param resources resources to be released
48 * @param consumers resource consumers to whom the resource allocated to
49 * @return true if succeeds, otherwise false
50 */
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070051 boolean release(List<ResourcePath> resources, List<ResourceConsumer> consumers);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070052
53 /**
54 * Returns the resource consumer to whom the specified resource is allocated.
55 *
56 * @param resource resource whose allocated consumer to be returned
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070057 * @return resource consumer who are allocated the resource
58 */
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070059 Optional<ResourceConsumer> getConsumer(ResourcePath resource);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070060
61 /**
62 * Returns a collection of the resources allocated to the specified consumer.
63 *
64 * @param consumer resource consumer whose allocated resource are searched for
65 * @return a collection of the resources allocated to the specified consumer
66 */
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070067 Collection<ResourcePath> getResources(ResourceConsumer consumer);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070068
69 /**
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070070 * Returns a collection of the resources which are children of the specified parent and
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070071 * whose type is the specified class.
72 *
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070073 * @param parent parent of the resources to be returned
74 * @param cls class instance of the children
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070075 * @param <T> type of the resource
76 * @return a collection of the resources which belongs to the specified subject and
77 * whose type is the specified class.
78 */
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070079 <T> Collection<ResourcePath> getAllocatedResources(ResourcePath parent, Class<T> cls);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070080}