blob: 38deac7a616ae2ea8aa31c3c6214a157037eb082 [file] [log] [blame]
Dimitrios Mavrommatisf0c06322017-10-31 23:49:04 -07001/*
2 * Copyright 2017-present Open Networking Foundation
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 */
16package org.onosproject.artemis.impl;
17
18import com.google.common.base.MoreObjects;
19import org.onosproject.event.AbstractEvent;
20
21import java.util.Objects;
22
23/**
24 * Artemis event.
25 */
26public class ArtemisEvent extends AbstractEvent<ArtemisEvent.Type, Object> {
27
28 /**
29 * Creates an event of a given type and for the specified state and the
30 * current time.
31 *
32 * @param type upgrade event type
33 * @param subject upgrade state
34 */
35 protected ArtemisEvent(Type type, Object subject) {
36 super(type, subject);
37 }
38
39 /**
40 * Creates an event of a given type and for the specified state and time.
41 *
42 * @param type upgrade event type
43 * @param subject upgrade state
44 * @param time occurrence time
45 */
46 protected ArtemisEvent(Type type, Object subject, long time) {
47 super(type, subject, time);
48 }
49
50 @Override
51 public int hashCode() {
52 return Objects.hash(type(), subject(), time());
53 }
54
55 @Override
56 public boolean equals(Object obj) {
57 if (this == obj) {
58 return true;
59 }
60 if (obj instanceof ArtemisEvent) {
61 final ArtemisEvent other = (ArtemisEvent) obj;
62 return Objects.equals(this.type(), other.type()) &&
63 Objects.equals(this.subject(), other.subject()) &&
64 Objects.equals(this.time(), other.time());
65 }
66 return false;
67 }
68
69 @Override
70 public String toString() {
71 return MoreObjects.toStringHelper(this.getClass())
72 .add("type", type())
73 .add("subject", subject())
74 .add("time", time())
75 .toString();
76 }
77
78 /**
79 * Type of artemis-related events.
80 */
81 public enum Type {
82
83 /**
84 * Indicates that a hijack was detected.
85 */
86 HIJACK_ADDED,
87
88 /**
89 * Indicates that a bgp update message was received.
90 */
91 BGPUPDATE_ADDED,
92 }
93}