BUG-5280: refactor CohortEntry 28/41428/3
authorRobert Varga <rovarga@cisco.com>
Wed, 6 Jul 2016 17:46:39 +0000 (19:46 +0200)
committerRobert Varga <rovarga@cisco.com>
Mon, 11 Jul 2016 11:08:20 +0000 (13:08 +0200)
CohortEntry can be created in two transaction states: open and ready.
Make this explicit by hiding the two constructors and exposing two
explicit factory methods.

Change-Id: I33cb5a272828b23b8a6a2da5fad2ac3ead83ee7b
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/CohortEntry.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardCommitCoordinator.java

index 073f081..06d3ec9 100644 (file)
@@ -47,7 +47,7 @@ final class CohortEntry {
     private ActorRef replySender;
     private Shard shard;
 
-    CohortEntry(TransactionIdentifier transactionID, ReadWriteShardDataTreeTransaction transaction,
+    private CohortEntry(TransactionIdentifier transactionID, ReadWriteShardDataTreeTransaction transaction,
             DataTreeCohortActorRegistry cohortRegistry, SchemaContext schema, short clientVersion) {
         this.transaction = Preconditions.checkNotNull(transaction);
         this.transactionID = Preconditions.checkNotNull(transactionID);
@@ -55,7 +55,7 @@ final class CohortEntry {
         this.userCohorts = new CompositeDataTreeCohort(cohortRegistry, transactionID, schema, COMMIT_STEP_TIMEOUT);
     }
 
-    CohortEntry(TransactionIdentifier transactionID, ShardDataTreeCohort cohort, DataTreeCohortActorRegistry cohortRegistry,
+    private CohortEntry(TransactionIdentifier transactionID, ShardDataTreeCohort cohort, DataTreeCohortActorRegistry cohortRegistry,
             SchemaContext schema, short clientVersion) {
         this.transactionID = Preconditions.checkNotNull(transactionID);
         this.cohort = cohort;
@@ -64,6 +64,16 @@ final class CohortEntry {
         this.userCohorts = new CompositeDataTreeCohort(cohortRegistry, transactionID, schema, COMMIT_STEP_TIMEOUT);
     }
 
+    static CohortEntry createOpen(TransactionIdentifier transactionID, ReadWriteShardDataTreeTransaction transaction,
+            DataTreeCohortActorRegistry cohortRegistry, SchemaContext schema, short clientVersion) {
+        return new CohortEntry(transactionID, transaction, cohortRegistry, schema, clientVersion);
+    }
+
+    static CohortEntry createReady(TransactionIdentifier transactionID, ShardDataTreeCohort cohort,
+            DataTreeCohortActorRegistry cohortRegistry, SchemaContext schema, short clientVersion) {
+        return new CohortEntry(transactionID, cohort, cohortRegistry, schema, clientVersion);
+    }
+
     void updateLastAccessTime() {
         lastAccessTimer.reset();
         lastAccessTimer.start();
index 08ba31f..eb0c04d 100644 (file)
@@ -143,7 +143,8 @@ final class ShardCommitCoordinator {
                 ready.getTransactionID(), ready.getTxnClientVersion());
 
         final ShardDataTreeCohort cohort = ready.getTransaction().ready();
-        final CohortEntry cohortEntry = new CohortEntry(ready.getTransactionID(), cohort, cohortRegistry, schema, ready.getTxnClientVersion());
+        final CohortEntry cohortEntry = CohortEntry.createReady(ready.getTransactionID(), cohort, cohortRegistry,
+            schema, ready.getTxnClientVersion());
         cohortCache.put(cohortEntry.getTransactionID(), cohortEntry);
 
         if(!queueCohortEntry(cohortEntry, sender, shard)) {
@@ -174,7 +175,7 @@ final class ShardCommitCoordinator {
     void handleBatchedModifications(BatchedModifications batched, ActorRef sender, Shard shard) {
         CohortEntry cohortEntry = cohortCache.get(batched.getTransactionID());
         if(cohortEntry == null) {
-            cohortEntry = new CohortEntry(batched.getTransactionID(),
+            cohortEntry = CohortEntry.createOpen(batched.getTransactionID(),
                     dataTree.newReadWriteTransaction(batched.getTransactionID()),
                     cohortRegistry, dataTree.getSchemaContext(), batched.getVersion());
             cohortCache.put(cohortEntry.getTransactionID(), cohortEntry);
@@ -235,7 +236,7 @@ final class ShardCommitCoordinator {
     void handleReadyLocalTransaction(ReadyLocalTransaction message, ActorRef sender, Shard shard) {
         final ShardDataTreeCohort cohort = new SimpleShardDataTreeCohort(dataTree, message.getModification(),
                 message.getTransactionID());
-        final CohortEntry cohortEntry = new CohortEntry(message.getTransactionID(), cohort, cohortRegistry,
+        final CohortEntry cohortEntry = CohortEntry.createReady(message.getTransactionID(), cohort, cohortRegistry,
             dataTree.getSchemaContext(), DataStoreVersions.CURRENT_VERSION);
         cohortCache.put(cohortEntry.getTransactionID(), cohortEntry);
         cohortEntry.setDoImmediateCommit(message.isDoCommitOnReady());