Bump versions to 4.0.0-SNAPSHOT
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / sharding / ShardProxyTransaction.java
index 52630eb..fde000f 100644 (file)
@@ -5,11 +5,12 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.controller.cluster.sharding;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.util.concurrent.AsyncFunction;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
@@ -20,15 +21,15 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map.Entry;
+import java.util.Optional;
 import java.util.stream.Collectors;
-import javax.annotation.Nonnull;
 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor;
 import org.opendaylight.mdsal.dom.spi.shard.DOMDataTreeShardWriteTransaction;
 import org.opendaylight.mdsal.dom.spi.shard.ForeignShardModificationContext;
+import org.opendaylight.mdsal.dom.spi.shard.ForeignShardThreePhaseCommitCohort;
 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
-import org.opendaylight.mdsal.dom.store.inmemory.ForeignShardThreePhaseCommitCohort;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -37,6 +38,7 @@ import org.slf4j.LoggerFactory;
  * Proxy {@link DOMDataTreeShardWriteTransaction} that creates a proxy cursor that translates all calls into
  * {@link ClientTransaction} calls.
  */
+@Deprecated(forRemoval = true)
 class ShardProxyTransaction implements DOMDataTreeShardWriteTransaction {
 
     private static final Logger LOG = LoggerFactory.getLogger(ShardProxyTransaction.class);
@@ -52,9 +54,9 @@ class ShardProxyTransaction implements DOMDataTreeShardWriteTransaction {
     ShardProxyTransaction(final DOMDataTreeIdentifier shardRoot,
                           final Collection<DOMDataTreeIdentifier> prefixes,
                           final DistributedShardModification modification) {
-        this.shardRoot = Preconditions.checkNotNull(shardRoot);
-        this.prefixes = Preconditions.checkNotNull(prefixes);
-        this.modification = Preconditions.checkNotNull(modification);
+        this.shardRoot = requireNonNull(shardRoot);
+        this.prefixes = requireNonNull(prefixes);
+        this.modification = requireNonNull(modification);
     }
 
     private DOMDataTreeWriteCursor getCursor() {
@@ -64,9 +66,8 @@ class ShardProxyTransaction implements DOMDataTreeShardWriteTransaction {
         return cursor;
     }
 
-    @Nonnull
     @Override
-    public DOMDataTreeWriteCursor createCursor(@Nonnull final DOMDataTreeIdentifier prefix) {
+    public DOMDataTreeWriteCursor createCursor(final DOMDataTreeIdentifier prefix) {
         checkAvailable(prefix);
         final YangInstanceIdentifier relativePath = toRelative(prefix.getRootIdentifier());
         final DOMDataTreeWriteCursor ret = getCursor();
@@ -92,7 +93,7 @@ class ShardProxyTransaction implements DOMDataTreeShardWriteTransaction {
     private YangInstanceIdentifier toRelative(final YangInstanceIdentifier path) {
         final Optional<YangInstanceIdentifier> relative =
                 path.relativeTo(modification.getPrefix().getRootIdentifier());
-        Preconditions.checkArgument(relative.isPresent());
+        checkArgument(relative.isPresent());
         return relative.get();
     }
 
@@ -100,7 +101,7 @@ class ShardProxyTransaction implements DOMDataTreeShardWriteTransaction {
     public void ready() {
         LOG.debug("Readying transaction for shard {}", shardRoot);
 
-        Preconditions.checkNotNull(modification, "Attempting to ready an empty transaction.");
+        requireNonNull(modification, "Attempting to ready an empty transaction.");
 
         cohorts.add(modification.seal());
         for (Entry<DOMDataTreeIdentifier, ForeignShardModificationContext> entry
@@ -124,7 +125,7 @@ class ShardProxyTransaction implements DOMDataTreeShardWriteTransaction {
     public ListenableFuture<Void> submit() {
         LOG.debug("Submitting transaction for shard {}", shardRoot);
 
-        Preconditions.checkState(!cohorts.isEmpty(), "Transaction not readied yet");
+        checkTransactionReadied();
 
         final AsyncFunction<Boolean, Void> validateFunction = input -> prepare();
         final AsyncFunction<Void, Void> prepareFunction = input -> commit();
@@ -136,11 +137,15 @@ class ShardProxyTransaction implements DOMDataTreeShardWriteTransaction {
         return Futures.transformAsync(prepareFuture, prepareFunction, MoreExecutors.directExecutor());
     }
 
+    private void checkTransactionReadied() {
+        checkState(!cohorts.isEmpty(), "Transaction not readied yet");
+    }
+
     @Override
     public ListenableFuture<Boolean> validate() {
         LOG.debug("Validating transaction for shard {}", shardRoot);
 
-        Preconditions.checkState(!cohorts.isEmpty(), "Transaction not readied yet");
+        checkTransactionReadied();
         final List<ListenableFuture<Boolean>> futures =
                 cohorts.stream().map(DOMStoreThreePhaseCommitCohort::canCommit).collect(Collectors.toList());
         final SettableFuture<Boolean> ret = SettableFuture.create();
@@ -164,7 +169,7 @@ class ShardProxyTransaction implements DOMDataTreeShardWriteTransaction {
     public ListenableFuture<Void> prepare() {
         LOG.debug("Preparing transaction for shard {}", shardRoot);
 
-        Preconditions.checkState(!cohorts.isEmpty(), "Transaction not readied yet");
+        checkTransactionReadied();
         final List<ListenableFuture<Void>> futures =
                 cohorts.stream().map(DOMStoreThreePhaseCommitCohort::preCommit).collect(Collectors.toList());
         final SettableFuture<Void> ret = SettableFuture.create();
@@ -188,7 +193,7 @@ class ShardProxyTransaction implements DOMDataTreeShardWriteTransaction {
     public ListenableFuture<Void> commit() {
         LOG.debug("Committing transaction for shard {}", shardRoot);
 
-        Preconditions.checkState(!cohorts.isEmpty(), "Transaction not readied yet");
+        checkTransactionReadied();
         final List<ListenableFuture<Void>> futures =
                 cohorts.stream().map(DOMStoreThreePhaseCommitCohort::commit).collect(Collectors.toList());
         final SettableFuture<Void> ret = SettableFuture.create();