Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.cluster; |
tom | 73d6d1e | 2014-09-17 20:08:01 -0700 | [diff] [blame] | 17 | |
Jon Hall | b471f2c | 2017-04-05 09:07:39 -0700 | [diff] [blame] | 18 | import com.google.common.base.MoreObjects; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 19 | import org.onosproject.event.AbstractEvent; |
tom | 73d6d1e | 2014-09-17 20:08:01 -0700 | [diff] [blame] | 20 | |
Jon Hall | b471f2c | 2017-04-05 09:07:39 -0700 | [diff] [blame] | 21 | import java.util.Objects; |
| 22 | |
tom | 73d6d1e | 2014-09-17 20:08:01 -0700 | [diff] [blame] | 23 | /** |
| 24 | * Describes cluster-related event. |
| 25 | */ |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 26 | public class ClusterEvent extends AbstractEvent<ClusterEvent.Type, ControllerNode> { |
tom | 73d6d1e | 2014-09-17 20:08:01 -0700 | [diff] [blame] | 27 | |
| 28 | /** |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 29 | * Type of cluster-related events. |
tom | 73d6d1e | 2014-09-17 20:08:01 -0700 | [diff] [blame] | 30 | */ |
| 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 | */ |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 45 | INSTANCE_ACTIVATED, |
tom | 73d6d1e | 2014-09-17 20:08:01 -0700 | [diff] [blame] | 46 | |
| 47 | /** |
Thomas Vachuska | fba7f3d | 2016-03-23 15:46:25 -0700 | [diff] [blame] | 48 | * Signifies that a cluster instance became ready. |
| 49 | */ |
| 50 | INSTANCE_READY, |
| 51 | |
| 52 | /** |
tom | 73d6d1e | 2014-09-17 20:08:01 -0700 | [diff] [blame] | 53 | * Signifies that a cluster instance became inactive. |
| 54 | */ |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 55 | INSTANCE_DEACTIVATED |
tom | 73d6d1e | 2014-09-17 20:08:01 -0700 | [diff] [blame] | 56 | } |
tom | 73d6d1e | 2014-09-17 20:08:01 -0700 | [diff] [blame] | 57 | |
| 58 | /** |
| 59 | * Creates an event of a given type and for the specified instance and the |
| 60 | * current time. |
| 61 | * |
| 62 | * @param type cluster event type |
| 63 | * @param instance cluster device subject |
| 64 | */ |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 65 | public ClusterEvent(Type type, ControllerNode instance) { |
tom | 73d6d1e | 2014-09-17 20:08:01 -0700 | [diff] [blame] | 66 | super(type, instance); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Creates an event of a given type and for the specified device and time. |
| 71 | * |
| 72 | * @param type device event type |
| 73 | * @param instance event device subject |
| 74 | * @param time occurrence time |
| 75 | */ |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 76 | public ClusterEvent(Type type, ControllerNode instance, long time) { |
tom | 73d6d1e | 2014-09-17 20:08:01 -0700 | [diff] [blame] | 77 | super(type, instance, time); |
| 78 | } |
| 79 | |
Jon Hall | b471f2c | 2017-04-05 09:07:39 -0700 | [diff] [blame] | 80 | |
| 81 | @Override |
| 82 | public int hashCode() { |
| 83 | return Objects.hash(type(), subject(), time()); |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public boolean equals(Object obj) { |
| 88 | if (this == obj) { |
| 89 | return true; |
| 90 | } |
| 91 | if (obj instanceof ClusterEvent) { |
| 92 | final ClusterEvent other = (ClusterEvent) obj; |
| 93 | return Objects.equals(this.type(), other.type()) && |
| 94 | Objects.equals(this.subject(), other.subject()) && |
| 95 | Objects.equals(this.time(), other.time()); |
| 96 | } |
| 97 | return false; |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public String toString() { |
| 102 | return MoreObjects.toStringHelper(this.getClass()) |
| 103 | .add("type", type()) |
| 104 | .add("subject", subject()) |
| 105 | .add("time", time()) |
| 106 | .toString(); |
| 107 | } |
| 108 | |
tom | 73d6d1e | 2014-09-17 20:08:01 -0700 | [diff] [blame] | 109 | } |