Use Empty instead of Void in cohorts
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / LocalThreePhaseCommitCohort.java
index 1f8800f5d34fea884d483ff9a1d39bf082799b06..091bfa01e4db0346b85fbb432ddace51e7e8857c 100644 (file)
@@ -7,20 +7,23 @@
  */
 package org.opendaylight.controller.cluster.datastore;
 
+import static java.util.Objects.requireNonNull;
+
 import akka.actor.ActorSelection;
 import akka.dispatch.Futures;
 import akka.dispatch.OnComplete;
-import com.google.common.base.Preconditions;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.Optional;
 import java.util.SortedSet;
 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
 import org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply;
 import org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction;
-import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
+import org.opendaylight.controller.cluster.datastore.utils.ActorUtils;
+import org.opendaylight.mdsal.common.api.CommitInfo;
 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
 import org.opendaylight.mdsal.dom.spi.store.SnapshotBackedWriteTransaction;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
+import org.opendaylight.yangtools.yang.common.Empty;
+import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import scala.concurrent.Future;
@@ -37,28 +40,28 @@ class LocalThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCohort {
 
     private final SnapshotBackedWriteTransaction<TransactionIdentifier> transaction;
     private final DataTreeModification modification;
-    private final ActorContext actorContext;
+    private final ActorUtils actorUtils;
     private final ActorSelection leader;
     private final Exception operationError;
 
-    protected LocalThreePhaseCommitCohort(final ActorContext actorContext, final ActorSelection leader,
+    protected LocalThreePhaseCommitCohort(final ActorUtils actorUtils, final ActorSelection leader,
             final SnapshotBackedWriteTransaction<TransactionIdentifier> transaction,
             final DataTreeModification modification,
             final Exception operationError) {
-        this.actorContext = Preconditions.checkNotNull(actorContext);
-        this.leader = Preconditions.checkNotNull(leader);
-        this.transaction = Preconditions.checkNotNull(transaction);
-        this.modification = Preconditions.checkNotNull(modification);
+        this.actorUtils = requireNonNull(actorUtils);
+        this.leader = requireNonNull(leader);
+        this.transaction = requireNonNull(transaction);
+        this.modification = requireNonNull(modification);
         this.operationError = operationError;
     }
 
-    protected LocalThreePhaseCommitCohort(final ActorContext actorContext, final ActorSelection leader,
+    protected LocalThreePhaseCommitCohort(final ActorUtils actorUtils, final ActorSelection leader,
             final SnapshotBackedWriteTransaction<TransactionIdentifier> transaction, final Exception operationError) {
-        this.actorContext = Preconditions.checkNotNull(actorContext);
-        this.leader = Preconditions.checkNotNull(leader);
-        this.transaction = Preconditions.checkNotNull(transaction);
-        this.operationError = Preconditions.checkNotNull(operationError);
-        this.modification = null;
+        this.actorUtils = requireNonNull(actorUtils);
+        this.leader = requireNonNull(leader);
+        this.transaction = requireNonNull(transaction);
+        this.operationError = requireNonNull(operationError);
+        modification = null;
     }
 
     private Future<Object> initiateCommit(final boolean immediate,
@@ -69,46 +72,47 @@ class LocalThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCohort {
 
         final ReadyLocalTransaction message = new ReadyLocalTransaction(transaction.getIdentifier(),
                 modification, immediate, participatingShardNames);
-        return actorContext.executeOperationAsync(leader, message, actorContext.getTransactionCommitOperationTimeout());
+        return actorUtils.executeOperationAsync(leader, message, actorUtils.getTransactionCommitOperationTimeout());
     }
 
-    Future<ActorSelection> initiateCoordinatedCommit(Optional<SortedSet<String>> participatingShardNames) {
+    Future<ActorSelection> initiateCoordinatedCommit(final Optional<SortedSet<String>> participatingShardNames) {
         final Future<Object> messageFuture = initiateCommit(false, participatingShardNames);
-        final Future<ActorSelection> ret = TransactionReadyReplyMapper.transform(messageFuture, actorContext,
+        final Future<ActorSelection> ret = TransactionReadyReplyMapper.transform(messageFuture, actorUtils,
                 transaction.getIdentifier());
         ret.onComplete(new OnComplete<ActorSelection>() {
             @Override
             public void onComplete(final Throwable failure, final ActorSelection success) {
                 if (failure != null) {
-                    LOG.info("Failed to prepare transaction {} on backend", transaction.getIdentifier(), failure);
+                    LOG.warn("Failed to prepare transaction {} on backend", transaction.getIdentifier(), failure);
                     transactionAborted(transaction);
                     return;
                 }
 
                 LOG.debug("Transaction {} resolved to actor {}", transaction.getIdentifier(), success);
             }
-        }, actorContext.getClientDispatcher());
+        }, actorUtils.getClientDispatcher());
 
         return ret;
     }
 
     Future<Object> initiateDirectCommit() {
         final Future<Object> messageFuture = initiateCommit(true, Optional.empty());
-        messageFuture.onComplete(new OnComplete<Object>() {
+        messageFuture.onComplete(new OnComplete<>() {
             @Override
             public void onComplete(final Throwable failure, final Object message) {
                 if (failure != null) {
-                    LOG.error("Failed to prepare transaction {} on backend", transaction.getIdentifier(), failure);
+                    LOG.warn("Failed to prepare transaction {} on backend", transaction.getIdentifier(), failure);
                     transactionAborted(transaction);
                 } else if (CommitTransactionReply.isSerializedType(message)) {
                     LOG.debug("Transaction {} committed successfully", transaction.getIdentifier());
                     transactionCommitted(transaction);
                 } else {
-                    LOG.error("Transaction {} resulted in unhandled message type {}, aborting", message.getClass());
+                    LOG.error("Transaction {} resulted in unhandled message type {}, aborting",
+                        transaction.getIdentifier(), message.getClass());
                     transactionAborted(transaction);
                 }
             }
-        }, actorContext.getClientDispatcher());
+        }, actorUtils.getClientDispatcher());
 
         return messageFuture;
     }
@@ -120,26 +124,26 @@ class LocalThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCohort {
     }
 
     @Override
-    public final ListenableFuture<Void> preCommit() {
+    public final ListenableFuture<Empty> preCommit() {
         // Intended no-op
         throw new UnsupportedOperationException();
     }
 
     @Override
-    public final ListenableFuture<Void> abort() {
+    public final ListenableFuture<Empty> abort() {
         // Intended no-op
         throw new UnsupportedOperationException();
     }
 
     @Override
-    public final ListenableFuture<Void> commit() {
+    public final ListenableFuture<CommitInfo> commit() {
         // Intended no-op
         throw new UnsupportedOperationException();
     }
 
-    protected void transactionAborted(SnapshotBackedWriteTransaction<TransactionIdentifier> aborted) {
+    protected void transactionAborted(final SnapshotBackedWriteTransaction<TransactionIdentifier> aborted) {
     }
 
-    protected void transactionCommitted(SnapshotBackedWriteTransaction<TransactionIdentifier> comitted) {
+    protected void transactionCommitted(final SnapshotBackedWriteTransaction<TransactionIdentifier> comitted) {
     }
 }