Create SemaphoreKeeper inside decorators
[openflowplugin.git] / applications / forwardingrules-sync / src / main / java / org / opendaylight / openflowplugin / applications / frsync / impl / SyncReactorGuardDecorator.java
index a6d1bef72da98b563e777875bb4159e66d6d43a7..f4ee57fdde6d860404148191ae6b66ccd6f4bc48 100644 (file)
@@ -18,6 +18,7 @@ import javax.annotation.Nullable;
 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.SemaphoreKeeperGuavaImpl;
 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;
@@ -32,12 +33,11 @@ public class SyncReactorGuardDecorator implements SyncReactor {
 
     private static final Logger LOG = LoggerFactory.getLogger(SyncReactorGuardDecorator.class);
     private final SyncReactor delegate;
-    private final SemaphoreKeeper<InstanceIdentifier<FlowCapableNode>> semaphoreKeeper;
+    private final SemaphoreKeeper<InstanceIdentifier<FlowCapableNode>> semaphoreKeeper =
+            new SemaphoreKeeperGuavaImpl<>(1, true);
 
-    public SyncReactorGuardDecorator(final SyncReactor delegate,
-                                     final SemaphoreKeeper<InstanceIdentifier<FlowCapableNode>> semaphoreKeeper) {
+    public SyncReactorGuardDecorator(final SyncReactor delegate) {
         this.delegate = delegate;
-        this.semaphoreKeeper = semaphoreKeeper;
     }
 
     public ListenableFuture<Boolean> syncup(final InstanceIdentifier<FlowCapableNode> flowcapableNodePath,
@@ -59,9 +59,9 @@ public class SyncReactorGuardDecorator implements SyncReactor {
     }
 
     private FutureCallback<Boolean> createSyncupCallback(final Semaphore guard,
-                                                                final long stampBeforeGuard,
-                                                                final long stampAfterGuard,
-                                                                final NodeId nodeId) {
+                                                         final long stampBeforeGuard,
+                                                         final long stampAfterGuard,
+                                                         final NodeId nodeId) {
         return new FutureCallback<Boolean>() {
             @Override
             public void onSuccess(@Nullable final Boolean result) {