alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | */ |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 16 | package org.onosproject.incubator.net.meter; |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 17 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | |
alshabib | eadfc8e | 2015-08-18 15:40:46 -0700 | [diff] [blame^] | 20 | import java.util.Optional; |
| 21 | |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 22 | /** |
| 23 | * Representation of an operation on the meter table. |
| 24 | */ |
| 25 | public class MeterOperation { |
| 26 | |
alshabib | eadfc8e | 2015-08-18 15:40:46 -0700 | [diff] [blame^] | 27 | private final Optional<MeterContext> context; |
| 28 | |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 29 | /** |
| 30 | * Tyoe of meter operation. |
| 31 | */ |
| 32 | public enum Type { |
| 33 | ADD, |
| 34 | REMOVE, |
| 35 | MODIFY |
| 36 | } |
| 37 | |
| 38 | private final Meter meter; |
| 39 | private final Type type; |
| 40 | |
| 41 | |
alshabib | eadfc8e | 2015-08-18 15:40:46 -0700 | [diff] [blame^] | 42 | public MeterOperation(Meter meter, Type type, MeterContext context) { |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 43 | this.meter = meter; |
| 44 | this.type = type; |
alshabib | eadfc8e | 2015-08-18 15:40:46 -0700 | [diff] [blame^] | 45 | this.context = Optional.ofNullable(context); |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Returns the type of operation. |
| 50 | * |
| 51 | * @return type |
| 52 | */ |
| 53 | public Type type() { |
| 54 | return type; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Returns the meter. |
| 59 | * |
| 60 | * @return a meter |
| 61 | */ |
| 62 | public Meter meter() { |
| 63 | return meter; |
| 64 | } |
| 65 | |
alshabib | eadfc8e | 2015-08-18 15:40:46 -0700 | [diff] [blame^] | 66 | /** |
| 67 | * Returns a context which allows application to |
| 68 | * be notified on the success value of this operation. |
| 69 | * |
| 70 | * @return a meter context |
| 71 | */ |
| 72 | public Optional<MeterContext> context() { |
| 73 | return this.context; |
| 74 | } |
| 75 | |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 76 | @Override |
| 77 | public String toString() { |
| 78 | return MoreObjects.toStringHelper(this) |
| 79 | .add("meter", meter) |
| 80 | .add("type", type) |
| 81 | .toString(); |
| 82 | } |
| 83 | } |