Do not leak DataTree from backend actor
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / AbstractTransactionContextFactory.java
index f5a156f8687ae674748de3eab01e2600ff766db8..6d573dedf53223b34c8c2ca525bea3435d9bc812 100644 (file)
@@ -7,24 +7,25 @@
  */
 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.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.DataTree;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.ReadOnlyDataTree;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import scala.concurrent.Future;
@@ -42,20 +43,19 @@ abstract class AbstractTransactionContextFactory<F extends LocalTransactionFacto
 
     private final ConcurrentMap<String, F> 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() {
@@ -116,7 +116,7 @@ abstract class AbstractTransactionContextFactory<F extends LocalTransactionFacto
     final TransactionContextWrapper newTransactionContextWrapper(final TransactionProxy parent,
             final String shardName) {
         final TransactionContextWrapper transactionContextWrapper =
-                new TransactionContextWrapper(parent.getIdentifier(), actorContext, shardName);
+                new TransactionContextWrapper(parent.getIdentifier(), actorUtils, shardName);
 
         Future<PrimaryShardInfo> findPrimaryFuture = findPrimaryShard(shardName, parent.getIdentifier());
         if (findPrimaryFuture.isCompleted()) {
@@ -136,14 +136,14 @@ abstract class AbstractTransactionContextFactory<F extends LocalTransactionFacto
                         onFindPrimaryShardFailure(failure, parent, shardName, transactionContextWrapper);
                     }
                 }
-            }, actorContext.getClientDispatcher());
+            }, actorUtils.getClientDispatcher());
         }
 
         return transactionContextWrapper;
     }
 
     private void updateShardInfo(final String shardName, final PrimaryShardInfo primaryShardInfo) {
-        final Optional<DataTree> maybeDataTree = primaryShardInfo.getLocalShardDataTree();
+        final Optional<ReadOnlyDataTree> maybeDataTree = primaryShardInfo.getLocalShardDataTree();
         if (maybeDataTree.isPresent()) {
             if (!knownLocal.containsKey(shardName)) {
                 LOG.debug("Shard {} resolved to local data tree - adding local factory", shardName);
@@ -177,8 +177,8 @@ abstract class AbstractTransactionContextFactory<F extends LocalTransactionFacto
      * @param shardName Shard name
      * @return Future containing shard information.
      */
-    protected abstract Future<PrimaryShardInfo> findPrimaryShard(@Nonnull String shardName,
-            @Nonnull TransactionIdentifier txId);
+    protected abstract Future<PrimaryShardInfo> findPrimaryShard(@NonNull String shardName,
+            @NonNull TransactionIdentifier txId);
 
     /**
      * Create local transaction factory for specified shard, backed by specified shard leader
@@ -190,22 +190,22 @@ abstract class AbstractTransactionContextFactory<F extends LocalTransactionFacto
      *                 read-only manner.
      * @return Transaction factory for local use.
      */
-    protected abstract F factoryForShard(String shardName, ActorSelection shardLeader, DataTree dataTree);
+    protected abstract F factoryForShard(String shardName, ActorSelection shardLeader, ReadOnlyDataTree dataTree);
 
     /**
      * Callback invoked from child transactions to push any futures, which need to
      * be waited for before the next transaction is allocated.
      * @param cohortFutures Collection of futures
      */
-    protected abstract <T> void onTransactionReady(@Nonnull TransactionIdentifier transaction,
-            @Nonnull Collection<Future<T>> cohortFutures);
+    protected abstract <T> void onTransactionReady(@NonNull TransactionIdentifier transaction,
+            @NonNull Collection<Future<T>> 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) {