blob: 0189a5700f7d5ac00f276a22e9d2690e12edb23c [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 /**
Sho SHIMIZU2d8a13a2015-08-18 22:37:41 -070028 * Unregisters the resources as children of the parent resource in transactional way.
29 * The state after completion of this method is all the resources are unregistered,
30 * or no resource is unregistered. The whole unregistration fails when any one of the
31 * resource can't be unregistered.
32 *
33 * @param parent resource which is the parent of the resource to be unregistered
34 * @param children resources to be unregistered
35 * @return true if the registration succeeds, false otherwise
36 */
37 boolean unregister(ResourcePath parent, List<ResourcePath> children);
38
39 /**
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070040 * Allocates the specified resources to the specified consumer in transactional way.
41 * The state after completion of this method is all the resources are allocated to the consumer,
42 * or no resource is allocated to the consumer. The whole allocation fails when any one of
43 * the resource can't be allocated.
44 *
45 * @param resources resources to be allocated
46 * @param consumer resource consumer which the resources are allocated to
47 * @return true if the allocation succeeds, false otherwise.
48 */
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070049 boolean allocate(List<ResourcePath> resources, ResourceConsumer consumer);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070050
51 /**
52 * Releases the specified resources allocated to the specified corresponding consumers
53 * in transactional way. The state after completion of this method is all the resources
54 * are released from the consumer, or no resource is released. The whole release fails
55 * when any one of the resource can't be released. The size of the list of resources and
56 * that of consumers must be equal. The resource and consumer with the same position from
57 * the head of each list correspond to each other.
58 *
59 * @param resources resources to be released
60 * @param consumers resource consumers to whom the resource allocated to
61 * @return true if succeeds, otherwise false
62 */
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070063 boolean release(List<ResourcePath> resources, List<ResourceConsumer> consumers);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070064
65 /**
66 * Returns the resource consumer to whom the specified resource is allocated.
67 *
68 * @param resource resource whose allocated consumer to be returned
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070069 * @return resource consumer who are allocated the resource
70 */
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070071 Optional<ResourceConsumer> getConsumer(ResourcePath resource);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070072
73 /**
74 * Returns a collection of the resources allocated to the specified consumer.
75 *
76 * @param consumer resource consumer whose allocated resource are searched for
77 * @return a collection of the resources allocated to the specified consumer
78 */
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070079 Collection<ResourcePath> getResources(ResourceConsumer consumer);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070080
81 /**
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070082 * Returns a collection of the resources which are children of the specified parent and
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070083 * whose type is the specified class.
84 *
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070085 * @param parent parent of the resources to be returned
86 * @param cls class instance of the children
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070087 * @param <T> type of the resource
88 * @return a collection of the resources which belongs to the specified subject and
89 * whose type is the specified class.
90 */
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070091 <T> Collection<ResourcePath> getAllocatedResources(ResourcePath parent, Class<T> cls);
Sho SHIMIZU78ee25c2015-07-16 15:54:14 -070092}