alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 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 | */ |
alshabib | 10c810b | 2015-08-18 16:59:04 -0700 | [diff] [blame] | 16 | package org.onosproject.net.meter; |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 17 | |
Jordi Ortiz | aa8de49 | 2016-12-01 00:21:36 +0100 | [diff] [blame] | 18 | import org.onosproject.net.DeviceId; |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 19 | import org.onosproject.store.Store; |
| 20 | |
| 21 | import java.util.Collection; |
alshabib | eadfc8e | 2015-08-18 15:40:46 -0700 | [diff] [blame] | 22 | import java.util.concurrent.CompletableFuture; |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * Entity that stores and distributed meter objects. |
| 26 | */ |
| 27 | public interface MeterStore extends Store<MeterEvent, MeterStoreDelegate> { |
| 28 | |
| 29 | /** |
| 30 | * Adds a meter to the store. |
| 31 | * |
| 32 | * @param meter a meter |
alshabib | eadfc8e | 2015-08-18 15:40:46 -0700 | [diff] [blame] | 33 | * @return a future indicating the result of the store operation |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 34 | */ |
alshabib | eadfc8e | 2015-08-18 15:40:46 -0700 | [diff] [blame] | 35 | CompletableFuture<MeterStoreResult> storeMeter(Meter meter); |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * Deletes a meter from the store. |
| 39 | * |
| 40 | * @param meter a meter |
alshabib | eadfc8e | 2015-08-18 15:40:46 -0700 | [diff] [blame] | 41 | * @return a future indicating the result of the store operation |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 42 | */ |
alshabib | eadfc8e | 2015-08-18 15:40:46 -0700 | [diff] [blame] | 43 | CompletableFuture<MeterStoreResult> deleteMeter(Meter meter); |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 44 | |
Jordi Ortiz | aa8de49 | 2016-12-01 00:21:36 +0100 | [diff] [blame] | 45 | /** |
| 46 | * Adds the meter features to the store. |
| 47 | * |
| 48 | * @param meterfeatures the meter features |
| 49 | * @return the result of the store operation |
| 50 | */ |
| 51 | MeterStoreResult storeMeterFeatures(MeterFeatures meterfeatures); |
| 52 | |
| 53 | /** |
| 54 | * Deletes the meter features from the store. |
| 55 | * |
| 56 | * @param deviceId the device id |
| 57 | * @return a future indicating the result of the store operation |
| 58 | */ |
| 59 | MeterStoreResult deleteMeterFeatures(DeviceId deviceId); |
| 60 | |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 61 | /** |
| 62 | * Updates a meter whose meter id is the same as the passed meter. |
| 63 | * |
| 64 | * @param meter a new meter |
alshabib | eadfc8e | 2015-08-18 15:40:46 -0700 | [diff] [blame] | 65 | * @return a future indicating the result of the store operation |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 66 | */ |
alshabib | eadfc8e | 2015-08-18 15:40:46 -0700 | [diff] [blame] | 67 | CompletableFuture<MeterStoreResult> updateMeter(Meter meter); |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 68 | |
| 69 | /** |
| 70 | * Updates a given meter's state with the provided state. |
alshabib | eadfc8e | 2015-08-18 15:40:46 -0700 | [diff] [blame] | 71 | * |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 72 | * @param meter a meter |
| 73 | */ |
| 74 | void updateMeterState(Meter meter); |
| 75 | |
| 76 | /** |
alshabib | 70aaa1b | 2015-09-25 14:30:59 -0700 | [diff] [blame] | 77 | * Obtains a meter matching the given meter key. |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 78 | * |
alshabib | 70aaa1b | 2015-09-25 14:30:59 -0700 | [diff] [blame] | 79 | * @param key a meter key |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 80 | * @return a meter |
| 81 | */ |
alshabib | 70aaa1b | 2015-09-25 14:30:59 -0700 | [diff] [blame] | 82 | Meter getMeter(MeterKey key); |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 83 | |
| 84 | /** |
| 85 | * Returns all meters stored in the store. |
| 86 | * |
| 87 | * @return a collection of meters |
| 88 | */ |
| 89 | Collection<Meter> getAllMeters(); |
| 90 | |
| 91 | /** |
Jordi Ortiz | 9287b63 | 2017-06-22 11:01:37 +0200 | [diff] [blame] | 92 | * Returns all meters stored in the store for a |
| 93 | * precise device. |
| 94 | * |
| 95 | * @param deviceId the device to get the meter list from |
| 96 | * @return a collection of meters |
| 97 | */ |
| 98 | Collection<Meter> getAllMeters(DeviceId deviceId); |
| 99 | |
| 100 | /** |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 101 | * Update the store by deleting the failed meter. |
| 102 | * Notifies the delegate that the meter failed to allow it |
| 103 | * to nofity the app. |
| 104 | * |
| 105 | * @param op a failed meter operation |
| 106 | * @param reason a failure reason |
| 107 | */ |
| 108 | void failedMeter(MeterOperation op, MeterFailReason reason); |
alshabib | 5eb7939 | 2015-08-19 18:09:55 -0700 | [diff] [blame] | 109 | |
| 110 | /** |
| 111 | * Delete this meter immediately. |
| 112 | * @param m a meter |
| 113 | */ |
| 114 | void deleteMeterNow(Meter m); |
| 115 | |
Jordi Ortiz | aa8de49 | 2016-12-01 00:21:36 +0100 | [diff] [blame] | 116 | /** |
| 117 | * Retrieve maximum meters available for the device. |
| 118 | * |
| 119 | * @param key the meter features key |
| 120 | * @return the maximum number of meters supported by the device |
| 121 | */ |
| 122 | long getMaxMeters(MeterFeaturesKey key); |
| 123 | |
Jordi Ortiz | 6c84776 | 2017-01-30 17:13:05 +0100 | [diff] [blame] | 124 | /** |
Pier Luigi | f094c61 | 2017-10-14 12:15:02 +0200 | [diff] [blame] | 125 | * Allocates the first available MeterId. |
Jordi Ortiz | 6c84776 | 2017-01-30 17:13:05 +0100 | [diff] [blame] | 126 | * |
| 127 | * @param deviceId the device id |
Pier Luigi | f094c61 | 2017-10-14 12:15:02 +0200 | [diff] [blame] | 128 | * @return the meter Id or null if it was not possible |
| 129 | * to allocate a meter id |
Jordi Ortiz | 6c84776 | 2017-01-30 17:13:05 +0100 | [diff] [blame] | 130 | */ |
Pier Luigi | f094c61 | 2017-10-14 12:15:02 +0200 | [diff] [blame] | 131 | MeterId allocateMeterId(DeviceId deviceId); |
| 132 | |
| 133 | /** |
| 134 | * Frees the given meter id. |
| 135 | * |
| 136 | * @param deviceId the device id |
| 137 | * @param meterId the id to be freed |
| 138 | */ |
| 139 | void freeMeterId(DeviceId deviceId, MeterId meterId); |
Jordi Ortiz | 6c84776 | 2017-01-30 17:13:05 +0100 | [diff] [blame] | 140 | |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 141 | } |