alshabib | a9b2b5d | 2015-09-23 15:01:47 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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 | |
alshabib | 2ce0c73 | 2015-10-02 11:20:39 +0200 | [diff] [blame^] | 18 | import com.google.common.annotations.Beta; |
alshabib | a9b2b5d | 2015-09-23 15:01:47 -0700 | [diff] [blame] | 19 | import org.onosproject.event.AbstractEvent; |
| 20 | import org.onosproject.net.ConnectPoint; |
| 21 | |
| 22 | import java.util.Optional; |
| 23 | |
| 24 | /** |
| 25 | * An entity representing a multicast event. Event either add or remove |
| 26 | * sinks or sources. |
| 27 | */ |
alshabib | 2ce0c73 | 2015-10-02 11:20:39 +0200 | [diff] [blame^] | 28 | @Beta |
alshabib | a9b2b5d | 2015-09-23 15:01:47 -0700 | [diff] [blame] | 29 | public class McastEvent extends AbstractEvent<McastEvent.Type, McastRoute> { |
| 30 | |
| 31 | private final Optional<ConnectPoint> sink; |
| 32 | private final Optional<ConnectPoint> source; |
| 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 | /** |
| 51 | * A source for a mcast route (ie. the subject) has been removed. |
| 52 | */ |
| 53 | SOURCE_REMOVED, |
| 54 | |
| 55 | /** |
| 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 | |
| 66 | private McastEvent(McastEvent.Type type, McastRoute subject) { |
| 67 | super(type, subject); |
| 68 | sink = Optional.empty(); |
| 69 | source = Optional.empty(); |
| 70 | } |
| 71 | |
| 72 | private McastEvent(McastEvent.Type type, McastRoute subject, long time) { |
| 73 | super(type, subject, time); |
| 74 | sink = Optional.empty(); |
| 75 | source = Optional.empty(); |
| 76 | } |
| 77 | |
| 78 | protected McastEvent(McastEvent.Type type, McastRoute subject, |
| 79 | ConnectPoint sink, |
| 80 | ConnectPoint source) { |
| 81 | super(type, subject); |
| 82 | this.sink = Optional.ofNullable(sink); |
| 83 | this.source = Optional.ofNullable(source); |
| 84 | } |
| 85 | |
| 86 | protected McastEvent(McastEvent.Type type, McastRoute subject, long time, |
| 87 | ConnectPoint sink, |
| 88 | ConnectPoint source) { |
| 89 | super(type, subject, time); |
| 90 | this.sink = Optional.ofNullable(sink); |
| 91 | this.source = Optional.ofNullable(source); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * The sink which has been removed or added. The field may not be set |
| 96 | * if the sink has not been detected yet or has been removed. |
| 97 | * |
| 98 | * @return an optional connect point |
| 99 | */ |
| 100 | public Optional<ConnectPoint> sink() { |
| 101 | return sink; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * The source which has been removed or added. The field may not be set |
| 106 | * if the source has not been detected yet or has been removed. |
| 107 | |
| 108 | * @return an optional connect point |
| 109 | */ |
| 110 | public Optional<ConnectPoint> source() { |
| 111 | return source; |
| 112 | } |
| 113 | } |