alshabib
Committed by Gerrit Code Review

changing event posting to not post from compute.

This will probably have to change once we understand
how the mcastrib will be used.

Change-Id: Iebc2654732d1429b574c20830817d0f112249ada
...@@ -22,6 +22,8 @@ import org.onosproject.net.ConnectPoint; ...@@ -22,6 +22,8 @@ import org.onosproject.net.ConnectPoint;
22 import java.util.Collections; 22 import java.util.Collections;
23 import java.util.List; 23 import java.util.List;
24 24
25 +import static com.google.common.base.Preconditions.checkNotNull;
26 +
25 /** 27 /**
26 * Simple entity maintaining a mapping between a source and a collection of sink 28 * Simple entity maintaining a mapping between a source and a collection of sink
27 * connect points. 29 * connect points.
...@@ -30,25 +32,30 @@ public final class MulticastData { ...@@ -30,25 +32,30 @@ public final class MulticastData {
30 32
31 private final ConnectPoint source; 33 private final ConnectPoint source;
32 private final List<ConnectPoint> sinks; 34 private final List<ConnectPoint> sinks;
35 + private final boolean isEmpty;
33 36
34 private MulticastData() { 37 private MulticastData() {
35 this.source = null; 38 this.source = null;
36 this.sinks = Collections.EMPTY_LIST; 39 this.sinks = Collections.EMPTY_LIST;
40 + isEmpty = true;
37 } 41 }
38 42
39 public MulticastData(ConnectPoint source, List<ConnectPoint> sinks) { 43 public MulticastData(ConnectPoint source, List<ConnectPoint> sinks) {
40 - this.source = source; 44 + this.source = checkNotNull(source, "Multicast source cannot be null.");
41 - this.sinks = sinks; 45 + this.sinks = checkNotNull(sinks, "List of sinks cannot be null.");
46 + isEmpty = false;
42 } 47 }
43 48
44 public MulticastData(ConnectPoint source, ConnectPoint sink) { 49 public MulticastData(ConnectPoint source, ConnectPoint sink) {
45 - this.source = source; 50 + this.source = checkNotNull(source, "Multicast source cannot be null.");
46 - this.sinks = Lists.newArrayList(sink); 51 + this.sinks = Lists.newArrayList(checkNotNull(sink, "Sink cannot be null."));
52 + isEmpty = false;
47 } 53 }
48 54
49 public MulticastData(ConnectPoint source) { 55 public MulticastData(ConnectPoint source) {
50 - this.source = source; 56 + this.source = checkNotNull(source, "Multicast source cannot be null.");
51 this.sinks = Lists.newArrayList(); 57 this.sinks = Lists.newArrayList();
58 + isEmpty = false;
52 } 59 }
53 60
54 public ConnectPoint source() { 61 public ConnectPoint source() {
...@@ -68,7 +75,7 @@ public final class MulticastData { ...@@ -68,7 +75,7 @@ public final class MulticastData {
68 } 75 }
69 76
70 public boolean isEmpty() { 77 public boolean isEmpty() {
71 - return source == null && sinks.size() == 0; 78 + return isEmpty;
72 } 79 }
73 80
74 public static MulticastData empty() { 81 public static MulticastData empty() {
......
...@@ -38,6 +38,7 @@ import org.onosproject.store.service.Versioned; ...@@ -38,6 +38,7 @@ import org.onosproject.store.service.Versioned;
38 import org.slf4j.Logger; 38 import org.slf4j.Logger;
39 39
40 import java.util.List; 40 import java.util.List;
41 +import java.util.concurrent.atomic.AtomicReference;
41 42
42 import static org.slf4j.LoggerFactory.getLogger; 43 import static org.slf4j.LoggerFactory.getLogger;
43 44
...@@ -123,28 +124,38 @@ public class MulticastRouteManager ...@@ -123,28 +124,38 @@ public class MulticastRouteManager
123 124
124 @Override 125 @Override
125 public void addSink(McastRoute route, ConnectPoint connectPoint) { 126 public void addSink(McastRoute route, ConnectPoint connectPoint) {
127 + AtomicReference<ConnectPoint> source = new AtomicReference<>();
126 mcastRoutes.compute(route, (k, v) -> { 128 mcastRoutes.compute(route, (k, v) -> {
127 if (!v.isEmpty()) { 129 if (!v.isEmpty()) {
128 v.appendSink(connectPoint); 130 v.appendSink(connectPoint);
129 - post(new McastEvent(McastEvent.Type.SINK_ADDED, route, 131 + source.set(v.source());
130 - connectPoint, v.source()));
131 } else { 132 } else {
132 log.warn("Route {} does not exist"); 133 log.warn("Route {} does not exist");
133 } 134 }
134 return v; 135 return v;
135 }); 136 });
137 +
138 + if (source.get() != null) {
139 + post(new McastEvent(McastEvent.Type.SINK_ADDED, route,
140 + connectPoint, source.get()));
141 + }
136 } 142 }
137 143
138 144
139 @Override 145 @Override
140 public void removeSink(McastRoute route, ConnectPoint connectPoint) { 146 public void removeSink(McastRoute route, ConnectPoint connectPoint) {
147 + AtomicReference<ConnectPoint> source = new AtomicReference<>();
141 mcastRoutes.compute(route, (k, v) -> { 148 mcastRoutes.compute(route, (k, v) -> {
142 if (v.removeSink(connectPoint)) { 149 if (v.removeSink(connectPoint)) {
143 - post(new McastEvent(McastEvent.Type.SINK_REMOVED, route, 150 + source.set(v.source());
144 - connectPoint, v.source()));
145 } 151 }
146 return v; 152 return v;
147 }); 153 });
154 +
155 + if (source.get() != null) {
156 + post(new McastEvent(McastEvent.Type.SINK_REMOVED, route,
157 + connectPoint, source.get()));
158 + }
148 } 159 }
149 160
150 @Override 161 @Override
......