Update MRI projects for Aluminium
[netconf.git] / netconf / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / sal / NetconfDeviceSalProvider.java
index ca84151ae9e208923bf0a4af3353e8cc065dc68f..5dd2418603f5899444939893cc3caaf7dc5a87e6 100644 (file)
@@ -7,27 +7,29 @@
  */
 package org.opendaylight.netconf.sal.connect.netconf.sal;
 
-import com.google.common.base.Preconditions;
-import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
-import org.opendaylight.controller.md.sal.dom.api.DOMActionService;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
-import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
-import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
-import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.Transaction;
+import org.opendaylight.mdsal.binding.api.TransactionChain;
+import org.opendaylight.mdsal.binding.api.TransactionChainListener;
+import org.opendaylight.mdsal.dom.api.DOMActionService;
+import org.opendaylight.mdsal.dom.api.DOMDataBroker;
+import org.opendaylight.mdsal.dom.api.DOMMountPoint;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService;
+import org.opendaylight.mdsal.dom.api.DOMNotification;
+import org.opendaylight.mdsal.dom.api.DOMNotificationService;
+import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.yangtools.concepts.ObjectRegistration;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class NetconfDeviceSalProvider implements AutoCloseable {
-
     private static final Logger LOG = LoggerFactory.getLogger(NetconfDeviceSalProvider.class);
 
     private final RemoteDeviceId id;
@@ -36,12 +38,12 @@ public class NetconfDeviceSalProvider implements AutoCloseable {
 
     private volatile NetconfDeviceTopologyAdapter topologyDatastoreAdapter;
 
-    private BindingTransactionChain txChain;
+    private TransactionChain txChain;
 
     private final TransactionChainListener transactionChainListener =  new TransactionChainListener() {
         @Override
-        public void onTransactionChainFailed(final TransactionChain<?, ?> chain,
-                                             final AsyncTransaction<?, ?> transaction, final Throwable cause) {
+        public void onTransactionChainFailed(final TransactionChain chain, final Transaction transaction,
+                final Throwable cause) {
             LOG.error("{}: TransactionChain({}) {} FAILED!", id, chain, transaction.getIdentifier(), cause);
             chain.close();
             resetTransactionChainForAdapaters();
@@ -49,7 +51,7 @@ public class NetconfDeviceSalProvider implements AutoCloseable {
         }
 
         @Override
-        public void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) {
+        public void onTransactionChainSuccessful(final TransactionChain chain) {
             LOG.trace("{}: TransactionChain({}) SUCCESSFUL", id, chain);
         }
     };
@@ -64,30 +66,30 @@ public class NetconfDeviceSalProvider implements AutoCloseable {
         mountInstance = new MountInstance(mountService, id);
         this.dataBroker = dataBroker;
         if (dataBroker != null) {
-            txChain = Preconditions.checkNotNull(dataBroker).createTransactionChain(transactionChainListener);
+            txChain = requireNonNull(dataBroker).createTransactionChain(transactionChainListener);
             topologyDatastoreAdapter = new NetconfDeviceTopologyAdapter(id, txChain);
         }
     }
 
     public MountInstance getMountInstance() {
-        Preconditions.checkState(mountInstance != null,
-                "%s: Mount instance was not initialized by sal. Cannot get mount instance", id);
+        checkState(mountInstance != null, "%s: Mount instance was not initialized by sal. Cannot get mount instance",
+                id);
         return mountInstance;
     }
 
     public NetconfDeviceTopologyAdapter getTopologyDatastoreAdapter() {
-        Preconditions.checkState(topologyDatastoreAdapter != null,
-                "%s: Sal provider %s was not initialized by sal. Cannot get topology datastore adapter", id);
-        return topologyDatastoreAdapter;
+        final NetconfDeviceTopologyAdapter local = topologyDatastoreAdapter;
+        checkState(local != null,
+                "%s: Sal provider %s was not initialized by sal. Cannot get topology datastore adapter", id, this);
+        return local;
     }
 
+    @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
+            justification = "https://github.com/spotbugs/spotbugs/issues/811")
     private void resetTransactionChainForAdapaters() {
-        txChain = Preconditions.checkNotNull(dataBroker).createTransactionChain(transactionChainListener);
-
+        txChain = requireNonNull(dataBroker).createTransactionChain(transactionChainListener);
         topologyDatastoreAdapter.setTxChain(txChain);
-
         LOG.trace("{}: Resetting TransactionChain {}", id, txChain);
-
     }
 
     @Override
@@ -111,21 +113,21 @@ public class NetconfDeviceSalProvider implements AutoCloseable {
         private ObjectRegistration<DOMMountPoint> topologyRegistration;
 
         MountInstance(final DOMMountPointService mountService, final RemoteDeviceId id) {
-            this.mountService = Preconditions.checkNotNull(mountService);
-            this.id = Preconditions.checkNotNull(id);
+            this.mountService = requireNonNull(mountService);
+            this.id = requireNonNull(id);
         }
 
-        public void onTopologyDeviceConnected(final SchemaContext initialCtx,
+        public void onTopologyDeviceConnected(final EffectiveModelContext initialCtx,
                 final DOMDataBroker broker, final DOMRpcService rpc,
                 final NetconfDeviceNotificationService newNotificationService) {
             onTopologyDeviceConnected(initialCtx, broker, rpc, newNotificationService, null);
         }
 
-        public synchronized void onTopologyDeviceConnected(final SchemaContext initialCtx,
+        public synchronized void onTopologyDeviceConnected(final EffectiveModelContext initialCtx,
                 final DOMDataBroker broker, final DOMRpcService rpc,
                 final NetconfDeviceNotificationService newNotificationService, final DOMActionService deviceAction) {
-            Preconditions.checkNotNull(mountService, "Closed");
-            Preconditions.checkState(topologyRegistration == null, "Already initialized");
+            requireNonNull(mountService, "Closed");
+            checkState(topologyRegistration == null, "Already initialized");
 
             final DOMMountPointService.DOMMountPointBuilder mountBuilder =
                     mountService.createMountPoint(id.getTopologyPath());
@@ -167,9 +169,8 @@ public class NetconfDeviceSalProvider implements AutoCloseable {
         }
 
         public synchronized void publish(final DOMNotification domNotification) {
-            Preconditions.checkNotNull(notificationService, "Device not set up yet, cannot handle notification {}",
-                    domNotification);
-            notificationService.publishNotification(domNotification);
+            checkNotNull(notificationService, "Device not set up yet, cannot handle notification %s", domNotification)
+                .publishNotification(domNotification);
         }
     }