BUG-5280: move proxy instantiation to AbstractClientHistory 76/44276/4
authorRobert Varga <rovarga@cisco.com>
Thu, 18 Aug 2016 13:15:12 +0000 (15:15 +0200)
committerTom Pantelis <tpanteli@brocade.com>
Wed, 24 Aug 2016 02:07:14 +0000 (02:07 +0000)
Histories should be the synchronization point for accessing
per-cookie proxies. Move instantiation code, making cookie/history
mapping internal to AbstractClientHistory.

Change-Id: I512e93d72b682668790a5dd213112d772143f045
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractClientHistory.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientTransaction.java

index f364994..fda9a16 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;
@@ -54,7 +55,7 @@ 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) {
+    private LocalHistoryIdentifier getHistoryForCookie(final Long cookie) {
         LocalHistoryIdentifier ret = histories.get(cookie);
         if (ret == null) {
             ret = new LocalHistoryIdentifier(identifier.getClientId(), identifier.getHistoryId(), cookie);
@@ -82,6 +83,11 @@ abstract class AbstractClientHistory extends LocalAbortable implements Identifia
         state = State.CLOSED;
     }
 
+    final AbstractProxyTransaction createTransactionProxy(final TransactionIdentifier transactionId, final Long shard) {
+        return AbstractProxyTransaction.create(client, getHistoryForCookie(shard),
+            transactionId.getTransactionId(), client.resolver().getFutureBackendInfo(shard));
+    }
+
     /**
      * Callback invoked from {@link ClientTransaction} when a transaction has been sub
      *
index f5f545a..10d64ed 100644 (file)
@@ -72,18 +72,16 @@ public final class ClientTransaction extends LocalAbortable implements Identifia
         Preconditions.checkState(state == OPEN_STATE, "Transaction %s is closed", transactionId);
     }
 
+    private AbstractProxyTransaction createProxy(final Long shard) {
+        return parent.createTransactionProxy(transactionId, shard);
+    }
+
     private AbstractProxyTransaction ensureProxy(final YangInstanceIdentifier path) {
         checkNotClosed();
 
         final ModuleShardBackendResolver resolver = parent.getClient().resolver();
         final Long shard = resolver.resolveShardForPath(path);
-        AbstractProxyTransaction ret = proxies.get(shard);
-        if (ret == null) {
-            ret = AbstractProxyTransaction.create(parent.getClient(), parent.getHistoryForCookie(shard),
-                transactionId.getTransactionId(), resolver.getFutureBackendInfo(shard));
-            proxies.put(shard, ret);
-        }
-        return ret;
+        return proxies.computeIfAbsent(shard, this::createProxy);
     }
 
     @Override