blob: 8c179dc517d90817bdebc6e0edca673090e3ee01 [file] [log] [blame]
Madan Jampani837a3632016-01-21 16:47:26 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Madan Jampani837a3632016-01-21 16:47:26 -08003 *
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.store.primitives;
17
18import org.onosproject.cluster.Partition;
19import org.onosproject.event.AbstractEvent;
20
Jon Hallf074af92017-04-05 15:10:46 -070021import java.util.Objects;
22
Madan Jampani837a3632016-01-21 16:47:26 -080023/**
24 * Describes partition-related event.
25 */
26public 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 Hallf074af92017-04-05 15:10:46 -070069
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 Jampani837a3632016-01-21 16:47:26 -080088}