CDS: split TransactionType from TransactionProxy 89/19089/8
authorRobert Varga <rovarga@cisco.com>
Sat, 25 Apr 2015 15:05:01 +0000 (17:05 +0200)
committerTom Pantelis <tpanteli@brocade.com>
Fri, 8 May 2015 03:38:18 +0000 (23:38 -0400)
The type is used outside, too, so split it out into its own file.

Change-Id: I00589bc46b724ae5b0de3852056111a3f1bcb897
Signed-off-by: Robert Varga <rovarga@cisco.com>
18 files changed:
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStore.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardSnapshotCohort.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardTransaction.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardTransactionChain.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardTransactionFactory.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionFutureCallback.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionType.java [new file with mode: 0644]
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionProxyTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionFailureTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionProxyTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/compat/PreLithiumTransactionProxyTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/compat/ShardTransactionHeliumBackwardsCompatibilityTest.java

index 69c127f2897017f218222b2a95b270b1bcc9f0de..a136cc6f75392e9d95426fe786d10e9381a1a6cd 100644 (file)
@@ -149,19 +149,19 @@ public class DistributedDataStore implements DOMStore, SchemaContextListener,
 
     @Override
     public DOMStoreReadTransaction newReadOnlyTransaction() {
-        return new TransactionProxy(actorContext, TransactionProxy.TransactionType.READ_ONLY);
+        return new TransactionProxy(actorContext, TransactionType.READ_ONLY);
     }
 
     @Override
     public DOMStoreWriteTransaction newWriteOnlyTransaction() {
         actorContext.acquireTxCreationPermit();
-        return new TransactionProxy(actorContext, TransactionProxy.TransactionType.WRITE_ONLY);
+        return new TransactionProxy(actorContext, TransactionType.WRITE_ONLY);
     }
 
     @Override
     public DOMStoreReadWriteTransaction newReadWriteTransaction() {
         actorContext.acquireTxCreationPermit();
-        return new TransactionProxy(actorContext, TransactionProxy.TransactionType.READ_WRITE);
+        return new TransactionProxy(actorContext, TransactionType.READ_WRITE);
     }
 
     @Override
index e62e918e5e7eff53b8f7e00dbe1e8300d270b59f..2fd51de8b674be89a065f28d5f2cacd16ec101fc 100644 (file)
@@ -493,7 +493,7 @@ public class Shard extends RaftActor {
             ShardTransactionIdentifier transactionId, String transactionChainId,
             short clientVersion ) {
 
-        return transactionActorFactory.newShardTransaction(TransactionProxy.TransactionType.fromInt(transactionType),
+        return transactionActorFactory.newShardTransaction(TransactionType.fromInt(transactionType),
                 transactionId, transactionChainId, clientVersion);
     }
 
index 600509a26b87b480156f4baf843f2b887ed4f655..c4ac727cb3b59fa3efa77b2ef3ccf7427c2a81a7 100644 (file)
@@ -51,7 +51,7 @@ class ShardSnapshotCohort implements RaftActorSnapshotCohort {
                 "createSnapshot" + ++createSnapshotTransactionCounter);
 
         ActorRef createSnapshotTransaction = transactionActorFactory.newShardTransaction(
-                TransactionProxy.TransactionType.READ_ONLY, transactionID, "", DataStoreVersions.CURRENT_VERSION);
+                TransactionType.READ_ONLY, transactionID, "", DataStoreVersions.CURRENT_VERSION);
 
         createSnapshotTransaction.tell(CreateSnapshot.INSTANCE, actorRef);
     }
index 600ec393971ffe72efd12dfaaaf472cc61edd204..4f59f9feb52a5da87310d8d5e442bd2ca4dcf6b8 100644 (file)
@@ -16,7 +16,6 @@ import akka.japi.Creator;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import org.opendaylight.controller.cluster.common.actor.AbstractUntypedActorWithMetering;
-import org.opendaylight.controller.cluster.datastore.TransactionProxy.TransactionType;
 import org.opendaylight.controller.cluster.datastore.exceptions.UnknownMessageException;
 import org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard.ShardStats;
 import org.opendaylight.controller.cluster.datastore.messages.CloseTransaction;
index 7a163088d4bec3938132285810ae35d70f2127fe..aedc6c42b862d0cc2ffd94fc9082b82d38f2aa2e 100644 (file)
@@ -13,7 +13,6 @@ import akka.actor.ActorRef;
 import akka.actor.Props;
 import akka.japi.Creator;
 import org.opendaylight.controller.cluster.common.actor.AbstractUntypedActor;
-import org.opendaylight.controller.cluster.datastore.TransactionProxy.TransactionType;
 import org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard.ShardStats;
 import org.opendaylight.controller.cluster.datastore.messages.CloseTransactionChain;
 import org.opendaylight.controller.cluster.datastore.messages.CloseTransactionChainReply;
index 3a92062e7f86972d55fe7f230c655898d0f0acfb..f8b8b9c95252834b2f0661a2658005124c53ef0f 100644 (file)
@@ -37,7 +37,7 @@ class ShardTransactionActorFactory {
         this.shardActor = shardActor;
     }
 
-    ActorRef newShardTransaction(TransactionProxy.TransactionType type, ShardTransactionIdentifier transactionID,
+    ActorRef newShardTransaction(TransactionType type, ShardTransactionIdentifier transactionID,
             String transactionChainID, short clientVersion) {
         final AbstractShardDataTreeTransaction<?> transaction;
         switch (type) {
index cf261cbd2af103b70f3dfce9885903a88ee293e6..97f3e7444d3ee564c88845256e7448209036fe09 100644 (file)
@@ -91,20 +91,20 @@ public class TransactionChainProxy implements DOMStoreTransactionChain {
         State localState = currentState;
         checkReadyState(localState);
 
-        return new ChainedTransactionProxy(actorContext, TransactionProxy.TransactionType.READ_ONLY,
+        return new ChainedTransactionProxy(actorContext, TransactionType.READ_ONLY,
                 transactionChainId, localState.getPreviousReadyFutures());
     }
 
     @Override
     public DOMStoreReadWriteTransaction newReadWriteTransaction() {
         actorContext.acquireTxCreationPermit();
-        return allocateWriteTransaction(TransactionProxy.TransactionType.READ_WRITE);
+        return allocateWriteTransaction(TransactionType.READ_WRITE);
     }
 
     @Override
     public DOMStoreWriteTransaction newWriteOnlyTransaction() {
         actorContext.acquireTxCreationPermit();
-        return allocateWriteTransaction(TransactionProxy.TransactionType.WRITE_ONLY);
+        return allocateWriteTransaction(TransactionType.WRITE_ONLY);
     }
 
     @Override
@@ -115,7 +115,7 @@ public class TransactionChainProxy implements DOMStoreTransactionChain {
         actorContext.broadcast(new CloseTransactionChain(transactionChainId).toSerializable());
     }
 
-    private ChainedTransactionProxy allocateWriteTransaction(TransactionProxy.TransactionType type) {
+    private ChainedTransactionProxy allocateWriteTransaction(TransactionType type) {
         State localState = currentState;
 
         checkReadyState(localState);
index a8a93c5e7ce196a2a5e7c0a0e60678b40bbb0854..0fddd66c54cbe77ece3f7d52a40f8a009c1e978c 100644 (file)
@@ -17,7 +17,6 @@ import java.util.List;
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.TimeUnit;
 import javax.annotation.concurrent.GuardedBy;
-import org.opendaylight.controller.cluster.datastore.TransactionProxy.TransactionType;
 import org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException;
 import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier;
 import org.opendaylight.controller.cluster.datastore.messages.CreateTransaction;
index c9f1f752068506becc15163a528dbf501905f064..950434390dfe831192e8f1c847dcf35524d8f75a 100644 (file)
@@ -62,23 +62,6 @@ import scala.concurrent.Promise;
  */
 public class TransactionProxy extends AbstractDOMStoreTransaction<TransactionIdentifier> implements DOMStoreReadWriteTransaction {
 
-    public static enum TransactionType {
-        READ_ONLY,
-        WRITE_ONLY,
-        READ_WRITE;
-
-        // Cache all values
-        private static final TransactionType[] VALUES = values();
-
-        public static TransactionType fromInt(final int type) {
-            try {
-                return VALUES[type];
-            } catch (IndexOutOfBoundsException e) {
-                throw new IllegalArgumentException("In TransactionType enum value " + type, e);
-            }
-        }
-    }
-
     private static enum TransactionState {
         OPEN,
         READY,
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionType.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionType.java
new file mode 100644 (file)
index 0000000..649dae5
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.datastore;
+
+public enum TransactionType {
+    READ_ONLY,
+    WRITE_ONLY,
+    READ_WRITE;
+
+    // Cache all values
+    private static final TransactionType[] VALUES = values();
+
+    public static TransactionType fromInt(final int type) {
+        try {
+            return VALUES[type];
+        } catch (IndexOutOfBoundsException e) {
+            throw new IllegalArgumentException("In TransactionType enum value " + type, e);
+        }
+    }
+}
\ No newline at end of file
index a64a5802b8387102bdfac19e4535a440088ccf55..c22b7acd386cf3c5ecc66ab8dbbf2cc1d75f7e8f 100644 (file)
@@ -46,7 +46,6 @@ import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
 import org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder;
-import org.opendaylight.controller.cluster.datastore.TransactionProxy.TransactionType;
 import org.opendaylight.controller.cluster.datastore.TransactionProxyTest.TestException;
 import org.opendaylight.controller.cluster.datastore.messages.BatchedModifications;
 import org.opendaylight.controller.cluster.datastore.messages.BatchedModificationsReply;
index 1ecf0971c10d3f0a429f3c56ea36d84eaa44befc..06d9f360aae23ab8edb0d99e5529ae6457e1d3b7 100644 (file)
@@ -365,7 +365,7 @@ public class ShardTest extends AbstractShardTest {
             shard.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
 
             shard.tell(new CreateTransaction("txn-1",
-                    TransactionProxy.TransactionType.READ_ONLY.ordinal() ).toSerializable(), getRef());
+                    TransactionType.READ_ONLY.ordinal() ).toSerializable(), getRef());
 
             CreateTransactionReply reply = expectMsgClass(duration("3 seconds"),
                     CreateTransactionReply.class);
@@ -386,7 +386,7 @@ public class ShardTest extends AbstractShardTest {
             waitUntilLeader(shard);
 
             shard.tell(new CreateTransaction("txn-1",
-                    TransactionProxy.TransactionType.READ_ONLY.ordinal() , "foobar").toSerializable(),
+                    TransactionType.READ_ONLY.ordinal() , "foobar").toSerializable(),
                     getRef());
 
             CreateTransactionReply reply = expectMsgClass(duration("3 seconds"),
@@ -961,7 +961,7 @@ public class ShardTest extends AbstractShardTest {
 
             // Create a read Tx on the same chain.
 
-            shard.tell(new CreateTransaction(transactionID2, TransactionProxy.TransactionType.READ_ONLY.ordinal() ,
+            shard.tell(new CreateTransaction(transactionID2, TransactionType.READ_ONLY.ordinal() ,
                     transactionChainID).toSerializable(), getRef());
 
             CreateTransactionReply createReply = expectMsgClass(duration("3 seconds"), CreateTransactionReply.class);
index e45389f5f36fbd151a24ae9e4d5a02a4995a2772..15f61660643ea1f02e84055d42aad749d305983e 100644 (file)
@@ -17,7 +17,6 @@ import akka.testkit.TestActorRef;
 import java.util.Collections;
 import java.util.concurrent.TimeUnit;
 import org.junit.Test;
-import org.opendaylight.controller.cluster.datastore.TransactionProxy.TransactionType;
 import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier;
 import org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard.ShardStats;
 import org.opendaylight.controller.cluster.datastore.node.utils.serialization.NormalizedNodeSerializer;
index 23984ad973933666d41fb60c762e18517181ef1a..f20db19bd7ea137cd786c9fc30cdb23c7828d53a 100644 (file)
@@ -17,7 +17,6 @@ import org.junit.Test;
 import org.mockito.InOrder;
 import org.mockito.Mockito;
 import org.opendaylight.controller.cluster.datastore.ShardWriteTransaction.GetCompositeModificationReply;
-import org.opendaylight.controller.cluster.datastore.TransactionProxy.TransactionType;
 import org.opendaylight.controller.cluster.datastore.exceptions.UnknownMessageException;
 import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier;
 import org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard.ShardStats;
index 026b5490288c1bbdeb1ec44d37e998abddad813e..76f299b548596a05b11280c8c0402ea6c0faae7b 100644 (file)
@@ -21,8 +21,8 @@ import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.timeout;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
-import static org.opendaylight.controller.cluster.datastore.TransactionProxy.TransactionType.READ_WRITE;
-import static org.opendaylight.controller.cluster.datastore.TransactionProxy.TransactionType.WRITE_ONLY;
+import static org.opendaylight.controller.cluster.datastore.TransactionType.READ_WRITE;
+import static org.opendaylight.controller.cluster.datastore.TransactionType.WRITE_ONLY;
 import akka.actor.ActorRef;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
index 844feb2f47e988b89498a80946d97aecbff8c049..dd55441c2a22a014d725674379c071c990c051cf 100644 (file)
@@ -11,9 +11,9 @@ import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
-import static org.opendaylight.controller.cluster.datastore.TransactionProxy.TransactionType.READ_ONLY;
-import static org.opendaylight.controller.cluster.datastore.TransactionProxy.TransactionType.READ_WRITE;
-import static org.opendaylight.controller.cluster.datastore.TransactionProxy.TransactionType.WRITE_ONLY;
+import static org.opendaylight.controller.cluster.datastore.TransactionType.READ_ONLY;
+import static org.opendaylight.controller.cluster.datastore.TransactionType.READ_WRITE;
+import static org.opendaylight.controller.cluster.datastore.TransactionType.WRITE_ONLY;
 import akka.actor.ActorRef;
 import akka.actor.ActorSelection;
 import akka.actor.ActorSystem;
@@ -34,7 +34,6 @@ import org.junit.Assert;
 import org.junit.Test;
 import org.mockito.InOrder;
 import org.mockito.Mockito;
-import org.opendaylight.controller.cluster.datastore.TransactionProxy.TransactionType;
 import org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException;
 import org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException;
 import org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException;
@@ -677,7 +676,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest {
     public void testGetIdentifier() {
         setupActorContextWithInitialCreateTransaction(getSystem(), READ_ONLY);
         TransactionProxy transactionProxy = new TransactionProxy(mockActorContext,
-                TransactionProxy.TransactionType.READ_ONLY);
+                TransactionType.READ_ONLY);
 
         Object id = transactionProxy.getIdentifier();
         assertNotNull("getIdentifier returned null", id);
index ca342b960a8749d78ae5aa0b1879b06ecc61110b..5681b760920a8615910bb1661ed16702b42df519 100644 (file)
@@ -15,8 +15,8 @@ import static org.mockito.Matchers.eq;
 import static org.mockito.Matchers.isA;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.verify;
-import static org.opendaylight.controller.cluster.datastore.TransactionProxy.TransactionType.READ_WRITE;
-import static org.opendaylight.controller.cluster.datastore.TransactionProxy.TransactionType.WRITE_ONLY;
+import static org.opendaylight.controller.cluster.datastore.TransactionType.READ_WRITE;
+import static org.opendaylight.controller.cluster.datastore.TransactionType.WRITE_ONLY;
 import akka.actor.ActorRef;
 import akka.dispatch.Futures;
 import akka.util.Timeout;
index e206e69cdaaa88d04ca38ab530865ba9e7e37320..cdbab1c6d1c7b9cdd70bddf92efc733ee64d7f93 100644 (file)
@@ -22,7 +22,7 @@ import org.opendaylight.controller.cluster.datastore.DatastoreContext;
 import org.opendaylight.controller.cluster.datastore.Shard;
 import org.opendaylight.controller.cluster.datastore.ShardTest;
 import org.opendaylight.controller.cluster.datastore.ShardTestKit;
-import org.opendaylight.controller.cluster.datastore.TransactionProxy;
+import org.opendaylight.controller.cluster.datastore.TransactionType;
 import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier;
 import org.opendaylight.controller.cluster.datastore.messages.AbortTransactionReply;
 import org.opendaylight.controller.cluster.datastore.messages.CanCommitTransactionReply;
@@ -73,7 +73,7 @@ public class ShardTransactionHeliumBackwardsCompatibilityTest extends AbstractAc
             String transactionID = "txn-1";
             shard.tell(ShardTransactionMessages.CreateTransaction.newBuilder()
                     .setTransactionId(transactionID)
-                    .setTransactionType(TransactionProxy.TransactionType.WRITE_ONLY.ordinal())
+                    .setTransactionType(TransactionType.WRITE_ONLY.ordinal())
                     .setTransactionChainId("").build(), getRef());
 
             final FiniteDuration duration = duration("5 seconds");
@@ -147,7 +147,7 @@ public class ShardTransactionHeliumBackwardsCompatibilityTest extends AbstractAc
             String transactionID = "txn-1";
             shard.tell(ShardTransactionMessages.CreateTransaction.newBuilder()
                     .setTransactionId(transactionID)
-                    .setTransactionType(TransactionProxy.TransactionType.WRITE_ONLY.ordinal())
+                    .setTransactionType(TransactionType.WRITE_ONLY.ordinal())
                     .setTransactionChainId("").build(), getRef());
 
             final FiniteDuration duration = duration("5 seconds");