Adopt odlparent-10.0.0/yangtools-8.0.0-SNAPSHOT
[mdsal.git] / dom / mdsal-dom-spi / src / main / java / org / opendaylight / mdsal / dom / spi / store / SnapshotBackedReadWriteTransaction.java
index fe95c8e5365998a85e9559e061b507159e0d99de..3de4dc2c5e7cce740e1b904081e913eefee41e9e 100644 (file)
@@ -7,23 +7,23 @@
  */
 package org.opendaylight.mdsal.dom.spi.store;
 
-import static com.google.common.base.Preconditions.checkNotNull;
+import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.Beta;
-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.FluentFuture;
+import com.google.common.util.concurrent.MoreExecutors;
+import java.util.Optional;
 import org.opendaylight.mdsal.common.api.ReadFailedException;
-import org.opendaylight.mdsal.dom.spi.store.SnapshotBackedWriteTransaction.TransactionReadyPrototype;
+import org.opendaylight.yangtools.util.concurrent.FluentFutures;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
+import org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Implementation of Read-Write transaction which is backed by {@link DataTreeSnapshot}
- * and executed according to {@link TransactionReadyPrototype}.
+ * Implementation of Read-Write transaction which is backed by {@link DataTreeSnapshot} and executed according
+ * to {@link SnapshotBackedWriteTransaction.TransactionReadyPrototype}.
  *
  * @param <T> identifier type
  */
@@ -39,33 +39,29 @@ public final class SnapshotBackedReadWriteTransaction<T> extends
 
     @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
-    public CheckedFuture<Optional<NormalizedNode<?,?>>, ReadFailedException> read(final YangInstanceIdentifier path) {
+    public FluentFuture<Optional<NormalizedNode>> read(final YangInstanceIdentifier path) {
         LOG.debug("Tx: {} Read: {}", getIdentifier(), path);
-        checkNotNull(path, "Path must not be null.");
+        requireNonNull(path, "Path must not be null.");
 
-        final Optional<NormalizedNode<?, ?>> result;
+        final Optional<NormalizedNode> result;
 
         try {
             result = readSnapshotNode(path);
         } catch (Exception e) {
             LOG.error("Tx: {} Failed Read of {}", getIdentifier(), path, e);
-            return Futures.immediateFailedCheckedFuture(new ReadFailedException("Read failed", e));
+            return FluentFutures.immediateFailedFluentFuture(new ReadFailedException("Read failed", e));
         }
 
         if (result == null) {
-            return Futures.immediateFailedCheckedFuture(new ReadFailedException("Transaction is closed"));
-        } else {
-            return Futures.immediateCheckedFuture(result);
+            return FluentFutures.immediateFailedFluentFuture(new ReadFailedException("Transaction is closed"));
         }
+
+        return FluentFutures.immediateFluentFuture(result);
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
-    public CheckedFuture<Boolean, ReadFailedException> exists(final YangInstanceIdentifier path) {
-        try {
-            return Futures.immediateCheckedFuture(read(path).checkedGet().isPresent());
-        } catch (ReadFailedException e) {
-            return Futures.immediateFailedCheckedFuture(e);
-        }
+    public FluentFuture<Boolean> exists(final YangInstanceIdentifier path) {
+        return read(path).transform(Optional::isPresent, MoreExecutors.directExecutor());
     }
 }