Refactor TransactionContext.executeModification()
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / NoOpTransactionContext.java
index fc10b9c23b215fd37012e75549a7b997bf41434f..cee9d784acc46e7170b696daaaca26bcc54e2825 100644 (file)
@@ -8,12 +8,14 @@
 package org.opendaylight.controller.cluster.datastore;
 
 import akka.actor.ActorSelection;
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
-import com.google.common.util.concurrent.Futures;
-import java.util.concurrent.Semaphore;
-import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import com.google.common.util.concurrent.SettableFuture;
+import java.util.Optional;
+import java.util.SortedSet;
+import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
+import org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException;
+import org.opendaylight.controller.cluster.datastore.messages.AbstractRead;
+import org.opendaylight.mdsal.common.api.DataStoreUnavailableException;
+import org.opendaylight.mdsal.common.api.ReadFailedException;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.slf4j.Logger;
@@ -24,59 +26,60 @@ final class NoOpTransactionContext extends AbstractTransactionContext {
     private static final Logger LOG = LoggerFactory.getLogger(NoOpTransactionContext.class);
 
     private final Throwable failure;
-    private final Semaphore operationLimiter;
 
-    public NoOpTransactionContext(Throwable failure, TransactionIdentifier identifier, Semaphore operationLimiter) {
+    NoOpTransactionContext(final Throwable failure, final TransactionIdentifier identifier) {
         super(identifier);
         this.failure = failure;
-        this.operationLimiter = operationLimiter;
     }
 
     @Override
     public void closeTransaction() {
-        LOG.debug("NoOpTransactionContext {} closeTransaction called", identifier);
+        LOG.debug("NoOpTransactionContext {} closeTransaction called", getIdentifier());
     }
 
     @Override
-    public Future<ActorSelection> readyTransaction() {
-        LOG.debug("Tx {} readyTransaction called", identifier);
-        operationLimiter.release();
+    public Future<Object> directCommit(final Boolean havePermit) {
+        LOG.debug("Tx {} directCommit called, failure", getIdentifier(), failure);
         return akka.dispatch.Futures.failed(failure);
     }
 
     @Override
-    public void deleteData(YangInstanceIdentifier path) {
-        LOG.debug("Tx {} deleteData called path = {}", identifier, path);
-        operationLimiter.release();
+    public Future<ActorSelection> readyTransaction(final Boolean havePermit,
+            final Optional<SortedSet<String>> participatingShardNamess) {
+        LOG.debug("Tx {} readyTransaction called, failure", getIdentifier(), failure);
+        return akka.dispatch.Futures.failed(failure);
     }
 
     @Override
-    public void mergeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
-        LOG.debug("Tx {} mergeData called path = {}", identifier, path);
-        operationLimiter.release();
+    public <T> void executeRead(final AbstractRead<T> readCmd, final SettableFuture<T> proxyFuture,
+            final Boolean havePermit) {
+        LOG.debug("Tx {} executeRead {} called path = {}", getIdentifier(), readCmd.getClass().getSimpleName(),
+                readCmd.getPath());
+
+        final Throwable t;
+        if (failure instanceof NoShardLeaderException) {
+            t = new DataStoreUnavailableException(failure.getMessage(), failure);
+        } else {
+            t = failure;
+        }
+        proxyFuture.setException(new ReadFailedException("Error executeRead " + readCmd.getClass().getSimpleName()
+                + " for path " + readCmd.getPath(), t));
     }
 
     @Override
-    public void writeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
-        LOG.debug("Tx {} writeData called path = {}", identifier, path);
-        operationLimiter.release();
+    public void executeDelete(final YangInstanceIdentifier path, final Boolean havePermit) {
+        LOG.debug("Tx {} executeDelete called path = {}", getIdentifier(), path);
     }
 
     @Override
-    public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readData(
-            YangInstanceIdentifier path) {
-        LOG.debug("Tx {} readData called path = {}", identifier, path);
-        operationLimiter.release();
-        return Futures.immediateFailedCheckedFuture(new ReadFailedException(
-                "Error reading data for path " + path, failure));
+    public void executeMerge(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data,
+            final Boolean havePermit) {
+        LOG.debug("Tx {} executeMerge called path = {}", getIdentifier(), path);
     }
 
     @Override
-    public CheckedFuture<Boolean, ReadFailedException> dataExists(
-            YangInstanceIdentifier path) {
-        LOG.debug("Tx {} dataExists called path = {}", identifier, path);
-        operationLimiter.release();
-        return Futures.immediateFailedCheckedFuture(new ReadFailedException(
-                "Error checking exists for path " + path, failure));
+    public void executeWrite(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data,
+            final Boolean havePermit) {
+        LOG.debug("Tx {} executeWrite called path = {}", getIdentifier(), path);
     }
-}
\ No newline at end of file
+}