Merge "Close read-only transactions"
[netconf.git] / netconf / messagebus-netconf / src / main / java / org / opendaylight / netconf / messagebus / eventsources / netconf / NetconfEventSourceMount.java
index f49ddd9b74d57c26f98dfa4cd35e6441f5935982..c67995b4126d753fb4187fca6b188beaa8ba50ae 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.netconf.messagebus.eventsources.netconf;
 
 import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.FluentFuture;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.time.Instant;
 import java.time.ZoneId;
@@ -137,10 +136,10 @@ class NetconfEventSourceMount {
      * @throws InterruptedException if data read fails
      */
     List<Stream> getAvailableStreams() throws InterruptedException, ExecutionException {
-        DOMDataTreeReadTransaction tx = dataBroker.newReadOnlyTransaction();
-        FluentFuture<Optional<NormalizedNode<?, ?>>> checkFeature = tx.read(LogicalDatastoreType.OPERATIONAL,
-            STREAMS_PATH);
-        Optional<NormalizedNode<?, ?>> streams = checkFeature.get();
+        final Optional<NormalizedNode<?, ?>> streams;
+        try (DOMDataTreeReadTransaction tx = dataBroker.newReadOnlyTransaction()) {
+            streams = tx.read(LogicalDatastoreType.OPERATIONAL, STREAMS_PATH).get();
+        }
         if (streams.isPresent()) {
             Streams streams1 = (Streams) CODEC_REGISTRY.fromNormalizedNode(STREAMS_PATH, streams.get()).getValue();
             return streams1.getStream();