Sonar - technical debt of FRS app
[openflowplugin.git] / applications / forwardingrules-sync / src / main / java / org / opendaylight / openflowplugin / applications / frsync / impl / SyncReactorGuardDecorator.java
index e40b3b2200a1eda0fd070ea7553a6f8ba75e5f49..3f1b2716a3f743ccadfa1cad969f5c295d906205 100644 (file)
@@ -15,10 +15,10 @@ import com.google.common.util.concurrent.ListenableFuture;
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.TimeUnit;
 import javax.annotation.Nullable;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.openflowplugin.applications.frsync.SemaphoreKeeper;
 import org.opendaylight.openflowplugin.applications.frsync.SyncReactor;
 import org.opendaylight.openflowplugin.applications.frsync.util.PathUtil;
+import org.opendaylight.openflowplugin.applications.frsync.util.SyncupEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -42,10 +42,9 @@ public class SyncReactorGuardDecorator implements SyncReactor {
     }
 
     public ListenableFuture<Boolean> syncup(final InstanceIdentifier<FlowCapableNode> flowcapableNodePath,
-                                            final FlowCapableNode configTree, final FlowCapableNode operationalTree,
-                                            final LogicalDatastoreType dsType) throws InterruptedException {
+                                            final SyncupEntry syncupEntry) throws InterruptedException {
         final NodeId nodeId = PathUtil.digNodeId(flowcapableNodePath);
-        LOG.trace("syncup guard {}", nodeId.getValue());
+        LOG.trace("syncup guard decorator: {}", nodeId.getValue());
 
         final long stampBeforeGuard = System.nanoTime();
         final Semaphore guard = summonGuardAndAcquire(flowcapableNodePath);
@@ -62,37 +61,9 @@ public class SyncReactorGuardDecorator implements SyncReactor {
             }
 
             final ListenableFuture<Boolean> endResult =
-                    delegate.syncup(flowcapableNodePath, configTree, operationalTree, dsType);
-
-            Futures.addCallback(endResult, new FutureCallback<Boolean>() {
-                @Override
-                public void onSuccess(@Nullable final Boolean result) {
-                    if (LOG.isDebugEnabled()) {
-                        final long stampFinished = System.nanoTime();
-                        LOG.debug("syncup finished {} took:{} rpc:{} wait:{} guard:{} permits thread:{}", nodeId.getValue(),
-                                formatNanos(stampFinished - stampBeforeGuard),
-                                formatNanos(stampFinished - stampAfterGuard),
-                                formatNanos(stampAfterGuard - stampBeforeGuard),
-                                guard.availablePermits(), threadName());
-                    }
-
-                    releaseGuardForNodeId(guard);
-                }
+                    delegate.syncup(flowcapableNodePath, syncupEntry);
 
-                @Override
-                public void onFailure(final Throwable t) {
-                    if (LOG.isDebugEnabled()) {
-                        final long stampFinished = System.nanoTime();
-                        LOG.warn("syncup failed {} took:{} rpc:{} wait:{} guard:{} permits thread:{}", nodeId.getValue(),
-                                formatNanos(stampFinished - stampBeforeGuard),
-                                formatNanos(stampFinished - stampAfterGuard),
-                                formatNanos(stampAfterGuard - stampBeforeGuard),
-                                guard.availablePermits(), threadName());
-                    }
-
-                    releaseGuardForNodeId(guard);
-                }
-            });
+            Futures.addCallback(endResult, createSyncupCallback(guard, stampBeforeGuard, stampAfterGuard, nodeId));
             return endResult;
         } catch (InterruptedException e) {
             releaseGuardForNodeId(guard);
@@ -100,7 +71,32 @@ public class SyncReactorGuardDecorator implements SyncReactor {
         }
     }
 
-    private String formatNanos(long nanos) {
+    private static FutureCallback<Boolean> createSyncupCallback(final Semaphore guard,
+                                                                final long stampBeforeGuard,
+                                                                final long stampAfterGuard,
+                                                                final NodeId nodeId) {
+        return new FutureCallback<Boolean>() {
+            @Override
+            public void onSuccess(@Nullable final Boolean result) {
+                if (LOG.isDebugEnabled()) {
+                    final long stampFinished = System.nanoTime();
+                    LOG.debug("syncup finished {} took:{} rpc:{} wait:{} guard:{} permits thread:{}", nodeId.getValue(),
+                            formatNanos(stampFinished - stampBeforeGuard), formatNanos(stampFinished - stampAfterGuard),
+                            formatNanos(stampAfterGuard - stampBeforeGuard), guard.availablePermits(), threadName());
+                }
+                releaseGuardForNodeId(guard);
+            }
+            @Override
+            public void onFailure(final Throwable t) {
+                final long stampFinished = System.nanoTime();
+                LOG.error("syncup failed {} took:{} rpc:{} wait:{} guard:{} permits thread:{}", nodeId.getValue(),
+                        formatNanos(stampFinished - stampBeforeGuard), formatNanos(stampFinished - stampAfterGuard),
+                        formatNanos(stampAfterGuard - stampBeforeGuard), guard.availablePermits(), threadName());
+                releaseGuardForNodeId(guard);
+            }};
+    }
+
+    private static String formatNanos(long nanos) {
         return "'" + TimeUnit.NANOSECONDS.toMillis(nanos) + " ms'";
     }
 
@@ -127,7 +123,7 @@ public class SyncReactorGuardDecorator implements SyncReactor {
      * Unlock and release guard.
      * @param guard semaphore guard which should be unlocked
      */
-    private void releaseGuardForNodeId(final Semaphore guard) {
+    private static void releaseGuardForNodeId(final Semaphore guard) {
         if (guard != null) {
             guard.release();
             LOG.trace("syncup release guard:{} thread:{}", guard, threadName());