alshabib | a9b2b5d | 2015-09-23 15:01:47 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
alshabib | a9b2b5d | 2015-09-23 15:01:47 -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 | */ |
alshabib | 2ce0c73 | 2015-10-02 11:20:39 +0200 | [diff] [blame] | 16 | package org.onosproject.net.mcast; |
alshabib | a9b2b5d | 2015-09-23 15:01:47 -0700 | [diff] [blame] | 17 | |
| 18 | import org.onosproject.event.AbstractEvent; |
alshabib | a9b2b5d | 2015-09-23 15:01:47 -0700 | [diff] [blame] | 19 | |
Pier Luigi | 57d4179 | 2018-02-26 12:31:38 +0100 | [diff] [blame] | 20 | import java.util.Objects; |
| 21 | |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 22 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 23 | |
alshabib | a9b2b5d | 2015-09-23 15:01:47 -0700 | [diff] [blame] | 24 | /** |
| 25 | * An entity representing a multicast event. Event either add or remove |
| 26 | * sinks or sources. |
Ray Milkey | 50b1458 | 2017-08-23 09:55:02 -0700 | [diff] [blame] | 27 | * |
| 28 | * @deprecated in 1.11 ("Loon") release. To be moved into an app. |
alshabib | a9b2b5d | 2015-09-23 15:01:47 -0700 | [diff] [blame] | 29 | */ |
Ray Milkey | 50b1458 | 2017-08-23 09:55:02 -0700 | [diff] [blame] | 30 | @Deprecated |
alshabib | 79e5287 | 2015-12-07 16:01:01 -0800 | [diff] [blame] | 31 | public class McastEvent extends AbstractEvent<McastEvent.Type, McastRouteInfo> { |
alshabib | a9b2b5d | 2015-09-23 15:01:47 -0700 | [diff] [blame] | 32 | |
alshabib | a9b2b5d | 2015-09-23 15:01:47 -0700 | [diff] [blame] | 33 | |
| 34 | public enum Type { |
| 35 | /** |
| 36 | * A new mcast route has been added. |
| 37 | */ |
| 38 | ROUTE_ADDED, |
| 39 | |
| 40 | /** |
| 41 | * A mcast route has been removed. |
| 42 | */ |
| 43 | ROUTE_REMOVED, |
| 44 | |
| 45 | /** |
| 46 | * A source for a mcast route (ie. the subject) has been added. |
| 47 | */ |
| 48 | SOURCE_ADDED, |
| 49 | |
| 50 | /** |
Pier Luigi | 57d4179 | 2018-02-26 12:31:38 +0100 | [diff] [blame] | 51 | * A source for a mcast route has been updated. |
| 52 | */ |
| 53 | SOURCE_UPDATED, |
| 54 | |
| 55 | /** |
alshabib | a9b2b5d | 2015-09-23 15:01:47 -0700 | [diff] [blame] | 56 | * A sink for a mcast route (ie. the subject) has been added. |
| 57 | */ |
| 58 | SINK_ADDED, |
| 59 | |
| 60 | /** |
| 61 | * A source for a mcast route (ie. the subject) has been removed. |
| 62 | */ |
| 63 | SINK_REMOVED |
| 64 | } |
| 65 | |
Pier Luigi | 57d4179 | 2018-02-26 12:31:38 +0100 | [diff] [blame] | 66 | // Used when an update event happens |
| 67 | private McastRouteInfo prevSubject; |
| 68 | |
| 69 | /** |
| 70 | * Creates a McastEvent of a given type using the subject. |
| 71 | * |
| 72 | * @param type the event type |
| 73 | * @param subject the subject of the event type |
| 74 | */ |
alshabib | 79e5287 | 2015-12-07 16:01:01 -0800 | [diff] [blame] | 75 | public McastEvent(McastEvent.Type type, McastRouteInfo subject) { |
alshabib | a9b2b5d | 2015-09-23 15:01:47 -0700 | [diff] [blame] | 76 | super(type, subject); |
alshabib | a9b2b5d | 2015-09-23 15:01:47 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Pier Luigi | 57d4179 | 2018-02-26 12:31:38 +0100 | [diff] [blame] | 79 | /** |
| 80 | * Creates a McastEvent of a given type using the subject and |
| 81 | * the previous subject. |
| 82 | * |
| 83 | * @param type the event type |
| 84 | * @param subject the subject of the event |
| 85 | * @param prevSubject the previous subject of the event |
| 86 | */ |
| 87 | public McastEvent(McastEvent.Type type, McastRouteInfo subject, |
| 88 | McastRouteInfo prevSubject) { |
| 89 | super(type, subject); |
| 90 | // For now we have just this kind of updates |
| 91 | if (type == Type.SOURCE_UPDATED) { |
| 92 | this.prevSubject = prevSubject; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Gets the previous subject in this mcast event. |
| 98 | * |
| 99 | * @return the previous subject, or null if previous subject is not |
| 100 | * specified. |
| 101 | */ |
| 102 | public McastRouteInfo prevSubject() { |
| 103 | return this.prevSubject; |
| 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public int hashCode() { |
| 108 | return Objects.hash(type(), subject(), prevSubject); |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public boolean equals(Object other) { |
| 113 | if (this == other) { |
| 114 | return true; |
| 115 | } |
| 116 | |
| 117 | if (!(other instanceof McastEvent)) { |
| 118 | return false; |
| 119 | } |
| 120 | |
| 121 | McastEvent that = (McastEvent) other; |
| 122 | |
| 123 | return Objects.equals(this.subject(), that.subject()) && |
| 124 | Objects.equals(this.type(), that.type()) && |
| 125 | Objects.equals(this.prevSubject, that.prevSubject); |
| 126 | } |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 127 | |
| 128 | @Override |
| 129 | public String toString() { |
| 130 | return toStringHelper(this) |
| 131 | .add("type", type()) |
Pier Luigi | 57d4179 | 2018-02-26 12:31:38 +0100 | [diff] [blame] | 132 | .add("info", subject()) |
| 133 | .add("prevInfo", prevSubject()) |
| 134 | .toString(); |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 135 | } |
alshabib | a9b2b5d | 2015-09-23 15:01:47 -0700 | [diff] [blame] | 136 | } |