Reduce use of deprecated methods
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / md / sal / dom / broker / impl / legacy / sharded / adapter / ShardedDOMDataBrokerDelegatingReadWriteTransaction.java
index bd8643b..5ee9c43 100644 (file)
@@ -11,43 +11,43 @@ package org.opendaylight.controller.md.sal.dom.broker.impl.legacy.sharded.adapte
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkState;
 
-import com.google.common.base.Function;
 import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
-import com.google.common.util.concurrent.AsyncFunction;
 import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FluentFuture;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
 import com.google.common.util.concurrent.SettableFuture;
 import java.util.Map;
 import java.util.Queue;
-import javax.annotation.Nullable;
+import javax.annotation.Nonnull;
 import javax.annotation.concurrent.NotThreadSafe;
-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;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.opendaylight.mdsal.common.api.CommitInfo;
 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.DataTree;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
 import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 /**
- * Read/write transaction that delegates write and initial read to {@link org.opendaylight.mdsal.dom.broker.ShardedDOMWriteTransactionAdapter}
+ * Read/write transaction that delegates write and initial read to
+ * {@link org.opendaylight.mdsal.dom.broker.ShardedDOMWriteTransactionAdapter}
  * and {@link org.opendaylight.mdsal.dom.broker.ShardedDOMReadTransactionAdapter}
- * respectively. These two in turn rely on shard aware implementation of {@link org.opendaylight.mdsal.dom.api.DOMDataTreeService}.
+ * respectively. These two in turn rely on shard aware implementation of
+ * {@link org.opendaylight.mdsal.dom.api.DOMDataTreeService}.
+ *
  * <p>
  * Since reading data distributed on different subshards is not guaranteed to
  * return all relevant data, best effort is to try to operate only on single
@@ -58,9 +58,6 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 // FIXME explicitly enforce just one subtree requirement
 @NotThreadSafe
 class ShardedDOMDataBrokerDelegatingReadWriteTransaction implements DOMDataReadWriteTransaction {
-    private static final ListenableFuture<RpcResult<TransactionStatus>> SUCCESS_FUTURE =
-            Futures.immediateFuture(RpcResultBuilder.success(TransactionStatus.COMMITED).build());
-
     private final DOMDataReadOnlyTransaction readTxDelegate;
     private final DOMDataWriteTransaction writeTxDelegate;
     private final Object txIdentifier;
@@ -69,7 +66,7 @@ class ShardedDOMDataBrokerDelegatingReadWriteTransaction implements DOMDataReadW
     private final Map<LogicalDatastoreType, ListenableFuture<Optional<NormalizedNode<?, ?>>>> initialReadMap;
     private YangInstanceIdentifier root = null;
 
-    public ShardedDOMDataBrokerDelegatingReadWriteTransaction(final Object readWriteTxId, final SchemaContext ctx,
+    ShardedDOMDataBrokerDelegatingReadWriteTransaction(final Object readWriteTxId, final SchemaContext ctx,
                                                               final DOMDataReadOnlyTransaction readTxDelegate,
                                                               final DOMDataWriteTransaction writeTxDelegate) {
         this.readTxDelegate = checkNotNull(readTxDelegate);
@@ -77,12 +74,12 @@ class ShardedDOMDataBrokerDelegatingReadWriteTransaction implements DOMDataReadW
         this.txIdentifier = checkNotNull(readWriteTxId);
         this.initialReadMap = Maps.newEnumMap(LogicalDatastoreType.class);
 
-        final InMemoryDataTreeFactory treeFactory = InMemoryDataTreeFactory.getInstance();
+        final InMemoryDataTreeFactory treeFactory = new InMemoryDataTreeFactory();
         final ImmutableMap.Builder<LogicalDatastoreType, DataTreeSnapshot> snapshotMapBuilder = ImmutableMap.builder();
-        final ImmutableMap.Builder<LogicalDatastoreType, Queue<Modification>> modificationHistoryMapBuilder =
-                ImmutableMap.builder();
+        final ImmutableMap.Builder<LogicalDatastoreType, Queue<Modification>> modificationHistoryMapBuilder
+                ImmutableMap.builder();
         for (final LogicalDatastoreType store : LogicalDatastoreType.values()) {
-            final DataTree tree = treeFactory.create(treeTypeForStore(store));
+            final DataTree tree = treeFactory.create(treeConfigForStore(store));
             tree.setSchemaContext(ctx);
             snapshotMapBuilder.put(store, tree.takeSnapshot());
 
@@ -110,37 +107,33 @@ class ShardedDOMDataBrokerDelegatingReadWriteTransaction implements DOMDataReadW
     }
 
     @Override
-    public CheckedFuture<Void, TransactionCommitFailedException> submit() {
-        return writeTxDelegate.submit();
-    }
-
-    @Override
-    public ListenableFuture<RpcResult<TransactionStatus>> commit() {
-        return Futures.transform(submit(), (AsyncFunction<Void, RpcResult<TransactionStatus>>) input -> SUCCESS_FUTURE);
+    public FluentFuture<? extends CommitInfo> commit() {
+        return writeTxDelegate.commit();
     }
 
     @Override
     public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(final LogicalDatastoreType store,
                                                                                    final YangInstanceIdentifier path) {
-        checkState(root != null, "A modify operation (put, merge or delete) must be performed prior to a read operation");
+        checkState(root != null,
+                   "A modify operation (put, merge or delete) must be performed prior to a read operation");
         final SettableFuture<Optional<NormalizedNode<?, ?>>> readResult = SettableFuture.create();
         final Queue<Modification> currentHistory = Lists.newLinkedList(modificationHistoryMap.get(store));
         Futures.addCallback(initialReadMap.get(store), new FutureCallback<Optional<NormalizedNode<?, ?>>>() {
             @Override
-            public void onSuccess(@Nullable final Optional<NormalizedNode<?, ?>> result) {
+            public void onSuccess(@Nonnull final Optional<NormalizedNode<?, ?>> result) {
                 final DataTreeModification mod = snapshotMap.get(store).newModification();
                 if (result.isPresent()) {
                     mod.write(path, result.get());
                 }
                 applyModificationHistoryToSnapshot(mod, currentHistory);
-                readResult.set(mod.readNode(path));
+                readResult.set(Optional.fromJavaUtil(mod.readNode(path)));
             }
 
             @Override
-            public void onFailure(final Throwable t) {
-                readResult.setException(t);
+            public void onFailure(final Throwable throwable) {
+                readResult.setException(throwable);
             }
-        });
+        }, MoreExecutors.directExecutor());
 
         return Futures.makeChecked(readResult, ReadFailedException.MAPPER);
     }
@@ -148,10 +141,10 @@ class ShardedDOMDataBrokerDelegatingReadWriteTransaction implements DOMDataReadW
     @Override
     public CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store,
                                                               final YangInstanceIdentifier path) {
-        checkState(root != null, "A modify operation (put, merge or delete) must be performed prior to an exists operation");
-        return Futures.makeChecked(Futures.transform(read(store, path),
-                (Function<Optional<NormalizedNode<?, ?>>, Boolean>) Optional::isPresent),
-                ReadFailedException.MAPPER);
+        checkState(root != null,
+                   "A modify operation (put, merge or delete) must be performed prior to an exists operation");
+        return Futures.makeChecked(Futures.transform(read(store, path), Optional::isPresent,
+            MoreExecutors.directExecutor()), ReadFailedException.MAPPER);
     }
 
     @Override
@@ -184,17 +177,17 @@ class ShardedDOMDataBrokerDelegatingReadWriteTransaction implements DOMDataReadW
     private void initialRead(final YangInstanceIdentifier path) {
         root = path;
 
-        final InMemoryDataTreeFactory treeFactory = InMemoryDataTreeFactory.getInstance();
         for (final LogicalDatastoreType store : LogicalDatastoreType.values()) {
             initialReadMap.put(store, readTxDelegate.read(store, path));
         }
     }
 
-    private TreeType treeTypeForStore(final LogicalDatastoreType store) {
-        return store == LogicalDatastoreType.CONFIGURATION ? TreeType.CONFIGURATION : TreeType.OPERATIONAL;
+    private static DataTreeConfiguration treeConfigForStore(final LogicalDatastoreType store) {
+        return store == LogicalDatastoreType.CONFIGURATION ? DataTreeConfiguration.DEFAULT_CONFIGURATION
+                : DataTreeConfiguration.DEFAULT_OPERATIONAL;
     }
 
-    private void applyModificationHistoryToSnapshot(final DataTreeModification dataTreeModification,
+    private static void applyModificationHistoryToSnapshot(final DataTreeModification dataTreeModification,
                                                     final Queue<Modification> modificationHistory) {
         while (!modificationHistory.isEmpty()) {
             final Modification modification = modificationHistory.poll();

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.