Remove blocking get in read transaction 39/51939/1
authorAndrej Mak <andrej.mak@pantheon.tech>
Mon, 13 Feb 2017 09:30:40 +0000 (10:30 +0100)
committerAndrej Mak <andrej.mak@pantheon.tech>
Thu, 16 Feb 2017 09:06:12 +0000 (10:06 +0100)
Change-Id: I6829aea0e2cd1f98c3d845db05b4d52dfad8f75e
Signed-off-by: Andrej Mak <andrej.mak@pantheon.tech>
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/ReadOnlyTx.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/ReadWriteTx.java

index 8087fde8b709a95dc9c4d8e1f22c24a98033fc35..7d4478a92cf013d3ff32c9ac27d194ec7cbe59c8 100644 (file)
@@ -13,7 +13,6 @@ import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
-import java.util.concurrent.ExecutionException;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
@@ -95,12 +94,9 @@ public final class ReadOnlyTx implements DOMDataReadOnlyTransaction {
     @Override
     public CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
         final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> data = read(store, path);
-
-        try {
-            return Futures.immediateCheckedFuture(data.get().isPresent());
-        } catch (InterruptedException | ExecutionException e) {
-            return Futures.immediateFailedCheckedFuture(new ReadFailedException("Exists failed",e));
-        }
+        final ListenableFuture<Boolean> result =
+                Futures.transform(data, (Optional<NormalizedNode<?, ?>> a) -> a != null && a.isPresent());
+        return MappingCheckedFuture.create(result, ReadFailedException.MAPPER);
     }
 
     @Override
index de2f92236ed730ed5ae87a983083ab583ba5ba41..b063cba63ac8603861b9a387ff79dd5a42b43bf6 100644 (file)
@@ -10,9 +10,7 @@ package org.opendaylight.netconf.sal.connect.netconf.sal.tx;
 
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.CheckedFuture;
-import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
-import java.util.concurrent.ExecutionException;
 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
@@ -73,14 +71,7 @@ public class ReadWriteTx implements DOMDataReadWriteTransaction {
     @Override public CheckedFuture<Boolean, ReadFailedException> exists(
         final LogicalDatastoreType store,
         final YangInstanceIdentifier path) {
-        final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException>
-            data = read(store, path);
-
-        try {
-            return Futures.immediateCheckedFuture(data.get().isPresent());
-        } catch (InterruptedException | ExecutionException e) {
-            return Futures.immediateFailedCheckedFuture(new ReadFailedException("Exists failed",e));
-        }
+        return delegateReadTx.exists(store, path);
     }
 
     @Override