alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
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 | /** |
| 47 | * Adds the meter features to the store. |
| 48 | * |
| 49 | * @param meterfeatures the meter features |
| 50 | * @return the result of the store operation |
| 51 | */ |
| 52 | MeterStoreResult storeMeterFeatures(MeterFeatures meterfeatures); |
| 53 | |
| 54 | /** |
| 55 | * Deletes the meter features from the store. |
| 56 | * |
| 57 | * @param deviceId the device id |
| 58 | * @return a future indicating the result of the store operation |
| 59 | */ |
| 60 | MeterStoreResult deleteMeterFeatures(DeviceId deviceId); |
| 61 | |
| 62 | |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 63 | /** |
| 64 | * Updates a meter whose meter id is the same as the passed meter. |
| 65 | * |
| 66 | * @param meter a new meter |
alshabib | eadfc8e | 2015-08-18 15:40:46 -0700 | [diff] [blame] | 67 | * @return a future indicating the result of the store operation |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 68 | */ |
alshabib | eadfc8e | 2015-08-18 15:40:46 -0700 | [diff] [blame] | 69 | CompletableFuture<MeterStoreResult> updateMeter(Meter meter); |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * Updates a given meter's state with the provided state. |
alshabib | eadfc8e | 2015-08-18 15:40:46 -0700 | [diff] [blame] | 73 | * |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 74 | * @param meter a meter |
| 75 | */ |
| 76 | void updateMeterState(Meter meter); |
| 77 | |
| 78 | /** |
alshabib | 70aaa1b | 2015-09-25 14:30:59 -0700 | [diff] [blame] | 79 | * Obtains a meter matching the given meter key. |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 80 | * |
alshabib | 70aaa1b | 2015-09-25 14:30:59 -0700 | [diff] [blame] | 81 | * @param key a meter key |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 82 | * @return a meter |
| 83 | */ |
alshabib | 70aaa1b | 2015-09-25 14:30:59 -0700 | [diff] [blame] | 84 | Meter getMeter(MeterKey key); |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * Returns all meters stored in the store. |
| 88 | * |
| 89 | * @return a collection of meters |
| 90 | */ |
| 91 | Collection<Meter> getAllMeters(); |
| 92 | |
| 93 | /** |
| 94 | * Update the store by deleting the failed meter. |
| 95 | * Notifies the delegate that the meter failed to allow it |
| 96 | * to nofity the app. |
| 97 | * |
| 98 | * @param op a failed meter operation |
| 99 | * @param reason a failure reason |
| 100 | */ |
| 101 | void failedMeter(MeterOperation op, MeterFailReason reason); |
alshabib | 5eb7939 | 2015-08-19 18:09:55 -0700 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | * Delete this meter immediately. |
| 105 | * @param m a meter |
| 106 | */ |
| 107 | void deleteMeterNow(Meter m); |
| 108 | |
Jordi Ortiz | aa8de49 | 2016-12-01 00:21:36 +0100 | [diff] [blame] | 109 | /** |
| 110 | * Retrieve maximum meters available for the device. |
| 111 | * |
| 112 | * @param key the meter features key |
| 113 | * @return the maximum number of meters supported by the device |
| 114 | */ |
| 115 | long getMaxMeters(MeterFeaturesKey key); |
| 116 | |
Jordi Ortiz | 6c84776 | 2017-01-30 17:13:05 +0100 | [diff] [blame] | 117 | /** |
| 118 | * Returns the first available MeterId from previously removed meter. |
| 119 | * This method allows allocating MeterIds below the actual meterIdCounter |
| 120 | * value. |
| 121 | * |
| 122 | * @param deviceId the device id |
| 123 | * @return the meter Id or null if none exist |
| 124 | */ |
| 125 | MeterId firstReusableMeterId(DeviceId deviceId); |
| 126 | |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 127 | } |