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 | /** |
Sho SHIMIZU | 83e17a0 | 2015-08-20 14:07:05 -0700 | [diff] [blame] | 16 | * Registers the resources in transactional way. |
Sho SHIMIZU | ad619f5 | 2015-08-24 10:45:40 -0700 | [diff] [blame] | 17 | * Resource registration must be done before resource allocation. The state after completion |
Sho SHIMIZU | 4568c41 | 2015-08-21 16:39:07 -0700 | [diff] [blame] | 18 | * of this method is all the resources are registered, or none of the given resources is registered. |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 19 | * The whole registration fails when any one of the resource can't be registered. |
| 20 | * |
Sho SHIMIZU | 83e17a0 | 2015-08-20 14:07:05 -0700 | [diff] [blame] | 21 | * @param resources resources to be registered |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 22 | * @return true if the registration succeeds, false otherwise |
| 23 | */ |
Sho SHIMIZU | 83e17a0 | 2015-08-20 14:07:05 -0700 | [diff] [blame] | 24 | boolean register(List<ResourcePath> resources); |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 25 | |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 26 | /** |
Sho SHIMIZU | 83e17a0 | 2015-08-20 14:07:05 -0700 | [diff] [blame] | 27 | * Unregisters the resources in transactional way. |
Sho SHIMIZU | 2d8a13a | 2015-08-18 22:37:41 -0700 | [diff] [blame] | 28 | * The state after completion of this method is all the resources are unregistered, |
Sho SHIMIZU | 5618ee5 | 2015-08-21 17:19:44 -0700 | [diff] [blame^] | 29 | * or none of the given resources is unregistered. The whole unregistration fails when any one of the |
Sho SHIMIZU | 2d8a13a | 2015-08-18 22:37:41 -0700 | [diff] [blame] | 30 | * resource can't be unregistered. |
| 31 | * |
Sho SHIMIZU | 83e17a0 | 2015-08-20 14:07:05 -0700 | [diff] [blame] | 32 | * @param resources resources to be unregistered |
Sho SHIMIZU | 2d8a13a | 2015-08-18 22:37:41 -0700 | [diff] [blame] | 33 | * @return true if the registration succeeds, false otherwise |
| 34 | */ |
Sho SHIMIZU | 83e17a0 | 2015-08-20 14:07:05 -0700 | [diff] [blame] | 35 | boolean unregister(List<ResourcePath> resources); |
Sho SHIMIZU | 2d8a13a | 2015-08-18 22:37:41 -0700 | [diff] [blame] | 36 | |
| 37 | /** |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 38 | * Allocates the specified resources to the specified consumer in transactional way. |
| 39 | * The state after completion of this method is all the resources are allocated to the consumer, |
| 40 | * or no resource is allocated to the consumer. The whole allocation fails when any one of |
| 41 | * the resource can't be allocated. |
| 42 | * |
| 43 | * @param resources resources to be allocated |
| 44 | * @param consumer resource consumer which the resources are allocated to |
| 45 | * @return true if the allocation succeeds, false otherwise. |
| 46 | */ |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 47 | boolean allocate(List<ResourcePath> resources, ResourceConsumer consumer); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 48 | |
| 49 | /** |
| 50 | * Releases the specified resources allocated to the specified corresponding consumers |
| 51 | * in transactional way. The state after completion of this method is all the resources |
| 52 | * are released from the consumer, or no resource is released. The whole release fails |
| 53 | * when any one of the resource can't be released. The size of the list of resources and |
| 54 | * that of consumers must be equal. The resource and consumer with the same position from |
| 55 | * the head of each list correspond to each other. |
| 56 | * |
| 57 | * @param resources resources to be released |
| 58 | * @param consumers resource consumers to whom the resource allocated to |
| 59 | * @return true if succeeds, otherwise false |
| 60 | */ |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 61 | boolean release(List<ResourcePath> resources, List<ResourceConsumer> consumers); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 62 | |
| 63 | /** |
| 64 | * Returns the resource consumer to whom the specified resource is allocated. |
| 65 | * |
| 66 | * @param resource resource whose allocated consumer to be returned |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 67 | * @return resource consumer who are allocated the resource |
| 68 | */ |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 69 | Optional<ResourceConsumer> getConsumer(ResourcePath resource); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * Returns a collection of the resources allocated to the specified consumer. |
| 73 | * |
| 74 | * @param consumer resource consumer whose allocated resource are searched for |
| 75 | * @return a collection of the resources allocated to the specified consumer |
| 76 | */ |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 77 | Collection<ResourcePath> getResources(ResourceConsumer consumer); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 78 | |
| 79 | /** |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 80 | * 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] | 81 | * whose type is the specified class. |
| 82 | * |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 83 | * @param parent parent of the resources to be returned |
| 84 | * @param cls class instance of the children |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 85 | * @param <T> type of the resource |
| 86 | * @return a collection of the resources which belongs to the specified subject and |
| 87 | * whose type is the specified class. |
| 88 | */ |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 89 | <T> Collection<ResourcePath> getAllocatedResources(ResourcePath parent, Class<T> cls); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 90 | } |