Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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 | |
| 17 | package org.onosproject.net.pi.runtime; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import com.google.common.base.MoreObjects; |
| 21 | import com.google.common.base.Objects; |
| 22 | import org.onosproject.net.DeviceId; |
| 23 | |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 24 | import static com.google.common.base.Preconditions.checkNotNull; |
| 25 | |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 26 | /** |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 27 | * Global identifier of a PI meter cell instantiated on a device, uniquely |
| 28 | * defined by a device ID and meter cell ID. |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 29 | */ |
| 30 | @Beta |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 31 | public final class PiMeterCellHandle extends PiHandle { |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 32 | |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 33 | private final PiMeterCellId cellId; |
| 34 | |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 35 | private PiMeterCellHandle(DeviceId deviceId, PiMeterCellId meterCellId) { |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 36 | super(deviceId); |
| 37 | this.cellId = meterCellId; |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | /** |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 41 | * Creates a new handle for the given device ID and PI meter cell ID. |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 42 | * |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 43 | * @param deviceId device ID |
| 44 | * @param meterCellId meter cell ID |
| 45 | * @return PI meter handle |
| 46 | */ |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 47 | public static PiMeterCellHandle of(DeviceId deviceId, |
| 48 | PiMeterCellId meterCellId) { |
| 49 | return new PiMeterCellHandle(deviceId, meterCellId); |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Creates a new handle for the given device ID and PI meter cell |
| 54 | * configuration. |
| 55 | * |
| 56 | * @param deviceId device ID |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 57 | * @param meterCellConfig meter config |
| 58 | * @return PI meter handle |
| 59 | */ |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 60 | public static PiMeterCellHandle of(DeviceId deviceId, |
| 61 | PiMeterCellConfig meterCellConfig) { |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 62 | checkNotNull(meterCellConfig); |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 63 | return new PiMeterCellHandle(deviceId, meterCellConfig.cellId()); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Returns the cell ID associated with this handle. |
| 68 | * |
| 69 | * @return cell ID |
| 70 | */ |
| 71 | public PiMeterCellId cellId() { |
| 72 | return cellId; |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public PiEntityType entityType() { |
| 77 | return PiEntityType.METER_CELL_CONFIG; |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public int hashCode() { |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 82 | return Objects.hashCode(deviceId(), cellId); |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public boolean equals(Object o) { |
| 87 | if (this == o) { |
| 88 | return true; |
| 89 | } |
| 90 | if (o == null || getClass() != o.getClass()) { |
| 91 | return false; |
| 92 | } |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 93 | PiMeterCellHandle that = (PiMeterCellHandle) o; |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 94 | return Objects.equal(deviceId(), that.deviceId()) && |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 95 | Objects.equal(cellId, that.cellId); |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public String toString() { |
| 100 | return MoreObjects.toStringHelper(this) |
| 101 | .add("deviceId", deviceId()) |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 102 | .add("meterCellId", cellId) |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 103 | .toString(); |
| 104 | } |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 105 | } |