import com.google.common.util.concurrent.ListenableFuture;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
import javax.inject.Singleton;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.mastership.ReconciliationFrameworkEvent;
import org.opendaylight.openflowplugin.api.openflow.mastership.ReconciliationFrameworkRegistration;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.rf.state.rev170713.ResultState;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Singleton
+@Component(immediate = true)
public final class MastershipChangeServiceManagerImpl implements MastershipChangeServiceManager {
-
private static final Logger LOG = LoggerFactory.getLogger(MastershipChangeServiceManagerImpl.class);
private final List<MastershipChangeService> serviceGroup = new CopyOnWriteArrayList<>();
+
private ReconciliationFrameworkEvent rfService = null;
- private MasterChecker masterChecker;
+ private MasterChecker masterChecker = null;
+
+ @Inject
+ @Activate
+ public MastershipChangeServiceManagerImpl() {
+ // for DI only
+ }
+
+ @PreDestroy
+ @Deactivate
+ @Override
+ public void close() {
+ serviceGroup.clear();
+ }
- @NonNull
@Override
- public MastershipChangeRegistration register(@NonNull MastershipChangeService service) {
- final MastershipServiceDelegate registration =
- new MastershipServiceDelegate(service, () -> serviceGroup.remove(service));
+ public MastershipChangeRegistration register(final MastershipChangeService service) {
+ final var registration = new MastershipServiceDelegate(service, () -> serviceGroup.remove(service));
serviceGroup.add(service);
if (masterChecker != null && masterChecker.isAnyDeviceMastered()) {
masterChecker.listOfMasteredDevices().forEach(service::onBecomeOwner);
@Override
public ReconciliationFrameworkRegistration reconciliationFrameworkRegistration(
- @NonNull ReconciliationFrameworkEvent reconciliationFrameworkEvent) throws MastershipChangeException {
+ final ReconciliationFrameworkEvent reconciliationFrameworkEvent) throws MastershipChangeException {
if (rfService != null) {
throw new MastershipChangeException("Reconciliation framework already registered.");
- } else {
- rfService = reconciliationFrameworkEvent;
- return new ReconciliationFrameworkServiceDelegate(reconciliationFrameworkEvent, () -> rfService = null);
}
- }
-
- @Override
- public void close() {
- serviceGroup.clear();
+ rfService = reconciliationFrameworkEvent;
+ return new ReconciliationFrameworkServiceDelegate(reconciliationFrameworkEvent, () -> rfService = null);
}
@Override
@Override
public void becomeSlaveOrDisconnect(@NonNull final DeviceInfo deviceInfo) {
if (rfService != null) {
- ListenableFuture<Void> future = rfService.onDeviceDisconnected(deviceInfo);
+ final var future = rfService.onDeviceDisconnected(deviceInfo);
// TODO This null future check here should ideally not be required, but some tests currently rely on it
if (future != null) {
addErrorLogging(future, LOG, "onDeviceDisconnected() failed");
}
@Override
- public ListenableFuture<ResultState> becomeMasterBeforeSubmittedDS(@NonNull DeviceInfo deviceInfo) {
- return rfService == null ? Futures.immediateFuture(ResultState.DONOTHING) :
- rfService.onDevicePrepared(deviceInfo);
+ public ListenableFuture<ResultState> becomeMasterBeforeSubmittedDS(final DeviceInfo deviceInfo) {
+ return rfService == null ? Futures.immediateFuture(ResultState.DONOTHING)
+ : rfService.onDevicePrepared(deviceInfo);
}
@Override
<argument ref="notificationPublishService"/>
<argument ref="clusterSingletonServiceProvider"/>
<argument ref="entityOwnershipService"/>
- <argument ref="mastershipChangeServiceManagerImpl"/>
+ <argument ref="mastershipChangeServiceManager"/>
<argument ref="diagStatusProvider"/>
<argument ref="systemReadyMonitor"/>
</bean>
<reference id="ppDB"
interface="org.opendaylight.mdsal.binding.api.DataBroker"/>
- <bean id="mastershipChangeServiceManagerImpl"
- class="org.opendaylight.openflowplugin.impl.mastership.MastershipChangeServiceManagerImpl"/>
- <service ref="mastershipChangeServiceManagerImpl"
- interface="org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeServiceManager"/>
-
<reference id="switchConnectionProviderList"
interface="org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProviderList"
ext:proxy-method="classes"/>
interface="org.opendaylight.openflowplugin.impl.DiagStatusProvider"/>
<reference id="systemReadyMonitor"
interface="org.opendaylight.infrautils.ready.SystemReadyMonitor"/>
+ <reference id="mastershipChangeServiceManager"
+ interface="org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeServiceManager"/>
<odl:action-provider interface="org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService"/>
</blueprint>