X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FLocalTransactionContext.java;h=b201486fb2267c8bad28e8cd5d0ecbc9bf045bb4;hp=9b0accd455117f464d556fa8fc8c73f1990d0b23;hb=HEAD;hpb=d71b6614d6cdb5a98f086edeb56f5c52f365c61c diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalTransactionContext.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalTransactionContext.java deleted file mode 100644 index 9b0accd455..0000000000 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalTransactionContext.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2015 Brocade Communications 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; - -import akka.actor.ActorSelection; -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.SettableFuture; -import org.opendaylight.controller.cluster.datastore.utils.ActorContext; -import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction; -import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransaction; -import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import scala.concurrent.Future; - -/** - * Processes front-end transaction operations locally before being committed to the destination shard. - * Instances of this class are used when the destination shard is local to the caller. - * - * @author Thomas Pantelis - */ -abstract class LocalTransactionContext extends AbstractTransactionContext { - private final DOMStoreTransaction txDelegate; - - LocalTransactionContext(DOMStoreTransaction txDelegate, OperationLimiter limiter) { - super(limiter); - this.txDelegate = Preconditions.checkNotNull(txDelegate); - } - - protected abstract DOMStoreWriteTransaction getWriteDelegate(); - - protected abstract DOMStoreReadTransaction getReadDelegate(); - - @Override - public void writeData(YangInstanceIdentifier path, NormalizedNode data) { - incrementModificationCount(); - getWriteDelegate().write(path, data); - releaseOperation(); - } - - @Override - public void mergeData(YangInstanceIdentifier path, NormalizedNode data) { - incrementModificationCount(); - getWriteDelegate().merge(path, data); - releaseOperation(); - } - - @Override - public void deleteData(YangInstanceIdentifier path) { - incrementModificationCount(); - getWriteDelegate().delete(path); - releaseOperation(); - } - - @Override - public void readData(YangInstanceIdentifier path, final SettableFuture>> proxyFuture) { - Futures.addCallback(getReadDelegate().read(path), new FutureCallback>>() { - @Override - public void onSuccess(final Optional> result) { - proxyFuture.set(result); - releaseOperation(); - } - - @Override - public void onFailure(final Throwable t) { - proxyFuture.setException(t); - releaseOperation(); - } - }); - } - - @Override - public void dataExists(YangInstanceIdentifier path, final SettableFuture proxyFuture) { - Futures.addCallback(getReadDelegate().exists(path), new FutureCallback() { - @Override - public void onSuccess(final Boolean result) { - proxyFuture.set(result); - releaseOperation(); - } - - @Override - public void onFailure(final Throwable t) { - proxyFuture.setException(t); - releaseOperation(); - } - }); - } - - private LocalThreePhaseCommitCohort ready() { - logModificationCount(); - acquireOperation(); - return (LocalThreePhaseCommitCohort) getWriteDelegate().ready(); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - private T completeOperation(final ActorContext actorContext, final T operationFuture) { - operationFuture.onComplete(getLimiter(), actorContext.getClientDispatcher()); - return operationFuture; - } - - @Override - public Future readyTransaction() { - final LocalThreePhaseCommitCohort cohort = ready(); - return completeOperation(cohort.getActorContext(), cohort.initiateCoordinatedCommit()); - } - - @Override - public Future directCommit() { - final LocalThreePhaseCommitCohort cohort = ready(); - return completeOperation(cohort.getActorContext(), cohort.initiateDirectCommit()); - } - - @Override - public boolean supportsDirectCommit() { - return true; - } - - @Override - public void closeTransaction() { - txDelegate.close(); - releaseOperation(); - } -}