Make MastershipChangeServiceManagerImpl a component 79/110179/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 7 Feb 2024 11:25:13 +0000 (12:25 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 7 Feb 2024 17:17:03 +0000 (18:17 +0100)
This is a standalone component, let's activate it without blueprint.

JIRA: OPNFLWPLUG-1112
Change-Id: Icc9307c44641b8ae5f63c9696cd640c7c13d122d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/mastership/MastershipChangeServiceManagerImpl.java
openflowplugin-impl/src/main/resources/OSGI-INF/blueprint/openflowplugin-impl.xml

index f9443e2d2c8285076344d48963c3f254be1161a3..64c6497c87e4eb8534ab1bedc0fda73038aa41d3 100644 (file)
@@ -14,6 +14,8 @@ import com.google.common.util.concurrent.Futures;
 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;
@@ -25,23 +27,38 @@ import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeS
 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);
@@ -51,18 +68,12 @@ public final class MastershipChangeServiceManagerImpl implements MastershipChang
 
     @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
@@ -73,7 +84,7 @@ public final class MastershipChangeServiceManagerImpl implements MastershipChang
     @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");
@@ -83,9 +94,9 @@ public final class MastershipChangeServiceManagerImpl implements MastershipChang
     }
 
     @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
index 6413e46daa58f80384f3c889d734d22568c4a110..38a9d19b6407a83f00440ffb9e5320b7c2649952 100644 (file)
@@ -16,7 +16,7 @@
     <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"/>
@@ -80,6 +75,8 @@
              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>