BUG-5280: Create AbstractProxyHistory class
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / databroker / actors / dds / AbstractClientHistory.java
index f364994e3deb40fd8ee41f2c87a88363840bb173..7608556e6e8a0ad67d7c6a634c80dc2f70a4fa80 100644 (file)
@@ -12,6 +12,7 @@ import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
+import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
 import org.opendaylight.yangtools.concepts.Identifiable;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -33,7 +34,7 @@ abstract class AbstractClientHistory extends LocalAbortable implements Identifia
     private static final AtomicReferenceFieldUpdater<AbstractClientHistory, State> STATE_UPDATER =
             AtomicReferenceFieldUpdater.newUpdater(AbstractClientHistory.class, State.class, "state");
 
-    private final Map<Long, LocalHistoryIdentifier> histories = new ConcurrentHashMap<>();
+    private final Map<Long, AbstractProxyHistory> histories = new ConcurrentHashMap<>();
     private final DistributedDataStoreClientBehavior client;
     private final LocalHistoryIdentifier identifier;
 
@@ -54,19 +55,6 @@ abstract class AbstractClientHistory extends LocalAbortable implements Identifia
         Preconditions.checkState(success, "Race condition detected, state changed from %s to %s", expected, state);
     }
 
-    final LocalHistoryIdentifier getHistoryForCookie(final Long cookie) {
-        LocalHistoryIdentifier ret = histories.get(cookie);
-        if (ret == null) {
-            ret = new LocalHistoryIdentifier(identifier.getClientId(), identifier.getHistoryId(), cookie);
-            final LocalHistoryIdentifier existing = histories.putIfAbsent(cookie, ret);
-            if (existing != null) {
-                ret = existing;
-            }
-        }
-
-        return ret;
-    }
-
     @Override
     public final LocalHistoryIdentifier getIdentifier() {
         return identifier;
@@ -82,6 +70,17 @@ abstract class AbstractClientHistory extends LocalAbortable implements Identifia
         state = State.CLOSED;
     }
 
+    private AbstractProxyHistory createHistoryProxy(final Long shard) {
+        final LocalHistoryIdentifier historyId = new LocalHistoryIdentifier(identifier.getClientId(),
+            identifier.getHistoryId(), shard);
+        return AbstractProxyHistory.create(client, client.resolver().getFutureBackendInfo(shard), historyId);
+    }
+
+    final AbstractProxyTransaction createTransactionProxy(final TransactionIdentifier transactionId, final Long shard) {
+        final AbstractProxyHistory history = histories.computeIfAbsent(shard, this::createHistoryProxy);
+        return history.createTransactionProxy(transactionId);
+    }
+
     /**
      * Callback invoked from {@link ClientTransaction} when a transaction has been sub
      *