BUG-8275: Close ReadOnly transaction
[bgpcep.git] / pcep / topology-provider / src / main / java / org / opendaylight / bgpcep / pcep / topology / provider / PCEPStatefulPeerProposal.java
index 75daaa46e8844912b521a7a101be272a8442a3ff..dbcf4e588cf7710ceeb4956f48e5fff8aebea6a2 100644 (file)
@@ -14,6 +14,7 @@ import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.PathComputationClient1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1;
@@ -51,25 +52,28 @@ public final class PCEPStatefulPeerProposal {
 
     void setPeerProposal(final NodeId nodeId, final TlvsBuilder openTlvsBuilder) {
         if (isSynOptimizationEnabled(openTlvsBuilder)) {
-            final ListenableFuture<Optional<LspDbVersion>> future = this.dataBroker.newReadOnlyTransaction().read(
+            try (final ReadOnlyTransaction rTx = this.dataBroker.newReadOnlyTransaction()) {
+                final ListenableFuture<Optional<LspDbVersion>> future = rTx.read(
                     LogicalDatastoreType.OPERATIONAL,
                     this.topologyId.child(Node.class, new NodeKey(nodeId)).augmentation(Node1.class)
-                            .child(PathComputationClient.class).augmentation(PathComputationClient1.class)
-                            .child(LspDbVersion.class));
-            Futures.addCallback(future, new FutureCallback<Optional<LspDbVersion>>() {
-                @Override
-                public void onSuccess(final Optional<LspDbVersion> result) {
-                    if (result.isPresent()) {
-                        openTlvsBuilder.addAugmentation(Tlvs3.class, new Tlvs3Builder().setLspDbVersion(result.get())
-                                .build());
+                    .child(PathComputationClient.class).augmentation(PathComputationClient1.class)
+                    .child(LspDbVersion.class));
+                Futures.addCallback(future, new FutureCallback<Optional<LspDbVersion>>() {
+                    @Override
+                    public void onSuccess(final Optional<LspDbVersion> result) {
+                        if (result.isPresent()) {
+                            openTlvsBuilder.addAugmentation(Tlvs3.class,
+                                new Tlvs3Builder().setLspDbVersion(result.get()).build());
+                        }
                     }
-                }
 
-                @Override
-                public void onFailure(final Throwable t) {
-                    LOG.warn("Failed to read toplogy {}.", InstanceIdentifier.keyOf(PCEPStatefulPeerProposal.this.topologyId), t);
-                }
-            });
+                    @Override
+                    public void onFailure(final Throwable t) {
+                        LOG.warn("Failed to read toplogy {}.", InstanceIdentifier.keyOf(
+                            PCEPStatefulPeerProposal.this.topologyId), t);
+                    }
+                });
+            }
         }
     }