X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatabroker%2Factors%2Fdds%2FClientLocalHistory.java;h=102d0506173a24bfc01bb6239e7fa4af98cc9698;hb=cc1ec4a8e2ec99ad7711d0e5e649b34d37d87da0;hp=8f2ee88563641b81c20137ba7acef23c8f909e9c;hpb=98d1c5606bad9633ce5549bcd691a98c75abdf6a;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientLocalHistory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientLocalHistory.java index 8f2ee88563..102d050617 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientLocalHistory.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientLocalHistory.java @@ -10,7 +10,7 @@ package org.opendaylight.controller.cluster.databroker.actors.dds; import com.google.common.annotations.Beta; import com.google.common.base.Preconditions; import com.google.common.base.Verify; -import java.util.concurrent.atomic.AtomicLongFieldUpdater; +import java.util.Optional; import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; @@ -18,6 +18,7 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier * Client-side view of a local history. This class tracks all state related to a particular history and routes * frontend requests towards the backend. * + *

* This interface is used by the world outside of the actor system and in the actor system it is manifested via * its client actor. That requires some state transfer with {@link DistributedDataStoreClientBehavior}. In order to * reduce request latency, all messages are carbon-copied (and enqueued first) to the client actor. @@ -26,27 +27,10 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier */ @Beta public final class ClientLocalHistory extends AbstractClientHistory implements AutoCloseable { - - private static final AtomicLongFieldUpdater NEXT_TX_UPDATER = - AtomicLongFieldUpdater.newUpdater(ClientLocalHistory.class, "nextTx"); - - // Used via NEXT_TX_UPDATER - @SuppressWarnings("unused") - private volatile long nextTx = 0; - ClientLocalHistory(final DistributedDataStoreClientBehavior client, final LocalHistoryIdentifier historyId) { super(client, historyId); } - public ClientTransaction createTransaction() { - final State local = state(); - Preconditions.checkState(local == State.IDLE, "Local history %s state is %s", this, local); - updateState(local, State.TX_OPEN); - - return new ClientTransaction(getClient(), this, - new TransactionIdentifier(getIdentifier(), NEXT_TX_UPDATER.getAndIncrement(this))); - } - @Override public void close() { final State local = state(); @@ -57,10 +41,28 @@ public final class ClientLocalHistory extends AbstractClientHistory implements A } @Override - void onTransactionReady(final ClientTransaction transaction) { + ClientTransaction doCreateTransaction() { + final State local = state(); + Preconditions.checkState(local == State.IDLE, "Local history %s state is %s", this, local); + updateState(local, State.TX_OPEN); + + return new ClientTransaction(this, new TransactionIdentifier(getIdentifier(), nextTx())); + } + + @Override + AbstractTransactionCommitCohort onTransactionReady(final TransactionIdentifier txId, + final AbstractTransactionCommitCohort cohort) { + // FIXME: deal with CLOSED here final State local = state(); Verify.verify(local == State.TX_OPEN, "Local history %s is in unexpected state %s", this, local); updateState(local, State.IDLE); - super.onTransactionReady(transaction); + + return super.onTransactionReady(txId, cohort); + } + + @Override + AbstractProxyHistory createHistoryProxy(final LocalHistoryIdentifier historyId, + final Optional backendInfo) { + return AbstractProxyHistory.createClient(getClient(), backendInfo, historyId); } }