Jordan Halterman | 6359c83 | 2017-03-29 16:53:21 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2017-present 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.store.resource.impl; |
| 17 | |
| 18 | import org.onosproject.net.resource.DiscreteResourceId; |
| 19 | import org.onosproject.net.resource.Resource; |
| 20 | import org.onosproject.net.resource.ResourceConsumerId; |
| 21 | import org.onosproject.net.resource.ResourceId; |
| 22 | |
| 23 | import java.util.Optional; |
| 24 | import java.util.Set; |
| 25 | |
| 26 | /** |
| 27 | * Interface for transaction resource substores. |
| 28 | */ |
| 29 | interface TransactionalResourceSubStore<T extends ResourceId, U extends Resource> { |
| 30 | |
| 31 | /** |
| 32 | * Reads the given resource from the substore. |
| 33 | * |
| 34 | * @param resourceId the resource ID |
| 35 | * @return an optional containing the resource if it exists |
| 36 | */ |
| 37 | Optional<U> lookup(T resourceId); |
| 38 | |
| 39 | /** |
| 40 | * Registers the given set of resources for the given parent. |
| 41 | * |
| 42 | * @param parent the parent for which to register the resources |
| 43 | * @param resources the resources to register |
| 44 | * @return indicates whether the registration was successful |
| 45 | */ |
| 46 | boolean register(DiscreteResourceId parent, Set<U> resources); |
| 47 | |
| 48 | /** |
| 49 | * Unregisters the given set of resources for the given parent. |
| 50 | * |
| 51 | * @param parent the parent for which to unregister the resources |
| 52 | * @param resources the resources to register |
| 53 | * @return indicates whether the unregistration was successful |
| 54 | */ |
| 55 | boolean unregister(DiscreteResourceId parent, Set<U> resources); |
| 56 | |
| 57 | /** |
| 58 | * Returns a boolean indicating whether the given resource is allocated. |
| 59 | * |
| 60 | * @param resourceId the resource ID |
| 61 | * @return indicates whether the given resource is allocated |
| 62 | */ |
| 63 | boolean isAllocated(T resourceId); |
| 64 | |
| 65 | /** |
| 66 | * Allocates the given resource for the given consumer. |
| 67 | * |
| 68 | * @param consumerId the consumer ID |
| 69 | * @param resource the resource |
| 70 | * @return indicates whether the allocation was successful |
| 71 | */ |
| 72 | boolean allocate(ResourceConsumerId consumerId, U resource); |
| 73 | |
| 74 | /** |
| 75 | * Releases the given resource from the given consumer. |
| 76 | * |
| 77 | * @param consumerId the consumer ID |
| 78 | * @param resource the resource |
| 79 | * @return indicates whether the release was successful |
| 80 | */ |
| 81 | boolean release(ResourceConsumerId consumerId, U resource); |
| 82 | |
| 83 | } |