blob: c98cc7ab9a0dc9c139f2547cb8eed70c6cf67d59 [file] [log] [blame]
Madan Jampaniec1df022015-10-13 21:23:03 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Madan Jampaniec1df022015-10-13 21:23:03 -07003 *
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.cluster;
17
Jon Hall3557db52017-04-05 10:12:21 -070018import com.google.common.base.MoreObjects;
Madan Jampaniec1df022015-10-13 21:23:03 -070019import org.onosproject.event.AbstractEvent;
20
Jon Hall3557db52017-04-05 10:12:21 -070021import java.util.Objects;
22
Madan Jampaniec1df022015-10-13 21:23:03 -070023/**
24 * Describes a cluster metadata event.
25 */
26public 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 Hall3557db52017-04-05 10:12:21 -070059
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 Jampaniec1df022015-10-13 21:23:03 -070087}