Sho SHIMIZU | abd849c | 2015-07-14 09:14:12 -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 | */ |
| 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 allocating/releasing resource(s) and retrieving allocation(s) and availability. |
| 26 | */ |
| 27 | @Beta |
| 28 | public interface ResourceService { |
| 29 | /** |
| 30 | * Allocates the specified resource to the specified user. |
| 31 | * |
| 32 | * @param consumer resource user which the resource is allocated to |
| 33 | * @param resource resource to be allocated |
Sho SHIMIZU | abd849c | 2015-07-14 09:14:12 -0700 | [diff] [blame] | 34 | * @return allocation information enclosed by Optional. If the allocation fails, the return value is empty |
| 35 | */ |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame^] | 36 | Optional<ResourceAllocation> allocate(ResourceConsumer consumer, ResourcePath resource); |
Sho SHIMIZU | abd849c | 2015-07-14 09:14:12 -0700 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * Transactionally allocates the specified resources to the specified user. |
| 40 | * All allocations are made when this method succeeds, or no allocation is made when this method fails. |
| 41 | * |
| 42 | * @param consumer resource user which the resources are allocated to |
| 43 | * @param resources resources to be allocated |
| 44 | * @return non-empty list of allocation information if succeeded, otherwise empty list |
| 45 | */ |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame^] | 46 | List<ResourceAllocation> allocate(ResourceConsumer consumer, List<ResourcePath> resources); |
Sho SHIMIZU | abd849c | 2015-07-14 09:14:12 -0700 | [diff] [blame] | 47 | |
| 48 | /** |
| 49 | * Transactionally allocates the specified resources to the specified user. |
| 50 | * All allocations are made when this method succeeds, or no allocation is made when this method fails. |
| 51 | * |
| 52 | * @param consumer resource user which the resources are allocated to |
| 53 | * @param resources resources to be allocated |
| 54 | * @return non-empty list of allocation information if succeeded, otherwise empty list |
| 55 | */ |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame^] | 56 | List<ResourceAllocation> allocate(ResourceConsumer consumer, ResourcePath... resources); |
Sho SHIMIZU | abd849c | 2015-07-14 09:14:12 -0700 | [diff] [blame] | 57 | |
| 58 | /** |
| 59 | * Releases the specified resource allocation. |
| 60 | * |
| 61 | * @param allocation resource allocation to be released |
Sho SHIMIZU | abd849c | 2015-07-14 09:14:12 -0700 | [diff] [blame] | 62 | * @return true if succeeded, otherwise false |
| 63 | */ |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame^] | 64 | boolean release(ResourceAllocation allocation); |
Sho SHIMIZU | abd849c | 2015-07-14 09:14:12 -0700 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * Transactionally releases the specified resource allocations. |
| 68 | * All allocations are released when this method succeeded, or no allocation is released when this method fails. |
| 69 | * |
| 70 | * @param allocations resource allocations to be released |
| 71 | * @return true if succeeded, otherwise false |
| 72 | */ |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame^] | 73 | boolean release(List<ResourceAllocation> allocations); |
Sho SHIMIZU | abd849c | 2015-07-14 09:14:12 -0700 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * Transactionally releases the specified resource allocations. |
| 77 | * All allocations are released when this method succeeded, or no allocation is released when this method fails. |
| 78 | * |
| 79 | * @param allocations resource allocations to be released |
| 80 | * @return true if succeeded, otherwise false |
| 81 | */ |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame^] | 82 | boolean release(ResourceAllocation... allocations); |
Sho SHIMIZU | abd849c | 2015-07-14 09:14:12 -0700 | [diff] [blame] | 83 | |
| 84 | /** |
| 85 | * Transactionally releases the resources allocated to the specified consumer. |
| 86 | * All allocations are released when this method succeeded, or no allocation is released when this method fails. |
| 87 | * |
| 88 | * @param consumer consumer whose allocated resources are to be released |
| 89 | * @return true if succeeded, otherwise false |
| 90 | */ |
| 91 | boolean release(ResourceConsumer consumer); |
| 92 | |
| 93 | /** |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame^] | 94 | * Returns allocated resources being as children of the specified parent and being the specified resource type. |
Sho SHIMIZU | abd849c | 2015-07-14 09:14:12 -0700 | [diff] [blame] | 95 | * |
Sho SHIMIZU | abd849c | 2015-07-14 09:14:12 -0700 | [diff] [blame] | 96 | * @param cls class to specify a type of resource |
Sho SHIMIZU | abd849c | 2015-07-14 09:14:12 -0700 | [diff] [blame] | 97 | * @param <T> type of the resource |
| 98 | * @return non-empty collection of resource allocations if resources are allocated with the subject and type, |
| 99 | * empty collection if no resource is allocated with the subject and type |
| 100 | */ |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame^] | 101 | <T> Collection<ResourceAllocation> getResourceAllocations(ResourcePath parent, Class<T> cls); |
Sho SHIMIZU | abd849c | 2015-07-14 09:14:12 -0700 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | * Returns resources allocated to the specified consumer. |
| 105 | * |
| 106 | * @param consumer consumer whose allocated resources are to be returned |
| 107 | * @return resources allocated to the consumer |
| 108 | */ |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame^] | 109 | Collection<ResourceAllocation> getResourceAllocations(ResourceConsumer consumer); |
Sho SHIMIZU | abd849c | 2015-07-14 09:14:12 -0700 | [diff] [blame] | 110 | |
| 111 | /** |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame^] | 112 | * Returns the availability of the specified resource. |
Sho SHIMIZU | abd849c | 2015-07-14 09:14:12 -0700 | [diff] [blame] | 113 | * |
| 114 | * @param resource resource to check the availability |
Sho SHIMIZU | abd849c | 2015-07-14 09:14:12 -0700 | [diff] [blame] | 115 | * @return true if available, otherwise false |
| 116 | */ |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame^] | 117 | boolean isAvailable(ResourcePath resource); |
Sho SHIMIZU | abd849c | 2015-07-14 09:14:12 -0700 | [diff] [blame] | 118 | |
| 119 | // TODO: listener and event mechanism need to be considered |
| 120 | } |