From: Robert Varga Date: Wed, 6 Jul 2016 17:46:39 +0000 (+0200) Subject: BUG-5280: refactor CohortEntry X-Git-Tag: release/boron~71 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=23472d531aca7f695082a3d57719894bfa34d0ac;hp=647fcf3b6ed4fb42f462be03e71f6d8244f71056 BUG-5280: refactor CohortEntry 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 --- diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/CohortEntry.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/CohortEntry.java index 073f0814c0..06d3ec9d67 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/CohortEntry.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/CohortEntry.java @@ -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(); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardCommitCoordinator.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardCommitCoordinator.java index 08ba31f79b..eb0c04dbbd 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardCommitCoordinator.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardCommitCoordinator.java @@ -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());