BGPCEP-739: Fix "raced with transaction PingPongTransaction"
[bgpcep.git] / pcep / topology-provider / src / main / java / org / opendaylight / bgpcep / pcep / topology / provider / ServerSessionManager.java
index 8eb1fa454fd9557b180c79a37d44e8f1682e606f..13110181f09d2226701d3273008abd9afa5cfa6d 100755 (executable)
@@ -18,6 +18,7 @@ import java.net.InetSocketAddress;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
@@ -85,11 +86,9 @@ final class ServerSessionManager implements PCEPSessionListenerFactory, Topology
     }
 
     /**
-     * Create Base Topology
-     *
-     * @throws TransactionCommitFailedException exception
+     * Create Base Topology.
      */
-    synchronized CheckedFuture<Void, TransactionCommitFailedException> instantiateServiceInstance() {
+    synchronized void instantiateServiceInstance() {
         final TopologyKey key = InstanceIdentifier.keyOf(this.topology);
         final TopologyId topologyId = key.getTopologyId();
         final WriteTransaction tx = this.broker.newWriteOnlyTransaction();
@@ -98,21 +97,14 @@ final class ServerSessionManager implements PCEPSessionListenerFactory, Topology
                 .addAugmentation(TopologyTypes1.class, new TopologyTypes1Builder().setTopologyPcep(
                     new TopologyPcepBuilder().build()).build()).build())
             .setNode(new ArrayList<>()).build(), true);
-        final CheckedFuture<Void, TransactionCommitFailedException> future = tx.submit();
-        Futures.addCallback(future, new FutureCallback<Void>() {
-            @Override
-            public void onSuccess(final Void result) {
-                LOG.debug("PCEP Topology {} created successfully.", topologyId.getValue());
-                ServerSessionManager.this.isClosed.set(false);
-            }
-
-            @Override
-            public void onFailure(final Throwable t) {
-                LOG.error("Failed to create PCEP Topology {}.", topologyId.getValue(), t);
-                ServerSessionManager.this.isClosed.set(true);
-            }
-        });
-        return future;
+        try {
+            tx.submit().get();
+            LOG.info("PCEP Topology {} created successfully.", topologyId.getValue());
+            ServerSessionManager.this.isClosed.set(false);
+        } catch (final ExecutionException | InterruptedException throwable) {
+            LOG.error("Failed to create PCEP Topology {}.", topologyId.getValue(), throwable);
+            ServerSessionManager.this.isClosed.set(true);
+        }
     }
 
     private static NodeId createNodeId(final InetAddress addr) {