Madan Jampani | 837a363 | 2016-01-21 16:47:26 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Madan Jampani | 837a363 | 2016-01-21 16:47:26 -0800 | [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.store.primitives; |
| 17 | |
| 18 | import org.onosproject.cluster.Partition; |
| 19 | import org.onosproject.event.AbstractEvent; |
| 20 | |
Jon Hall | f074af9 | 2017-04-05 15:10:46 -0700 | [diff] [blame] | 21 | import java.util.Objects; |
| 22 | |
Madan Jampani | 837a363 | 2016-01-21 16:47:26 -0800 | [diff] [blame] | 23 | /** |
| 24 | * Describes partition-related event. |
| 25 | */ |
| 26 | public class PartitionEvent extends AbstractEvent<PartitionEvent.Type, Partition> { |
| 27 | |
| 28 | /** |
| 29 | * Type of partition-related events. |
| 30 | */ |
| 31 | public enum Type { |
| 32 | |
| 33 | /** |
| 34 | * Signifies that a partition has been administratively updated. |
| 35 | */ |
| 36 | UPDATED, |
| 37 | |
| 38 | /** |
| 39 | * Signifies that a partition has been successfully opened. |
| 40 | */ |
| 41 | OPENED, |
| 42 | |
| 43 | /** |
| 44 | * Signifies that a partition has been successfully closed. |
| 45 | */ |
| 46 | CLOSED, |
| 47 | |
| 48 | /** |
| 49 | * Signifies that a partition is available for operations. |
| 50 | */ |
| 51 | AVAILABLE, |
| 52 | |
| 53 | /** |
| 54 | * Signifies that a partition is unavailable for operations. |
| 55 | */ |
| 56 | UNAVAILABLE, |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Creates an event of a given type and for the specified partition and time. |
| 61 | * |
| 62 | * @param type partition event type |
| 63 | * @param subject event partition subject |
| 64 | * @param time occurrence time |
| 65 | */ |
| 66 | protected PartitionEvent(Type type, Partition subject, long time) { |
| 67 | super(type, subject, time); |
| 68 | } |
Jon Hall | f074af9 | 2017-04-05 15:10:46 -0700 | [diff] [blame] | 69 | |
| 70 | @Override |
| 71 | public int hashCode() { |
| 72 | return Objects.hash(type(), subject(), time()); |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public boolean equals(Object obj) { |
| 77 | if (this == obj) { |
| 78 | return true; |
| 79 | } |
| 80 | if (obj instanceof PartitionEvent) { |
| 81 | final PartitionEvent other = (PartitionEvent) obj; |
| 82 | return Objects.equals(this.type(), other.type()) && |
| 83 | Objects.equals(this.subject(), other.subject()) && |
| 84 | Objects.equals(this.time(), other.time()); |
| 85 | } |
| 86 | return false; |
| 87 | } |
Madan Jampani | 837a363 | 2016-01-21 16:47:26 -0800 | [diff] [blame] | 88 | } |