FR-sync cleaning
[openflowplugin.git] / applications / forwardingrules-sync / src / main / java / org / opendaylight / openflowplugin / applications / frsync / impl / SyncReactorGuardDecorator.java
index 90ead252bc52be1c458fb118b7e2b9da0199206e..f879aea76f3a3ddee05b77e71ffe9fb7b159edaa 100644 (file)
@@ -45,7 +45,7 @@ public class SyncReactorGuardDecorator implements SyncReactor {
                                             final FlowCapableNode configTree, final FlowCapableNode operationalTree,\r
                                             final LogicalDatastoreType dsType) throws InterruptedException {\r
         final NodeId nodeId = PathUtil.digNodeId(flowcapableNodePath);\r
-        LOG.trace("syncup {}", nodeId.getValue());\r
+        LOG.trace("syncup guard {}", nodeId.getValue());\r
 \r
         final long stampBeforeGuard = System.nanoTime();\r
         final Semaphore guard = summonGuardAndAcquire(flowcapableNodePath);//TODO handle InteruptedException\r
@@ -66,48 +66,47 @@ public class SyncReactorGuardDecorator implements SyncReactor {
                 public void onSuccess(@Nullable final Boolean result) {\r
                     if (LOG.isDebugEnabled()) {\r
                         final long stampFinished = System.nanoTime();\r
-                        LOG.debug("syncup finished {} took:{} rpc:{} wait:{} guard:{}, thread:{}", nodeId.getValue(),\r
+                        LOG.debug("syncup finished {} took:{} rpc:{} wait:{} guard:{} permits thread:{}", nodeId.getValue(),\r
                                 formatNanos(stampFinished - stampBeforeGuard),\r
                                 formatNanos(stampFinished - stampAfterGuard),\r
                                 formatNanos(stampAfterGuard - stampBeforeGuard),\r
-                                guard, threadName());\r
+                                guard.availablePermits(), threadName());\r
                     }\r
 \r
-                    releaseGuardForNodeId(nodeId, guard);\r
+                    releaseGuardForNodeId(guard);\r
                 }\r
 \r
                 @Override\r
                 public void onFailure(final Throwable t) {\r
                     if (LOG.isDebugEnabled()) {\r
                         final long stampFinished = System.nanoTime();\r
-                        LOG.warn("syncup failed {} took:{} rpc:{} wait:{} guard:{} thread:{}", nodeId.getValue(),\r
+                        LOG.warn("syncup failed {} took:{} rpc:{} wait:{} guard:{} permits thread:{}", nodeId.getValue(),\r
                                 formatNanos(stampFinished - stampBeforeGuard),\r
                                 formatNanos(stampFinished - stampAfterGuard),\r
                                 formatNanos(stampAfterGuard - stampBeforeGuard),\r
-                                guard, threadName());\r
+                                guard.availablePermits(), threadName());\r
                     }\r
 \r
-                    releaseGuardForNodeId(nodeId, guard);\r
+                    releaseGuardForNodeId(guard);\r
                 }\r
             });\r
             return endResult;\r
-        } catch(InterruptedException e) {\r
-            releaseGuardForNodeId(nodeId, guard);\r
+        } catch (InterruptedException e) {\r
+            releaseGuardForNodeId(guard);\r
             throw e;\r
         }\r
     }\r
 \r
-    protected String formatNanos(long nanos) {\r
+    private String formatNanos(long nanos) {\r
         return "'" + TimeUnit.NANOSECONDS.toMillis(nanos) + " ms'";\r
     }\r
 \r
     /**\r
-     * get guard\r
-     *\r
+     * Get guard and lock for node.\r
      * @param flowcapableNodePath II of node for which guard should be acquired\r
      * @return semaphore guard\r
      */\r
-    protected Semaphore summonGuardAndAcquire(final InstanceIdentifier<FlowCapableNode> flowcapableNodePath)\r
+    private Semaphore summonGuardAndAcquire(final InstanceIdentifier<FlowCapableNode> flowcapableNodePath)\r
             throws InterruptedException {\r
         final Semaphore guard = Preconditions.checkNotNull(semaphoreKeeper.summonGuard(flowcapableNodePath),\r
                 "no guard for " + flowcapableNodePath);\r
@@ -126,19 +125,17 @@ public class SyncReactorGuardDecorator implements SyncReactor {
     }\r
 \r
     /**\r
-     * unlock per node\r
-     *\r
-     * @param nodeId NodeId of node which should be unlocked\r
-     * @param guard semaphore guard\r
+     * Unlock and release guard.\r
+     * @param guard semaphore guard which should be unlocked\r
      */\r
-    protected void releaseGuardForNodeId(final NodeId nodeId, final Semaphore guard) {\r
+    private void releaseGuardForNodeId(final Semaphore guard) {\r
         if (guard == null) {\r
             return;\r
         }\r
         guard.release();\r
     }\r
 \r
-    static String threadName() {\r
+    private static String threadName() {\r
         final Thread currentThread = Thread.currentThread();\r
         return currentThread.getName();\r
     }\r