Sho SHIMIZU
Committed by Gerrit Code Review

Ignore config event if not master not to cause concurrent registrations

Change-Id: I1455ad9bbf373cd3b5742d35b8edb7392c4ca9d7
......@@ -23,6 +23,7 @@ import java.util.Set;
import java.util.concurrent.ExecutorService;
import org.onlab.util.Bandwidth;
import org.onosproject.mastership.MastershipService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.config.NetworkConfigEvent;
import org.onosproject.net.config.NetworkConfigListener;
......@@ -51,6 +52,7 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener {
private final ResourceAdminService adminService;
private final NetworkConfigService cfgService;
private final MastershipService mastershipService;
private final ExecutorService executor;
/**
......@@ -61,9 +63,10 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener {
* @param executor Executor to use.
*/
ResourceNetworkConfigListener(ResourceAdminService adminService, NetworkConfigService cfgService,
ExecutorService executor) {
MastershipService mastershipService, ExecutorService executor) {
this.adminService = checkNotNull(adminService);
this.cfgService = checkNotNull(cfgService);
this.mastershipService = checkNotNull(mastershipService);
this.executor = checkNotNull(executor);
}
......@@ -99,6 +102,10 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener {
checkArgument(event.configClass() == BandwidthCapacity.class);
ConnectPoint cp = (ConnectPoint) event.subject();
if (!mastershipService.isLocalMaster(cp.deviceId())) {
return;
}
BandwidthCapacity bwCapacity = cfgService.getConfig(cp, BandwidthCapacity.class);
switch (event.type()) {
......
......@@ -92,7 +92,7 @@ public final class ResourceRegistrar {
public void activate() {
factories.forEach(cfgRegistry::registerConfigFactory);
cfgListener = new ResourceNetworkConfigListener(adminService, cfgRegistry, executor);
cfgListener = new ResourceNetworkConfigListener(adminService, cfgRegistry, mastershipService, executor);
cfgRegistry.addListener(cfgListener);
deviceListener = new ResourceDeviceListener(adminService, resourceService,
......