Fix remaining CS warnings in sal-distributed-datastore
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / databroker / actors / dds / ClientTransaction.java
index f5f545a48e85af1c6faa255ee031b08934d1dcdc..0a1c8be2471102db655b80359f63ebb5faa2cfd2 100644 (file)
@@ -27,22 +27,28 @@ import org.slf4j.LoggerFactory;
 /**
  * Client-side view of a free-standing transaction.
  *
+ * <p>
  * This interface is used by the world outside of the actor system and in the actor system it is manifested via
  * its client actor. That requires some state transfer with {@link DistributedDataStoreClientBehavior}. In order to
  * reduce request latency, all messages are carbon-copied (and enqueued first) to the client actor.
  *
+ * <p>
  * It is internally composed of multiple {@link RemoteProxyTransaction}s, each responsible for a component shard.
  *
+ * <p>
  * Implementation is quite a bit complex, and involves cooperation with {@link AbstractClientHistory} for tracking
  * gaps in transaction identifiers seen by backends.
  *
+ * <p>
  * These gaps need to be accounted for in the transaction setup message sent to a particular backend, so it can verify
  * that the requested transaction is in-sequence. This is critical in ensuring that transactions (which are independent
  * entities from message queueing perspective) do not get reodered -- thus allowing multiple in-flight transactions.
  *
+ * <p>
  * Alternative would be to force visibility by sending an abort request to all potential backends, but that would mean
  * that even empty transactions increase load on all shards -- which would be a scalability issue.
  *
+ * <p>
  * Yet another alternative would be to introduce inter-transaction dependencies to the queueing layer in client actor,
  * but that would require additional indirection and complexity.
  *
@@ -62,8 +68,7 @@ public final class ClientTransaction extends LocalAbortable implements Identifia
 
     private volatile int state = OPEN_STATE;
 
-    ClientTransaction(final DistributedDataStoreClientBehavior client, final AbstractClientHistory parent,
-        final TransactionIdentifier transactionId) {
+    ClientTransaction(final AbstractClientHistory parent, final TransactionIdentifier transactionId) {
         this.transactionId = Preconditions.checkNotNull(transactionId);
         this.parent = Preconditions.checkNotNull(parent);
     }
@@ -72,18 +77,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