Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 1 | package org.onosproject.net.newresource; |
| 2 | |
| 3 | import com.google.common.annotations.Beta; |
| 4 | |
| 5 | import java.util.Collection; |
| 6 | import java.util.List; |
| 7 | import java.util.Optional; |
| 8 | |
| 9 | /** |
| 10 | * Service for storing resource and consumer information. |
| 11 | */ |
| 12 | @Beta |
| 13 | public interface ResourceStore { |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 14 | |
| 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 SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 27 | /** |
Sho SHIMIZU | 2d8a13a | 2015-08-18 22:37:41 -0700 | [diff] [blame^] | 28 | * 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 SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 40 | * 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 SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 49 | boolean allocate(List<ResourcePath> resources, ResourceConsumer consumer); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 50 | |
| 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 SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 63 | boolean release(List<ResourcePath> resources, List<ResourceConsumer> consumers); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 64 | |
| 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 SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 69 | * @return resource consumer who are allocated the resource |
| 70 | */ |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 71 | Optional<ResourceConsumer> getConsumer(ResourcePath resource); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 72 | |
| 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 SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 79 | Collection<ResourcePath> getResources(ResourceConsumer consumer); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 80 | |
| 81 | /** |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 82 | * Returns a collection of the resources which are children of the specified parent and |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 83 | * whose type is the specified class. |
| 84 | * |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 85 | * @param parent parent of the resources to be returned |
| 86 | * @param cls class instance of the children |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 87 | * @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 SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 91 | <T> Collection<ResourcePath> getAllocatedResources(ResourcePath parent, Class<T> cls); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 92 | } |