Madan Jampani | ec1df02 | 2015-10-13 21:23:03 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Madan Jampani | ec1df02 | 2015-10-13 21:23:03 -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.cluster; |
| 17 | |
Jon Hall | 3557db5 | 2017-04-05 10:12:21 -0700 | [diff] [blame] | 18 | import com.google.common.base.MoreObjects; |
Madan Jampani | ec1df02 | 2015-10-13 21:23:03 -0700 | [diff] [blame] | 19 | import org.onosproject.event.AbstractEvent; |
| 20 | |
Jon Hall | 3557db5 | 2017-04-05 10:12:21 -0700 | [diff] [blame] | 21 | import java.util.Objects; |
| 22 | |
Madan Jampani | ec1df02 | 2015-10-13 21:23:03 -0700 | [diff] [blame] | 23 | /** |
| 24 | * Describes a cluster metadata event. |
| 25 | */ |
| 26 | public class ClusterMetadataEvent extends AbstractEvent<ClusterMetadataEvent.Type, ClusterMetadata> { |
| 27 | |
| 28 | /** |
| 29 | * Type of cluster metadata events. |
| 30 | */ |
| 31 | public enum Type { |
| 32 | /** |
| 33 | * Signifies that the cluster metadata has changed. |
| 34 | */ |
| 35 | METADATA_CHANGED, |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Creates an event of a given type and for the specified metadata and the |
| 40 | * current time. |
| 41 | * |
| 42 | * @param type cluster metadata event type |
| 43 | * @param metadata cluster metadata subject |
| 44 | */ |
| 45 | public ClusterMetadataEvent(Type type, ClusterMetadata metadata) { |
| 46 | super(type, metadata); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Creates an event of a given type and for the specified metadata and time. |
| 51 | * |
| 52 | * @param type cluster metadata event type |
| 53 | * @param metadata cluster metadata subject |
| 54 | * @param time occurrence time |
| 55 | */ |
| 56 | public ClusterMetadataEvent(Type type, ClusterMetadata metadata, long time) { |
| 57 | super(type, metadata, time); |
| 58 | } |
Jon Hall | 3557db5 | 2017-04-05 10:12:21 -0700 | [diff] [blame] | 59 | |
| 60 | @Override |
| 61 | public int hashCode() { |
| 62 | return Objects.hash(type(), subject(), time()); |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public boolean equals(Object obj) { |
| 67 | if (this == obj) { |
| 68 | return true; |
| 69 | } |
| 70 | if (obj instanceof ClusterMetadataEvent) { |
| 71 | final ClusterMetadataEvent other = (ClusterMetadataEvent) obj; |
| 72 | return Objects.equals(this.type(), other.type()) && |
| 73 | Objects.equals(this.subject(), other.subject()) && |
| 74 | Objects.equals(this.time(), other.time()); |
| 75 | } |
| 76 | return false; |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public String toString() { |
| 81 | return MoreObjects.toStringHelper(this.getClass()) |
| 82 | .add("type", type()) |
| 83 | .add("subject", subject()) |
| 84 | .add("time", time()) |
| 85 | .toString(); |
| 86 | } |
Madan Jampani | ec1df02 | 2015-10-13 21:23:03 -0700 | [diff] [blame] | 87 | } |