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;
import java.util.Collections;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Simple entity maintaining a mapping between a source and a collection of sink
* connect points.
......@@ -30,25 +32,30 @@ public final class MulticastData {
private final ConnectPoint source;
private final List<ConnectPoint> sinks;
private final boolean isEmpty;
private MulticastData() {
this.source = null;
this.sinks = Collections.EMPTY_LIST;
isEmpty = true;
}
public MulticastData(ConnectPoint source, List<ConnectPoint> sinks) {
this.source = source;
this.sinks = sinks;
this.source = checkNotNull(source, "Multicast source cannot be null.");
this.sinks = checkNotNull(sinks, "List of sinks cannot be null.");
isEmpty = false;
}
public MulticastData(ConnectPoint source, ConnectPoint sink) {
this.source = source;
this.sinks = Lists.newArrayList(sink);
this.source = checkNotNull(source, "Multicast source cannot be null.");
this.sinks = Lists.newArrayList(checkNotNull(sink, "Sink cannot be null."));
isEmpty = false;
}
public MulticastData(ConnectPoint source) {
this.source = source;
this.source = checkNotNull(source, "Multicast source cannot be null.");
this.sinks = Lists.newArrayList();
isEmpty = false;
}
public ConnectPoint source() {
......@@ -68,7 +75,7 @@ public final class MulticastData {
}
public boolean isEmpty() {
return source == null && sinks.size() == 0;
return isEmpty;
}
public static MulticastData empty() {
......
......@@ -38,6 +38,7 @@ import org.onosproject.store.service.Versioned;
import org.slf4j.Logger;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import static org.slf4j.LoggerFactory.getLogger;
......@@ -123,28 +124,38 @@ public class MulticastRouteManager
@Override
public void addSink(McastRoute route, ConnectPoint connectPoint) {
mcastRoutes.compute(route, (k, v) -> {
AtomicReference<ConnectPoint> source = new AtomicReference<>();
mcastRoutes.compute(route, (k, v) -> {
if (!v.isEmpty()) {
v.appendSink(connectPoint);
post(new McastEvent(McastEvent.Type.SINK_ADDED, route,
connectPoint, v.source()));
source.set(v.source());
} else {
log.warn("Route {} does not exist");
}
return v;
});
if (source.get() != null) {
post(new McastEvent(McastEvent.Type.SINK_ADDED, route,
connectPoint, source.get()));
}
}
@Override
public void removeSink(McastRoute route, ConnectPoint connectPoint) {
AtomicReference<ConnectPoint> source = new AtomicReference<>();
mcastRoutes.compute(route, (k, v) -> {
if (v.removeSink(connectPoint)) {
post(new McastEvent(McastEvent.Type.SINK_REMOVED, route,
connectPoint, v.source()));
source.set(v.source());
}
return v;
});
if (source.get() != null) {
post(new McastEvent(McastEvent.Type.SINK_REMOVED, route,
connectPoint, source.get()));
}
}
@Override
......