blob: d4ec6785b277eb1f789a12fff73ac954ce993384 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.cluster;
tom73d6d1e2014-09-17 20:08:01 -070017
Jon Hallb471f2c2017-04-05 09:07:39 -070018import com.google.common.base.MoreObjects;
Brian O'Connorabafb502014-12-02 22:26:20 -080019import org.onosproject.event.AbstractEvent;
tom73d6d1e2014-09-17 20:08:01 -070020
Jon Hallb471f2c2017-04-05 09:07:39 -070021import java.util.Objects;
22
tom73d6d1e2014-09-17 20:08:01 -070023/**
24 * Describes cluster-related event.
25 */
tome4729872014-09-23 00:37:37 -070026public class ClusterEvent extends AbstractEvent<ClusterEvent.Type, ControllerNode> {
tom73d6d1e2014-09-17 20:08:01 -070027
28 /**
tomfc9a4ff2014-09-22 18:22:47 -070029 * Type of cluster-related events.
tom73d6d1e2014-09-17 20:08:01 -070030 */
31 public enum Type {
32 /**
33 * Signifies that a new cluster instance has been administratively added.
34 */
35 INSTANCE_ADDED,
36
37 /**
38 * Signifies that a cluster instance has been administratively removed.
39 */
40 INSTANCE_REMOVED,
41
42 /**
43 * Signifies that a cluster instance became active.
44 */
tomfc9a4ff2014-09-22 18:22:47 -070045 INSTANCE_ACTIVATED,
tom73d6d1e2014-09-17 20:08:01 -070046
47 /**
Thomas Vachuskafba7f3d2016-03-23 15:46:25 -070048 * Signifies that a cluster instance became ready.
49 */
50 INSTANCE_READY,
51
52 /**
tom73d6d1e2014-09-17 20:08:01 -070053 * Signifies that a cluster instance became inactive.
54 */
tomfc9a4ff2014-09-22 18:22:47 -070055 INSTANCE_DEACTIVATED
tom73d6d1e2014-09-17 20:08:01 -070056 }
tom73d6d1e2014-09-17 20:08:01 -070057
pierventre55a5f392021-11-05 15:37:32 +010058 public enum InstanceType {
59 /**
60 * Signifies that the event refers to an ONOS instance.
61 */
62 ONOS,
63
64 /**
65 * Signifies that the event refers to an Atomix instance.
66 */
67 STORAGE,
68
69 /**
70 * Signifies that the event refers to an Unknown instance.
71 */
72 UNKNOWN
73 }
74
75 private final InstanceType instanceType;
76
tom73d6d1e2014-09-17 20:08:01 -070077 /**
78 * Creates an event of a given type and for the specified instance and the
79 * current time.
80 *
81 * @param type cluster event type
82 * @param instance cluster device subject
83 */
tome4729872014-09-23 00:37:37 -070084 public ClusterEvent(Type type, ControllerNode instance) {
pierventre55a5f392021-11-05 15:37:32 +010085 this(type, instance, InstanceType.UNKNOWN);
tom73d6d1e2014-09-17 20:08:01 -070086 }
87
88 /**
89 * Creates an event of a given type and for the specified device and time.
90 *
91 * @param type device event type
92 * @param instance event device subject
93 * @param time occurrence time
94 */
tome4729872014-09-23 00:37:37 -070095 public ClusterEvent(Type type, ControllerNode instance, long time) {
pierventre55a5f392021-11-05 15:37:32 +010096 this(type, instance, time, InstanceType.UNKNOWN);
tom73d6d1e2014-09-17 20:08:01 -070097 }
98
pierventre55a5f392021-11-05 15:37:32 +010099 /**
100 * Creates an event of a given type and for the specified instance and the
101 * current time.
102 *
103 * @param type cluster event type
104 * @param instance cluster device subject
105 * @param instanceType instance type
106 */
107 public ClusterEvent(Type type, ControllerNode instance, InstanceType instanceType) {
108 super(type, instance);
109 this.instanceType = instanceType;
110 }
111
112 /**
113 * Creates an event of a given type and for the specified device and time.
114 *
115 * @param type device event type
116 * @param instance event device subject
117 * @param time occurrence time
118 * @param instanceType instance type
119 */
120 public ClusterEvent(Type type, ControllerNode instance, long time, InstanceType instanceType) {
121 super(type, instance, time);
122 this.instanceType = instanceType;
123 }
124
125 /**
126 * Returns the instance type subject.
127 *
128 * @return instance type subject or UNKNOWN if the event is not instance type specific.
129 */
130 public InstanceType instanceType() {
131 return instanceType;
132 }
Jon Hallb471f2c2017-04-05 09:07:39 -0700133
134 @Override
135 public int hashCode() {
pierventre55a5f392021-11-05 15:37:32 +0100136 return Objects.hash(type(), subject(), time(), instanceType());
Jon Hallb471f2c2017-04-05 09:07:39 -0700137 }
138
139 @Override
140 public boolean equals(Object obj) {
141 if (this == obj) {
142 return true;
143 }
144 if (obj instanceof ClusterEvent) {
145 final ClusterEvent other = (ClusterEvent) obj;
146 return Objects.equals(this.type(), other.type()) &&
147 Objects.equals(this.subject(), other.subject()) &&
pierventre55a5f392021-11-05 15:37:32 +0100148 Objects.equals(this.time(), other.time()) &&
149 Objects.equals(this.instanceType(), other.instanceType());
Jon Hallb471f2c2017-04-05 09:07:39 -0700150 }
151 return false;
152 }
153
154 @Override
155 public String toString() {
156 return MoreObjects.toStringHelper(this.getClass())
157 .add("type", type())
158 .add("subject", subject())
159 .add("time", time())
pierventre55a5f392021-11-05 15:37:32 +0100160 .add("instanceType", instanceType())
Jon Hallb471f2c2017-04-05 09:07:39 -0700161 .toString();
162 }
163
tom73d6d1e2014-09-17 20:08:01 -0700164}