BUG-8156 : fixed start of session manager
[bgpcep.git] / pcep / topology-provider / src / main / java / org / opendaylight / bgpcep / pcep / topology / provider / ServerSessionManager.java
index 7c0145bf8223f336fa4eb7a1d7331f9821abddc0..4cb9c6e27f946ce483cb999ba44f400d6255f2fa 100755 (executable)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.bgpcep.pcep.topology.provider;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
@@ -68,10 +69,12 @@ final class ServerSessionManager implements PCEPSessionListenerFactory, Topology
     private final InstanceIdentifier<Topology> topology;
     private final DataBroker broker;
     private final PCEPStatefulPeerProposal peerProposal;
-    private final AtomicBoolean isClosed = new AtomicBoolean(false);
     private final short rpcTimeout;
     private final AtomicReference<PCEPTopologyProviderRuntimeRegistration> runtimeRootRegistration = new AtomicReference<>();
 
+    @VisibleForTesting
+    public final AtomicBoolean isClosed = new AtomicBoolean(false);
+
     public ServerSessionManager(final DataBroker broker, final InstanceIdentifier<Topology> topology,
         final TopologySessionListenerFactory listenerFactory, final short rpcTimeout) {
         this.broker = Preconditions.checkNotNull(broker);
@@ -100,11 +103,13 @@ final class ServerSessionManager implements PCEPSessionListenerFactory, Topology
             @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);
             }
         }, MoreExecutors.directExecutor());
         return future;
@@ -115,6 +120,10 @@ final class ServerSessionManager implements PCEPSessionListenerFactory, Topology
     }
 
     synchronized void releaseNodeState(final TopologyNodeState nodeState, final PCEPSession session, final boolean persistNode) {
+        if (this.isClosed.get()) {
+            LOG.error("Session Manager has already been closed.");
+            return;
+        }
         this.nodes.remove(createNodeId(session.getRemoteAddress()));
         if (nodeState != null) {
             LOG.debug("Node {} unbound", nodeState.getNodeId());