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=493eb4089eb86cf9f119bfdf5589f780404b3715;hb=1d7e8fd9d781f630dee9dfb1b509067dd7fb9caa;hp=ac1872835ac37a612acdd0e9401c57c17f789c6a;hpb=db9a673c114febc785fbd324947ac2c3e3095d06;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 ac1872835a..493eb4089e 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 @@ -25,52 +25,60 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier * @author Robert Varga */ @Beta -public final class ClientLocalHistory extends AbstractClientHistory implements AutoCloseable { +public class ClientLocalHistory extends AbstractClientHistory implements AutoCloseable { ClientLocalHistory(final AbstractDataStoreClientBehavior client, final LocalHistoryIdentifier historyId) { super(client, historyId); } @Override public void close() { - final State local = state(); - if (local != State.CLOSED) { - Preconditions.checkState(local == State.IDLE, "Local history %s has an open transaction", this); - updateState(local, State.CLOSED); - } + doClose(); } - @Override - ClientTransaction doCreateTransaction() { + private State ensureIdleState() { final State local = state(); Preconditions.checkState(local == State.IDLE, "Local history %s state is %s", this, local); - updateState(local, State.TX_OPEN); + return local; + } + @Override + ClientSnapshot doCreateSnapshot() { + ensureIdleState(); + return new ClientSnapshot(this, new TransactionIdentifier(getIdentifier(), nextTx())); + } + + @Override + ClientTransaction doCreateTransaction() { + updateState(ensureIdleState(), State.TX_OPEN); return new ClientTransaction(this, new TransactionIdentifier(getIdentifier(), nextTx())); } @Override - void onTransactionAbort(final TransactionIdentifier txId) { - final State local = state(); - if (local == State.TX_OPEN) { - updateState(local, State.IDLE); + void onTransactionAbort(final AbstractClientHandle snap) { + if (snap instanceof ClientTransaction) { + final State local = state(); + if (local == State.TX_OPEN) { + updateState(local, State.IDLE); + } } - super.onTransactionAbort(txId); + super.onTransactionAbort(snap); } @Override - AbstractTransactionCommitCohort onTransactionReady(final TransactionIdentifier txId, + AbstractTransactionCommitCohort onTransactionReady(final ClientTransaction tx, final AbstractTransactionCommitCohort cohort) { + final State local = state(); switch (local) { case CLOSED: - return super.onTransactionReady(txId, cohort); + return super.onTransactionReady(tx, cohort); case IDLE: throw new IllegalStateException(String.format("Local history %s is idle when readying transaction %s", - this, txId)); + this, tx.getIdentifier())); case TX_OPEN: updateState(local, State.IDLE); - return super.onTransactionReady(txId, cohort); + return super.onTransactionReady(tx, cohort); default: throw new IllegalStateException(String.format("Local history %s in unhandled state %s", this, local)); @@ -80,6 +88,6 @@ public final class ClientLocalHistory extends AbstractClientHistory implements A @Override ProxyHistory createHistoryProxy(final LocalHistoryIdentifier historyId, final AbstractClientConnection connection) { - return ProxyHistory.createClient(connection, historyId); + return ProxyHistory.createClient(this, connection, historyId); } }