blob: 50e6fe91f33c1e9a5e2ce5db65febffe04784f9d [file] [log] [blame]
alshabibbc371962015-07-09 22:26:21 -07001/*
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 */
alshabib10c810b2015-08-18 16:59:04 -070016package org.onosproject.net.meter;
alshabibbc371962015-07-09 22:26:21 -070017
18import com.google.common.base.MoreObjects;
19
alshabibeadfc8e2015-08-18 15:40:46 -070020import java.util.Optional;
21
alshabibbc371962015-07-09 22:26:21 -070022/**
23 * Representation of an operation on the meter table.
24 */
25public class MeterOperation {
26
alshabibeadfc8e2015-08-18 15:40:46 -070027 private final Optional<MeterContext> context;
28
alshabibbc371962015-07-09 22:26:21 -070029 /**
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
alshabibeadfc8e2015-08-18 15:40:46 -070042 public MeterOperation(Meter meter, Type type, MeterContext context) {
alshabibbc371962015-07-09 22:26:21 -070043 this.meter = meter;
44 this.type = type;
alshabibeadfc8e2015-08-18 15:40:46 -070045 this.context = Optional.ofNullable(context);
alshabibbc371962015-07-09 22:26:21 -070046 }
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
alshabibeadfc8e2015-08-18 15:40:46 -070066 /**
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
alshabibbc371962015-07-09 22:26:21 -070076 @Override
77 public String toString() {
78 return MoreObjects.toStringHelper(this)
79 .add("meter", meter)
80 .add("type", type)
81 .toString();
82 }
83}