Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -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.ovsdb.rfc.message; |
| 17 | |
| 18 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 19 | import static com.google.common.base.Preconditions.checkNotNull; |
| 20 | |
| 21 | import java.util.Objects; |
| 22 | |
| 23 | import org.onosproject.ovsdb.rfc.notation.json.UpdateNotificationConverter; |
| 24 | |
| 25 | import com.fasterxml.jackson.databind.JsonNode; |
| 26 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; |
| 27 | |
| 28 | /** |
| 29 | * The "update" notification is sent by the server to the client to report |
| 30 | * changes in tables that are being monitored following a "monitor" request. The |
| 31 | * "params" of the result JsonNode. |
| 32 | */ |
| 33 | @JsonDeserialize(converter = UpdateNotificationConverter.class) |
| 34 | public final class UpdateNotification { |
| 35 | private final Object jsonValue; |
| 36 | private final JsonNode tbUpdatesJsonNode; |
| 37 | |
| 38 | /** |
| 39 | * Constructs a UpdateNotification object. |
| 40 | * @param jsonValue the "json-value" in "params" of the result JsonNode |
| 41 | * @param tbUpdatesJsonNode the "table-updates" in "params" of the result JsonNode |
| 42 | */ |
| 43 | public UpdateNotification(Object jsonValue, JsonNode tbUpdatesJsonNode) { |
| 44 | checkNotNull(jsonValue, "jsonValue cannot be null"); |
| 45 | checkNotNull(tbUpdatesJsonNode, "tablebUpdates JsonNode cannot be null"); |
| 46 | this.jsonValue = jsonValue; |
| 47 | this.tbUpdatesJsonNode = tbUpdatesJsonNode; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Return context. |
| 52 | * @return context |
| 53 | */ |
| 54 | public Object jsonValue() { |
| 55 | return jsonValue; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Return tbUpdatesJsonNode. |
| 60 | * @return tbUpdatesJsonNode |
| 61 | */ |
| 62 | public JsonNode tbUpdatesJsonNode() { |
| 63 | return tbUpdatesJsonNode; |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public int hashCode() { |
| 68 | return Objects.hash(jsonValue, tbUpdatesJsonNode); |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public boolean equals(Object obj) { |
| 73 | if (this == obj) { |
| 74 | return true; |
| 75 | } |
| 76 | if (obj instanceof UpdateNotification) { |
| 77 | final UpdateNotification other = (UpdateNotification) obj; |
| 78 | return Objects.equals(this.jsonValue, other.jsonValue) |
| 79 | && Objects.equals(this.tbUpdatesJsonNode, |
| 80 | other.tbUpdatesJsonNode); |
| 81 | } |
| 82 | return false; |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public String toString() { |
| 87 | return toStringHelper(this).add("jsonValue", jsonValue) |
| 88 | .add("tbUpdatesJsonNode", tbUpdatesJsonNode).toString(); |
| 89 | } |
| 90 | } |