Thomas Vachuska | 58de416 | 2015-09-10 16:15:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 16 | package org.onosproject.net.newresource; |
| 17 | |
| 18 | import com.google.common.annotations.Beta; |
| 19 | |
| 20 | import java.util.Collection; |
| 21 | import java.util.List; |
| 22 | import java.util.Optional; |
| 23 | |
| 24 | /** |
| 25 | * Service for storing resource and consumer information. |
| 26 | */ |
| 27 | @Beta |
| 28 | public interface ResourceStore { |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 29 | |
| 30 | /** |
Sho SHIMIZU | 83e17a0 | 2015-08-20 14:07:05 -0700 | [diff] [blame] | 31 | * Registers the resources in transactional way. |
Sho SHIMIZU | ad619f5 | 2015-08-24 10:45:40 -0700 | [diff] [blame] | 32 | * Resource registration must be done before resource allocation. The state after completion |
Sho SHIMIZU | 4568c41 | 2015-08-21 16:39:07 -0700 | [diff] [blame] | 33 | * 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] | 34 | * The whole registration fails when any one of the resource can't be registered. |
| 35 | * |
Sho SHIMIZU | 83e17a0 | 2015-08-20 14:07:05 -0700 | [diff] [blame] | 36 | * @param resources resources to be registered |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 37 | * @return true if the registration succeeds, false otherwise |
| 38 | */ |
Sho SHIMIZU | 83e17a0 | 2015-08-20 14:07:05 -0700 | [diff] [blame] | 39 | boolean register(List<ResourcePath> resources); |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 40 | |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 41 | /** |
Sho SHIMIZU | 83e17a0 | 2015-08-20 14:07:05 -0700 | [diff] [blame] | 42 | * Unregisters the resources in transactional way. |
Sho SHIMIZU | 2d8a13a | 2015-08-18 22:37:41 -0700 | [diff] [blame] | 43 | * 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] | 44 | * 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] | 45 | * resource can't be unregistered. |
| 46 | * |
Sho SHIMIZU | 83e17a0 | 2015-08-20 14:07:05 -0700 | [diff] [blame] | 47 | * @param resources resources to be unregistered |
Sho SHIMIZU | 2d8a13a | 2015-08-18 22:37:41 -0700 | [diff] [blame] | 48 | * @return true if the registration succeeds, false otherwise |
| 49 | */ |
Sho SHIMIZU | 83e17a0 | 2015-08-20 14:07:05 -0700 | [diff] [blame] | 50 | boolean unregister(List<ResourcePath> resources); |
Sho SHIMIZU | 2d8a13a | 2015-08-18 22:37:41 -0700 | [diff] [blame] | 51 | |
| 52 | /** |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 53 | * Allocates the specified resources to the specified consumer in transactional way. |
| 54 | * The state after completion of this method is all the resources are allocated to the consumer, |
| 55 | * or no resource is allocated to the consumer. The whole allocation fails when any one of |
| 56 | * the resource can't be allocated. |
| 57 | * |
| 58 | * @param resources resources to be allocated |
| 59 | * @param consumer resource consumer which the resources are allocated to |
| 60 | * @return true if the allocation succeeds, false otherwise. |
| 61 | */ |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 62 | boolean allocate(List<ResourcePath> resources, ResourceConsumer consumer); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 63 | |
| 64 | /** |
| 65 | * Releases the specified resources allocated to the specified corresponding consumers |
| 66 | * in transactional way. The state after completion of this method is all the resources |
| 67 | * are released from the consumer, or no resource is released. The whole release fails |
| 68 | * when any one of the resource can't be released. The size of the list of resources and |
| 69 | * that of consumers must be equal. The resource and consumer with the same position from |
| 70 | * the head of each list correspond to each other. |
| 71 | * |
| 72 | * @param resources resources to be released |
| 73 | * @param consumers resource consumers to whom the resource allocated to |
| 74 | * @return true if succeeds, otherwise false |
| 75 | */ |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 76 | boolean release(List<ResourcePath> resources, List<ResourceConsumer> consumers); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 77 | |
| 78 | /** |
| 79 | * Returns the resource consumer to whom the specified resource is allocated. |
| 80 | * |
| 81 | * @param resource resource whose allocated consumer to be returned |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 82 | * @return resource consumer who are allocated the resource |
| 83 | */ |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 84 | Optional<ResourceConsumer> getConsumer(ResourcePath resource); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * Returns a collection of the resources allocated to the specified consumer. |
| 88 | * |
| 89 | * @param consumer resource consumer whose allocated resource are searched for |
| 90 | * @return a collection of the resources allocated to the specified consumer |
| 91 | */ |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 92 | Collection<ResourcePath> getResources(ResourceConsumer consumer); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 93 | |
| 94 | /** |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 95 | * 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] | 96 | * whose type is the specified class. |
| 97 | * |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 98 | * @param parent parent of the resources to be returned |
| 99 | * @param cls class instance of the children |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 100 | * @param <T> type of the resource |
| 101 | * @return a collection of the resources which belongs to the specified subject and |
| 102 | * whose type is the specified class. |
| 103 | */ |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 104 | <T> Collection<ResourcePath> getAllocatedResources(ResourcePath parent, Class<T> cls); |
Sho SHIMIZU | 78ee25c | 2015-07-16 15:54:14 -0700 | [diff] [blame] | 105 | } |