Jian Li | 67e1e15 | 2016-04-18 17:52:58 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Jian Li | 67e1e15 | 2016-04-18 17:52:58 -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 | */ |
| 16 | package org.onosproject.cpman; |
| 17 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | |
Jian Li | 1aa0782 | 2016-04-19 17:58:02 -0700 | [diff] [blame] | 20 | import java.util.Arrays; |
Jian Li | 67e1e15 | 2016-04-18 17:52:58 -0700 | [diff] [blame] | 21 | import java.util.Objects; |
| 22 | |
| 23 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 24 | |
| 25 | /** |
| 26 | * A container class that is used to wrap the control metric response. |
| 27 | */ |
| 28 | public class ControlLoadSnapshot { |
| 29 | |
| 30 | private final long latest; |
| 31 | private final long average; |
| 32 | private final long time; |
Jian Li | 1aa0782 | 2016-04-19 17:58:02 -0700 | [diff] [blame] | 33 | private long[] recent; |
Jian Li | 67e1e15 | 2016-04-18 17:52:58 -0700 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Instantiates a new control metric response with given latest, average, time. |
| 37 | * |
Jian Li | 1aa0782 | 2016-04-19 17:58:02 -0700 | [diff] [blame] | 38 | * @param latest latest value of control metric |
Jian Li | 67e1e15 | 2016-04-18 17:52:58 -0700 | [diff] [blame] | 39 | * @param average average value of control metric |
Jian Li | 1aa0782 | 2016-04-19 17:58:02 -0700 | [diff] [blame] | 40 | * @param time last logging time of control metric |
Jian Li | 67e1e15 | 2016-04-18 17:52:58 -0700 | [diff] [blame] | 41 | */ |
| 42 | public ControlLoadSnapshot(long latest, long average, long time) { |
| 43 | this.latest = latest; |
| 44 | this.average = average; |
| 45 | this.time = time; |
| 46 | } |
| 47 | |
| 48 | /** |
Jian Li | 1aa0782 | 2016-04-19 17:58:02 -0700 | [diff] [blame] | 49 | * Instantiates a new control metric response with given latest, average, time, |
| 50 | * recent values. |
| 51 | * |
| 52 | * @param latest latest value of control metric |
| 53 | * @param average average value of control metric |
| 54 | * @param time last logging time of control metric |
| 55 | * @param recent a set of historical data |
| 56 | */ |
| 57 | public ControlLoadSnapshot(long latest, long average, long time, long[] recent) { |
| 58 | this.latest = latest; |
| 59 | this.average = average; |
| 60 | this.time = time; |
| 61 | this.recent = recent; |
| 62 | } |
| 63 | |
| 64 | /** |
Jian Li | 67e1e15 | 2016-04-18 17:52:58 -0700 | [diff] [blame] | 65 | * Returns latest value of control metric. |
| 66 | * |
| 67 | * @return latest value of control metric |
| 68 | */ |
| 69 | public long latest() { |
| 70 | return latest; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Returns last logging time of control metric. |
| 75 | * |
| 76 | * @return last logging time of control metric |
| 77 | */ |
| 78 | public long time() { |
| 79 | return time; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Returns average value of control metric. |
| 84 | * |
| 85 | * @return average value of control metric |
| 86 | */ |
| 87 | public long average() { |
| 88 | return average; |
| 89 | } |
| 90 | |
Jian Li | 1aa0782 | 2016-04-19 17:58:02 -0700 | [diff] [blame] | 91 | /** |
| 92 | * Returns a set of historical recent of control metric. |
| 93 | * |
| 94 | * @return a set of historical recent of control metric |
| 95 | */ |
| 96 | public long[] recent() { |
| 97 | return recent; |
| 98 | } |
| 99 | |
Jian Li | 67e1e15 | 2016-04-18 17:52:58 -0700 | [diff] [blame] | 100 | @Override |
| 101 | public int hashCode() { |
Jian Li | 1aa0782 | 2016-04-19 17:58:02 -0700 | [diff] [blame] | 102 | return Objects.hash(latest, average, time, recent); |
Jian Li | 67e1e15 | 2016-04-18 17:52:58 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public boolean equals(Object obj) { |
| 107 | if (this == obj) { |
| 108 | return true; |
| 109 | } |
| 110 | if (obj instanceof ControlLoadSnapshot) { |
| 111 | final ControlLoadSnapshot other = (ControlLoadSnapshot) obj; |
| 112 | return Objects.equals(this.latest, other.latest) && |
| 113 | Objects.equals(this.average, other.average) && |
Jian Li | 1aa0782 | 2016-04-19 17:58:02 -0700 | [diff] [blame] | 114 | Objects.equals(this.time, other.time) && |
| 115 | Arrays.equals(this.recent, other.recent); |
Jian Li | 67e1e15 | 2016-04-18 17:52:58 -0700 | [diff] [blame] | 116 | } |
| 117 | return false; |
| 118 | } |
| 119 | |
| 120 | @Override |
| 121 | public String toString() { |
| 122 | MoreObjects.ToStringHelper helper; |
| 123 | helper = toStringHelper(this) |
| 124 | .add("latest", latest) |
| 125 | .add("average", average) |
Jian Li | 1aa0782 | 2016-04-19 17:58:02 -0700 | [diff] [blame] | 126 | .add("time", time) |
| 127 | .add("recent", recent); |
| 128 | |
Jian Li | 67e1e15 | 2016-04-18 17:52:58 -0700 | [diff] [blame] | 129 | return helper.toString(); |
| 130 | } |
| 131 | } |