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%2Fdatastore%2FAbstractTransactionContextFactory.java;h=29b52f75579b57e2fbad4563585de9b10828d154;hb=546cd1fd100dbaa36908b22c2f422320dbd8c4b2;hp=69c69bb84b395dc5d89db35f74cdd44343987c95;hpb=925cb4a228d0fda99c7bfeb432eb25285a223887;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionContextFactory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionContextFactory.java index 69c69bb84b..29b52f7557 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionContextFactory.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionContextFactory.java @@ -7,24 +7,24 @@ */ package org.opendaylight.controller.cluster.datastore; +import static java.util.Objects.requireNonNull; + import akka.actor.ActorSelection; -import akka.dispatch.OnComplete; -import com.google.common.base.Preconditions; import java.util.Collection; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicLongFieldUpdater; -import javax.annotation.Nonnull; +import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier; import org.opendaylight.controller.cluster.access.concepts.MemberName; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo; -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.DOMStoreReadWriteTransaction; -import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree; +import org.opendaylight.controller.cluster.datastore.utils.ActorUtils; +import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction; +import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction; +import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction; +import org.opendaylight.yangtools.yang.data.api.schema.tree.ReadOnlyDataTree; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import scala.concurrent.Future; @@ -42,20 +42,19 @@ abstract class AbstractTransactionContextFactory knownLocal = new ConcurrentHashMap<>(); private final LocalHistoryIdentifier historyId; - private final ActorContext actorContext; + private final ActorUtils actorUtils; // Used via TX_COUNTER_UPDATER @SuppressWarnings("unused") private volatile long nextTx; - protected AbstractTransactionContextFactory(final ActorContext actorContext, - final LocalHistoryIdentifier historyId) { - this.actorContext = Preconditions.checkNotNull(actorContext); - this.historyId = Preconditions.checkNotNull(historyId); + protected AbstractTransactionContextFactory(final ActorUtils actorUtils, final LocalHistoryIdentifier historyId) { + this.actorUtils = requireNonNull(actorUtils); + this.historyId = requireNonNull(historyId); } - final ActorContext getActorContext() { - return actorContext; + final ActorUtils getActorUtils() { + return actorUtils; } final LocalHistoryIdentifier getHistoryId() { @@ -80,20 +79,48 @@ abstract class AbstractTransactionContextFactory findPrimaryFuture = findPrimaryShard(shardName, parent.getIdentifier()); + final DelayedTransactionContextWrapper contextWrapper = new DelayedTransactionContextWrapper( + parent.getIdentifier(), actorUtils, shardName); + final Future findPrimaryFuture = findPrimaryShard(shardName, parent.getIdentifier()); if (findPrimaryFuture.isCompleted()) { - Try maybe = findPrimaryFuture.value().get(); + final Try maybe = findPrimaryFuture.value().get(); if (maybe.isSuccess()) { - onFindPrimaryShardSuccess(maybe.get(), parent, shardName, transactionContextWrapper); + return maybeCreateDirectTransactionContextWrapper(maybe.get(), parent, shardName, + contextWrapper); } else { - onFindPrimaryShardFailure(maybe.failed().get(), parent, shardName, transactionContextWrapper); + onFindPrimaryShardFailure(maybe.failed().get(), parent, shardName, + contextWrapper); } } else { - findPrimaryFuture.onComplete(new OnComplete() { - @Override - public void onComplete(final Throwable failure, final PrimaryShardInfo primaryShardInfo) { - if (failure == null) { - onFindPrimaryShardSuccess(primaryShardInfo, parent, shardName, transactionContextWrapper); - } else { - onFindPrimaryShardFailure(failure, parent, shardName, transactionContextWrapper); - } + findPrimaryFuture.onComplete(result -> { + if (result.isSuccess()) { + onFindPrimaryShardSuccess(result.get(), parent, shardName, contextWrapper); + } else { + onFindPrimaryShardFailure(result.failed().get(), parent, shardName, contextWrapper); } - }, actorContext.getClientDispatcher()); + return null; + }, actorUtils.getClientDispatcher()); } - - return transactionContextWrapper; + return contextWrapper; } private void updateShardInfo(final String shardName, final PrimaryShardInfo primaryShardInfo) { - final Optional maybeDataTree = primaryShardInfo.getLocalShardDataTree(); + final Optional maybeDataTree = primaryShardInfo.getLocalShardDataTree(); if (maybeDataTree.isPresent()) { if (!knownLocal.containsKey(shardName)) { LOG.debug("Shard {} resolved to local data tree - adding local factory", shardName); @@ -177,8 +202,8 @@ abstract class AbstractTransactionContextFactory findPrimaryShard(@Nonnull String shardName, - @Nonnull TransactionIdentifier txId); + protected abstract Future findPrimaryShard(@NonNull String shardName, + @NonNull TransactionIdentifier txId); /** * Create local transaction factory for specified shard, backed by specified shard leader @@ -190,22 +215,22 @@ abstract class AbstractTransactionContextFactory void onTransactionReady(@Nonnull TransactionIdentifier transaction, - @Nonnull Collection> cohortFutures); + protected abstract void onTransactionReady(@NonNull TransactionIdentifier transaction, + @NonNull Collection> cohortFutures); /** * Callback invoked when the internal TransactionContext has been created for a transaction. * * @param transactionId the ID of the transaction. */ - protected abstract void onTransactionContextCreated(@Nonnull TransactionIdentifier transactionId); + protected abstract void onTransactionContextCreated(@NonNull TransactionIdentifier transactionId); private static TransactionContext createLocalTransactionContext(final LocalTransactionFactory factory, final TransactionProxy parent) { @@ -215,12 +240,12 @@ abstract class AbstractTransactionContextFactory