alshabib | eadfc8e | 2015-08-18 15:40:46 -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 | eadfc8e | 2015-08-18 15:40:46 -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 | eadfc8e | 2015-08-18 15:40:46 -0700 | [diff] [blame] | 17 | |
| 18 | import java.util.Optional; |
| 19 | |
| 20 | /** |
| 21 | * An entity used to indicate whether the store operation passed. |
| 22 | */ |
| 23 | public final class MeterStoreResult { |
| 24 | |
| 25 | |
| 26 | private final Type type; |
| 27 | private final Optional<MeterFailReason> reason; |
| 28 | |
| 29 | public enum Type { |
| 30 | SUCCESS, |
| 31 | FAIL |
| 32 | } |
| 33 | |
| 34 | private MeterStoreResult(Type type, MeterFailReason reason) { |
| 35 | this.type = type; |
| 36 | this.reason = Optional.ofNullable(reason); |
| 37 | } |
| 38 | |
| 39 | public Type type() { |
| 40 | return type; |
| 41 | } |
| 42 | |
| 43 | public Optional<MeterFailReason> reason() { |
| 44 | return reason; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * A successful store opertion. |
| 49 | * |
| 50 | * @return a meter store result |
| 51 | */ |
| 52 | public static MeterStoreResult success() { |
| 53 | return new MeterStoreResult(Type.SUCCESS, null); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * A failed store operation. |
| 58 | * |
| 59 | * @param reason a failure reason |
| 60 | * @return a meter store result |
| 61 | */ |
| 62 | public static MeterStoreResult fail(MeterFailReason reason) { |
| 63 | return new MeterStoreResult(Type.FAIL, reason); |
| 64 | } |
| 65 | |
| 66 | } |