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 { |
| 14 | /** |
| 15 | * Allocates the specified resources to the specified consumer in transactional way. |
| 16 | * The state after completion of this method is all the resources are allocated to the consumer, |
| 17 | * or no resource is allocated to the consumer. The whole allocation fails when any one of |
| 18 | * the resource can't be allocated. |
| 19 | * |
| 20 | * @param resources resources to be allocated |
| 21 | * @param consumer resource consumer which the resources are allocated to |
| 22 | * @return true if the allocation succeeds, false otherwise. |
| 23 | */ |
| 24 | boolean allocate(List<? extends Resource<?, ?>> resources, ResourceConsumer consumer); |
| 25 | |
| 26 | /** |
| 27 | * Releases the specified resources allocated to the specified corresponding consumers |
| 28 | * in transactional way. The state after completion of this method is all the resources |
| 29 | * are released from the consumer, or no resource is released. The whole release fails |
| 30 | * when any one of the resource can't be released. The size of the list of resources and |
| 31 | * that of consumers must be equal. The resource and consumer with the same position from |
| 32 | * the head of each list correspond to each other. |
| 33 | * |
| 34 | * @param resources resources to be released |
| 35 | * @param consumers resource consumers to whom the resource allocated to |
| 36 | * @return true if succeeds, otherwise false |
| 37 | */ |
| 38 | boolean release(List<? extends Resource<?, ?>> resources, List<ResourceConsumer> consumers); |
| 39 | |
| 40 | /** |
| 41 | * Returns the resource consumer to whom the specified resource is allocated. |
| 42 | * |
| 43 | * @param resource resource whose allocated consumer to be returned |
| 44 | * @param <S> type of subject of the resource |
| 45 | * @param <T> type of resource |
| 46 | * @return resource consumer who are allocated the resource |
| 47 | */ |
| 48 | <S, T> Optional<ResourceConsumer> getConsumer(Resource<S, T> resource); |
| 49 | |
| 50 | /** |
| 51 | * Returns a collection of the resources allocated to the specified consumer. |
| 52 | * |
| 53 | * @param consumer resource consumer whose allocated resource are searched for |
| 54 | * @return a collection of the resources allocated to the specified consumer |
| 55 | */ |
| 56 | Collection<Resource<?, ?>> getResources(ResourceConsumer consumer); |
| 57 | |
| 58 | /** |
| 59 | * Returns a collection of the resources which belongs to the specified subject and |
| 60 | * whose type is the specified class. |
| 61 | * |
| 62 | * @param subject subject of the resources to be returned |
| 63 | * @param cls class instance of the resources |
| 64 | * @param <S> type of the subject |
| 65 | * @param <T> type of the resource |
| 66 | * @return a collection of the resources which belongs to the specified subject and |
| 67 | * whose type is the specified class. |
| 68 | */ |
| 69 | <S, T> Collection<Resource<S, T>> getAllocatedResources(S subject, Class<T> cls); |
| 70 | } |