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 | import org.onosproject.net.DeviceId; |
| 20 | |
| 21 | import java.util.Objects; |
| 22 | import java.util.Optional; |
| 23 | import java.util.concurrent.TimeUnit; |
| 24 | |
| 25 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 26 | |
| 27 | /** |
| 28 | * A container class that is used to request control metric of remote node. |
| 29 | */ |
| 30 | public class ControlMetricsRequest { |
| 31 | private final ControlMetricType type; |
| 32 | private Optional<DeviceId> deviceId; |
| 33 | private String resourceName; |
| 34 | private int duration; |
| 35 | private TimeUnit unit; |
| 36 | |
| 37 | /** |
| 38 | * Instantiates a new control metric request of the control metric type and |
| 39 | * device identifier. |
| 40 | * |
| 41 | * @param type control metric type |
| 42 | * @param deviceId device identifier |
| 43 | */ |
| 44 | public ControlMetricsRequest(ControlMetricType type, Optional<DeviceId> deviceId) { |
| 45 | this.type = type; |
| 46 | this.deviceId = deviceId; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Instantiates a new control metric request of the control metric type and |
| 51 | * device identifier with the given projected time range. |
| 52 | * |
| 53 | * @param type control metric type |
| 54 | * @param duration projected time duration |
| 55 | * @param unit projected time unit |
| 56 | * @param deviceId device dientifer |
| 57 | */ |
| 58 | public ControlMetricsRequest(ControlMetricType type, int duration, TimeUnit unit, |
| 59 | Optional<DeviceId> deviceId) { |
| 60 | this.type = type; |
| 61 | this.deviceId = deviceId; |
| 62 | this.duration = duration; |
| 63 | this.unit = unit; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Instantiates a new control metric request of the control metric type and |
| 68 | * resource name. |
| 69 | * |
| 70 | * @param type control metric type |
| 71 | * @param resourceName resource name |
| 72 | */ |
| 73 | public ControlMetricsRequest(ControlMetricType type, String resourceName) { |
| 74 | this.type = type; |
| 75 | this.resourceName = resourceName; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Instantiates a new control metric request of the control metric type and |
| 80 | * resource name with the given projected time range. |
| 81 | * |
| 82 | * @param type control metric type |
| 83 | * @param duration projected time duration |
| 84 | * @param unit projected time unit |
| 85 | * @param resourceName resource name |
| 86 | */ |
| 87 | public ControlMetricsRequest(ControlMetricType type, int duration, TimeUnit unit, |
| 88 | String resourceName) { |
| 89 | this.type = type; |
| 90 | this.resourceName = resourceName; |
| 91 | this.duration = duration; |
| 92 | this.unit = unit; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Obtains control metric type. |
| 97 | * |
| 98 | * @return control metric type |
| 99 | */ |
| 100 | public ControlMetricType getType() { |
| 101 | return type; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Obtains resource name. |
| 106 | * |
| 107 | * @return resource name |
| 108 | */ |
| 109 | public String getResourceName() { |
| 110 | return resourceName; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Obtains device identifier. |
| 115 | * |
| 116 | * @return device identifier |
| 117 | */ |
| 118 | public Optional<DeviceId> getDeviceId() { |
| 119 | return deviceId; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Obtains projected time duration. |
| 124 | * |
| 125 | * @return projected time duration |
| 126 | */ |
| 127 | public int getDuration() { |
| 128 | return duration; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Obtains projected time unit. |
| 133 | * |
| 134 | * @return projected time unit |
| 135 | */ |
| 136 | public TimeUnit getUnit() { |
| 137 | return unit; |
| 138 | } |
| 139 | |
| 140 | @Override |
| 141 | public int hashCode() { |
| 142 | return Objects.hash(type, deviceId, resourceName, duration, unit.toString()); |
| 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public boolean equals(Object obj) { |
| 147 | if (this == obj) { |
| 148 | return true; |
| 149 | } |
| 150 | if (obj instanceof ControlMetricsRequest) { |
| 151 | final ControlMetricsRequest other = (ControlMetricsRequest) obj; |
| 152 | return Objects.equals(this.type, other.type) && |
| 153 | Objects.equals(this.deviceId, other.deviceId) && |
| 154 | Objects.equals(this.resourceName, other.resourceName) && |
| 155 | Objects.equals(this.duration, other.duration) && |
| 156 | Objects.equals(this.unit, other.unit); |
| 157 | } |
| 158 | return false; |
| 159 | } |
| 160 | |
| 161 | @Override |
| 162 | public String toString() { |
| 163 | MoreObjects.ToStringHelper helper; |
| 164 | helper = toStringHelper(this) |
| 165 | .add("type", type) |
| 166 | .add("resourceName", resourceName) |
| 167 | .add("duration", duration) |
| 168 | .add("timeUnit", unit); |
| 169 | if (deviceId != null) { |
| 170 | helper.add("deviceId", deviceId.get()); |
| 171 | } |
| 172 | return helper.toString(); |
| 173 | } |
| 174 | } |