blob: 9230736942fdc5635ec6532a59a788a48aa9a703 [file] [log] [blame]
Andrea Campanella545edb42018-03-20 16:37:29 -07001/*
2 * Copyright 2018-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.mcast.api;
17
18import com.google.common.annotations.Beta;
19import org.onosproject.event.AbstractEvent;
20
21import java.util.Objects;
22
23import static com.google.common.base.MoreObjects.toStringHelper;
24
25/**
26 * An entity representing a multicast event. Event either add or remove
27 * sinks or sources.
28 */
29@Beta
30public class McastEvent extends AbstractEvent<McastEvent.Type, McastRouteUpdate> {
31
32 /**
33 * Mcast Event type enum.
34 */
35 public enum Type {
36 /**
37 * A new mcast route has been added.
38 */
39 ROUTE_ADDED,
40
41 /**
42 * A mcast route has been removed.
43 */
44 ROUTE_REMOVED,
45
46 /**
47 * A set of sources for a mcast route (ie. the subject) has been added.
48 */
49 SOURCES_ADDED,
50
51 /**
52 * A set of sources for a mcast route has been removed.
53 */
54 SOURCES_REMOVED,
55
56 /**
57 * A set of sinks for a mcast route (ie. the subject) has been added.
58 */
59 SINKS_ADDED,
60
61 /**
62 * A set of sinks for a mcast route (ie. the subject) has been removed.
63 */
64 SINKS_REMOVED
65 }
66
67 private McastRouteUpdate prevSubject;
68
69 /**
70 * Creates a McastEvent of a given type using the subject.
71 *
72 * @param type the event type
73 * @param prevSubject the previous mcast information
74 * @param subject the current mcast information
75 */
76 public McastEvent(McastEvent.Type type, McastRouteUpdate prevSubject, McastRouteUpdate subject) {
77 super(type, subject);
78 this.prevSubject = prevSubject;
79 }
80
81 /**
82 * Gets the previous subject in this Mcast event.
83 *
84 * @return the previous subject, or null if previous subject is not
85 * specified.
86 */
87 public McastRouteUpdate prevSubject() {
88 return this.prevSubject;
89 }
90
91 @Override
92 public int hashCode() {
93 return Objects.hash(type(), subject(), prevSubject());
94 }
95
96 @Override
97 public boolean equals(Object other) {
98 if (this == other) {
99 return true;
100 }
101
102 if (!(other instanceof McastEvent)) {
103 return false;
104 }
105
106 McastEvent that = (McastEvent) other;
107
108 return Objects.equals(this.subject(), that.subject()) &&
109 Objects.equals(this.type(), that.type()) &&
110 Objects.equals(this.prevSubject(), that.prevSubject());
111 }
112
113 @Override
114 public String toString() {
115 return toStringHelper(this)
116 .add("type", type())
117 .add("prevSubject", prevSubject())
118 .add("subject", subject())
119 .toString();
120 }
121}