blob: b3f34ea849de0d1a7204d19bf5cf0ed0639c7815 [file] [log] [blame]
Jian Li67e1e152016-04-18 17:52:58 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Jian Li67e1e152016-04-18 17:52:58 -07003 *
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 */
16package org.onosproject.cpman;
17
18import com.google.common.base.MoreObjects;
19
Jian Li1aa07822016-04-19 17:58:02 -070020import java.util.Arrays;
Jian Li67e1e152016-04-18 17:52:58 -070021import java.util.Objects;
22
23import static com.google.common.base.MoreObjects.toStringHelper;
24
25/**
26 * A container class that is used to wrap the control metric response.
27 */
28public class ControlLoadSnapshot {
29
30 private final long latest;
31 private final long average;
32 private final long time;
Jian Li1aa07822016-04-19 17:58:02 -070033 private long[] recent;
Jian Li67e1e152016-04-18 17:52:58 -070034
35 /**
36 * Instantiates a new control metric response with given latest, average, time.
37 *
Jian Li1aa07822016-04-19 17:58:02 -070038 * @param latest latest value of control metric
Jian Li67e1e152016-04-18 17:52:58 -070039 * @param average average value of control metric
Jian Li1aa07822016-04-19 17:58:02 -070040 * @param time last logging time of control metric
Jian Li67e1e152016-04-18 17:52:58 -070041 */
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 Li1aa07822016-04-19 17:58:02 -070049 * 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 Li67e1e152016-04-18 17:52:58 -070065 * 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 Li1aa07822016-04-19 17:58:02 -070091 /**
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 Li67e1e152016-04-18 17:52:58 -0700100 @Override
101 public int hashCode() {
Jian Li1aa07822016-04-19 17:58:02 -0700102 return Objects.hash(latest, average, time, recent);
Jian Li67e1e152016-04-18 17:52:58 -0700103 }
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 Li1aa07822016-04-19 17:58:02 -0700114 Objects.equals(this.time, other.time) &&
115 Arrays.equals(this.recent, other.recent);
Jian Li67e1e152016-04-18 17:52:58 -0700116 }
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 Li1aa07822016-04-19 17:58:02 -0700126 .add("time", time)
127 .add("recent", recent);
128
Jian Li67e1e152016-04-18 17:52:58 -0700129 return helper.toString();
130 }
131}