Move forwardToRemote() to LocalProxyTransaction 40/53540/2
authorAndrej Mak <andrej.mak@pantheon.tech>
Mon, 20 Mar 2017 08:04:45 +0000 (09:04 +0100)
committerTom Pantelis <tpanteli@brocade.com>
Tue, 21 Mar 2017 16:05:10 +0000 (16:05 +0000)
Method has the same body in both implementations, so
it can be moved to parrent class.

Change-Id: I25f7cb99cc3727f0cbb8da9e59343a663d776e11
Signed-off-by: Andrej Mak <andrej.mak@pantheon.tech>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalProxyTransaction.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalReadOnlyProxyTransaction.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalReadWriteProxyTransaction.java

index 5e78f44..747fd14 100644 (file)
@@ -110,7 +110,7 @@ abstract class LocalProxyTransaction extends AbstractProxyTransaction {
 
     @Override
     void forwardToRemote(final RemoteProxyTransaction successor, final TransactionRequest<?> request,
-            final Consumer<Response<?, ?>> callback) {
+                         final Consumer<Response<?, ?>> callback) {
         if (request instanceof CommitLocalTransactionRequest) {
             final CommitLocalTransactionRequest req = (CommitLocalTransactionRequest) request;
             final DataTreeModification mod = req.getModification();
@@ -140,6 +140,9 @@ abstract class LocalProxyTransaction extends AbstractProxyTransaction {
         } else if (request instanceof AbortLocalTransactionRequest) {
             LOG.debug("Forwarding abort {} to successor {}", request, successor);
             successor.abort();
+        } else if (request instanceof TransactionPurgeRequest) {
+            LOG.debug("Forwarding purge {} to successor {}", request, successor);
+            successor.purge();
         } else {
             throw new IllegalArgumentException("Unhandled request" + request);
         }
index 9806208..65e6bf6 100644 (file)
@@ -11,22 +11,14 @@ import com.google.common.base.Preconditions;
 import com.google.common.base.Verify;
 import java.util.function.Consumer;
 import javax.annotation.concurrent.NotThreadSafe;
-import org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest;
 import org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest;
 import org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest;
 import org.opendaylight.controller.cluster.access.commands.PersistenceProtocol;
-import org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest;
-import org.opendaylight.controller.cluster.access.commands.TransactionRequest;
 import org.opendaylight.controller.cluster.access.concepts.Response;
 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
-import org.opendaylight.controller.cluster.datastore.util.AbstractDataTreeModificationCursor;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * A read-only specialization of {@link LocalProxyTransaction}.
@@ -35,7 +27,6 @@ import org.slf4j.LoggerFactory;
  */
 @NotThreadSafe
 final class LocalReadOnlyProxyTransaction extends LocalProxyTransaction {
-    private static final Logger LOG = LoggerFactory.getLogger(LocalReadOnlyProxyTransaction.class);
 
     private final DataTreeSnapshot snapshot;
 
@@ -95,43 +86,4 @@ final class LocalReadOnlyProxyTransaction extends LocalProxyTransaction {
         abort();
     }
 
-    @Override
-    void forwardToRemote(final RemoteProxyTransaction successor, final TransactionRequest<?> request,
-            final Consumer<Response<?, ?>> callback) {
-        if (request instanceof CommitLocalTransactionRequest) {
-            final CommitLocalTransactionRequest req = (CommitLocalTransactionRequest) request;
-            final DataTreeModification mod = req.getModification();
-
-            LOG.debug("Applying modification {} to successor {}", mod, successor);
-            mod.applyToCursor(new AbstractDataTreeModificationCursor() {
-                @Override
-                public void write(final PathArgument child, final NormalizedNode<?, ?> data) {
-                    successor.write(current().node(child), data);
-                }
-
-                @Override
-                public void merge(final PathArgument child, final NormalizedNode<?, ?> data) {
-                    successor.merge(current().node(child), data);
-                }
-
-                @Override
-                public void delete(final PathArgument child) {
-                    successor.delete(current().node(child));
-                }
-            });
-
-            successor.ensureSealed();
-
-            final ModifyTransactionRequest successorReq = successor.commitRequest(req.isCoordinated());
-            successor.sendRequest(successorReq, callback);
-        } else if (request instanceof AbortLocalTransactionRequest) {
-            LOG.debug("Forwarding abort {} to successor {}", request, successor);
-            successor.abort();
-        } else if (request instanceof TransactionPurgeRequest) {
-            LOG.debug("Forwarding purge {} to successor {}", request, successor);
-            successor.purge();
-        } else {
-            throw new IllegalArgumentException("Unhandled request" + request);
-        }
-    }
 }
index 3407da7..18d596f 100644 (file)
@@ -12,7 +12,6 @@ import com.google.common.base.Verify;
 import java.util.function.Consumer;
 import javax.annotation.Nullable;
 import javax.annotation.concurrent.NotThreadSafe;
-import org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest;
 import org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest;
 import org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest;
 import org.opendaylight.controller.cluster.access.commands.PersistenceProtocol;
@@ -22,7 +21,6 @@ import org.opendaylight.controller.cluster.access.commands.TransactionDoCommitRe
 import org.opendaylight.controller.cluster.access.commands.TransactionMerge;
 import org.opendaylight.controller.cluster.access.commands.TransactionModification;
 import org.opendaylight.controller.cluster.access.commands.TransactionPreCommitRequest;
-import org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest;
 import org.opendaylight.controller.cluster.access.commands.TransactionRequest;
 import org.opendaylight.controller.cluster.access.commands.TransactionWrite;
 import org.opendaylight.controller.cluster.access.concepts.Response;
@@ -142,7 +140,7 @@ final class LocalReadWriteProxyTransaction extends LocalProxyTransaction {
     @Override
     void applyModifyTransactionRequest(final ModifyTransactionRequest request,
             final @Nullable Consumer<Response<?, ?>> callback) {
-        for (TransactionModification mod : request.getModifications()) {
+        for (final TransactionModification mod : request.getModifications()) {
             if (mod instanceof TransactionWrite) {
                 modification.write(mod.getPath(), ((TransactionWrite)mod).getData());
             } else if (mod instanceof TransactionMerge) {
@@ -194,46 +192,6 @@ final class LocalReadWriteProxyTransaction extends LocalProxyTransaction {
         }
     }
 
-    @Override
-    void forwardToRemote(final RemoteProxyTransaction successor, final TransactionRequest<?> request,
-            final Consumer<Response<?, ?>> callback) {
-        if (request instanceof CommitLocalTransactionRequest) {
-            final CommitLocalTransactionRequest req = (CommitLocalTransactionRequest) request;
-            final DataTreeModification mod = req.getModification();
-
-            LOG.debug("Applying modification {} to successor {}", mod, successor);
-            mod.applyToCursor(new AbstractDataTreeModificationCursor() {
-                @Override
-                public void write(final PathArgument child, final NormalizedNode<?, ?> data) {
-                    successor.write(current().node(child), data);
-                }
-
-                @Override
-                public void merge(final PathArgument child, final NormalizedNode<?, ?> data) {
-                    successor.merge(current().node(child), data);
-                }
-
-                @Override
-                public void delete(final PathArgument child) {
-                    successor.delete(current().node(child));
-                }
-            });
-
-            successor.ensureSealed();
-
-            final ModifyTransactionRequest successorReq = successor.commitRequest(req.isCoordinated());
-            successor.sendRequest(successorReq, callback);
-        } else if (request instanceof AbortLocalTransactionRequest) {
-            LOG.debug("Forwarding abort {} to successor {}", request, successor);
-            successor.abort();
-        } else if (request instanceof TransactionPurgeRequest) {
-            LOG.debug("Forwarding purge {} to successor {}", request, successor);
-            successor.purge();
-        } else {
-            throw new IllegalArgumentException("Unhandled request" + request);
-        }
-    }
-
     @Override
     void forwardToLocal(final LocalProxyTransaction successor, final TransactionRequest<?> request,
             final Consumer<Response<?, ?>> callback) {