blob: a859cd50327de7c1649e6a4a00e895558ffced08 [file] [log] [blame]
Jian Li93a13832016-02-09 11:21:47 -08001/*
2 * Copyright 2016 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 */
16package org.onosproject.cpman;
17
Jian Li72b9b122016-02-11 15:58:51 -080018import org.onosproject.net.DeviceId;
19
20import java.util.Objects;
21
22import static com.google.common.base.MoreObjects.toStringHelper;
23
Jian Li93a13832016-02-09 11:21:47 -080024/**
25 * Default control message implementation.
26 */
27public class DefaultControlMessage implements ControlMessage {
28
29 private final Type type;
Jian Li72b9b122016-02-11 15:58:51 -080030 private final DeviceId deviceId;
Jian Li93a13832016-02-09 11:21:47 -080031 private final long load;
32 private final long rate;
33 private final long count;
Jian Li72b9b122016-02-11 15:58:51 -080034 private final long timestamp;
Jian Li93a13832016-02-09 11:21:47 -080035
36 /**
37 * Generates a control message instance using given type and statistic
38 * information.
39 *
40 * @param type control message type
Jian Li72b9b122016-02-11 15:58:51 -080041 * @param deviceId device identification
Jian Li93a13832016-02-09 11:21:47 -080042 * @param load control message load
43 * @param rate control message rate
44 * @param count control message count
Jian Li72b9b122016-02-11 15:58:51 -080045 * @param timestamp time stamp of the control message stats
Jian Li93a13832016-02-09 11:21:47 -080046 */
Jian Li72b9b122016-02-11 15:58:51 -080047 public DefaultControlMessage(Type type, DeviceId deviceId, long load,
48 long rate, long count, long timestamp) {
Jian Li93a13832016-02-09 11:21:47 -080049 this.type = type;
Jian Li72b9b122016-02-11 15:58:51 -080050 this.deviceId = deviceId;
Jian Li93a13832016-02-09 11:21:47 -080051 this.load = load;
52 this.rate = rate;
53 this.count = count;
Jian Li72b9b122016-02-11 15:58:51 -080054 this.timestamp = timestamp;
Jian Li93a13832016-02-09 11:21:47 -080055 }
56
57 @Override
58 public Type type() {
59 return type;
60 }
61
62 @Override
Jian Li72b9b122016-02-11 15:58:51 -080063 public DeviceId deviceId() {
64 return deviceId;
65 }
66
67 @Override
Jian Li93a13832016-02-09 11:21:47 -080068 public long load() {
69 return load;
70 }
71
72 @Override
73 public long rate() {
74 return rate;
75 }
76
77 @Override
78 public long count() {
79 return count;
80 }
81
82 @Override
Jian Li72b9b122016-02-11 15:58:51 -080083 public long timestamp() {
84 return timestamp;
85 }
86
87 @Override
88 public int hashCode() {
89 return Objects.hash(type, deviceId.toString(), load, rate, count, timestamp);
90 }
91
92 @Override
93 public boolean equals(Object obj) {
94 if (this == obj) {
95 return true;
96 }
97 if (obj instanceof DefaultControlMessage) {
98 final DefaultControlMessage other = (DefaultControlMessage) obj;
99 return Objects.equals(this.type, other.type) &&
100 Objects.equals(this.deviceId, other.deviceId) &&
101 Objects.equals(this.load, other.load) &&
102 Objects.equals(this.rate, other.rate) &&
103 Objects.equals(this.count, other.count) &&
104 Objects.equals(this.timestamp, other.timestamp);
105 }
106 return false;
107 }
108
109 @Override
110 public String toString() {
111 return toStringHelper(this)
112 .add("type", type)
113 .add("deviceId", deviceId.toString())
114 .add("load", load)
115 .add("rate", rate)
116 .add("count", count)
117 .add("timestamp", timestamp)
118 .toString();
Jian Li93a13832016-02-09 11:21:47 -0800119 }
120}