OPNFLWPLUG-1071 : Removal of javax.annotation.Nonnnull and replacement of javax.annot...
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / mastership / MastershipChangeServiceManagerImpl.java
index 240c2411aaad734fbda52b8c8a77f62ba62a3d35..dd6e81c367e5f8483d80df9139f8ae303e52515a 100644 (file)
@@ -7,12 +7,15 @@
  */
 package org.opendaylight.openflowplugin.impl.mastership;
 
+import static org.opendaylight.infrautils.utils.concurrent.LoggingFutures.addErrorLogging;
+
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.util.concurrent.ListenableFuture;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
-import javax.annotation.Nonnull;
+import javax.inject.Singleton;
+import org.apache.aries.blueprint.annotation.service.Service;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.lifecycle.MasterChecker;
 import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeException;
@@ -22,16 +25,22 @@ 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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
+@Singleton
+@Service(classes = MastershipChangeServiceManager.class)
 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;
 
-    @Nonnull
+    @NonNull
     @Override
-    public MastershipChangeRegistration register(@Nonnull MastershipChangeService service) {
+    public MastershipChangeRegistration register(@NonNull MastershipChangeService service) {
         final MastershipServiceDelegate registration =
                 new MastershipServiceDelegate(service, () -> serviceGroup.remove(service));
         serviceGroup.add(service);
@@ -43,7 +52,7 @@ public final class MastershipChangeServiceManagerImpl implements MastershipChang
 
     @Override
     public ReconciliationFrameworkRegistration reconciliationFrameworkRegistration(
-            @Nonnull ReconciliationFrameworkEvent reconciliationFrameworkEvent) throws MastershipChangeException {
+            @NonNull ReconciliationFrameworkEvent reconciliationFrameworkEvent) throws MastershipChangeException {
         if (rfService != null) {
             throw new MastershipChangeException("Reconciliation framework already registered.");
         } else {
@@ -58,27 +67,29 @@ public final class MastershipChangeServiceManagerImpl implements MastershipChang
     }
 
     @Override
-    public void becomeMaster(@Nonnull final DeviceInfo deviceInfo) {
+    public void becomeMaster(@NonNull final DeviceInfo deviceInfo) {
         serviceGroup.forEach(mastershipChangeService -> mastershipChangeService.onBecomeOwner(deviceInfo));
     }
 
     @Override
-    // FB flags this for onDeviceDisconnected but unclear why - seems a false positive.
-    @SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT")
-    public void becomeSlaveOrDisconnect(@Nonnull final DeviceInfo deviceInfo) {
+    public void becomeSlaveOrDisconnect(@NonNull final DeviceInfo deviceInfo) {
         if (rfService != null) {
-            rfService.onDeviceDisconnected(deviceInfo);
+            ListenableFuture<Void> 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");
+            }
         }
         serviceGroup.forEach(mastershipChangeService -> mastershipChangeService.onLoseOwnership(deviceInfo));
     }
 
     @Override
-    public ListenableFuture<ResultState> becomeMasterBeforeSubmittedDS(@Nonnull DeviceInfo deviceInfo) {
+    public ListenableFuture<ResultState> becomeMasterBeforeSubmittedDS(@NonNull DeviceInfo deviceInfo) {
         return rfService == null ? null : rfService.onDevicePrepared(deviceInfo);
     }
 
     @Override
-    public void setMasterChecker(@Nonnull final MasterChecker masterChecker) {
+    public void setMasterChecker(@NonNull final MasterChecker masterChecker) {
         this.masterChecker = masterChecker;
     }