Use OptionalLong to track enqueue time 06/83006/5
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 10 Jul 2019 14:07:59 +0000 (16:07 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 10 Jul 2019 15:37:15 +0000 (17:37 +0200)
This prevents the need to box/unbox primitive longs and makes things
generally more convenient.

Change-Id: I6ca394526b09fdd469a9440c9313371e6185c135
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractProxyTransaction.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalReadWriteProxyTransaction.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/RemoteProxyTransaction.java

index 0b9f2b1..1ed1e94 100644 (file)
@@ -22,6 +22,7 @@ import java.util.ArrayDeque;
 import java.util.Deque;
 import java.util.Iterator;
 import java.util.Optional;
+import java.util.OptionalLong;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
 import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
@@ -335,7 +336,7 @@ abstract class AbstractProxyTransaction implements Identifiable<TransactionIdent
         final boolean success = markSealed();
         checkState(success, "Proxy %s was already sealed", getIdentifier());
 
-        if (!sealAndSend(Optional.empty())) {
+        if (!sealAndSend(OptionalLong.empty())) {
             sealSuccessor();
         }
     }
@@ -359,7 +360,7 @@ abstract class AbstractProxyTransaction implements Identifiable<TransactionIdent
     }
 
     private void predecessorSealed() {
-        if (markSealed() && !sealAndSend(Optional.empty())) {
+        if (markSealed() && !sealAndSend(OptionalLong.empty())) {
             sealSuccessor();
         }
     }
@@ -381,7 +382,7 @@ abstract class AbstractProxyTransaction implements Identifiable<TransactionIdent
      * @param enqueuedTicks Enqueue ticks when this is invoked from replay path.
      * @return True if seal operation was successful, false if this proxy has a successor.
      */
-    boolean sealAndSend(final Optional<Long> enqueuedTicks) {
+    boolean sealAndSend(final OptionalLong enqueuedTicks) {
         return sealState();
     }
 
@@ -735,7 +736,7 @@ abstract class AbstractProxyTransaction implements Identifiable<TransactionIdent
                 successor.handleReplayedRemoteRequest(optState.get(), null, enqueuedTicks);
             }
             if (successor.markSealed()) {
-                successor.sealAndSend(Optional.of(enqueuedTicks));
+                successor.sealAndSend(OptionalLong.of(enqueuedTicks));
             }
         }
     }
@@ -853,7 +854,7 @@ abstract class AbstractProxyTransaction implements Identifiable<TransactionIdent
     abstract void handleReplayedRemoteRequest(TransactionRequest<?> request,
             @Nullable Consumer<Response<?, ?>> callback, long enqueuedTicks);
 
-    private static IllegalStateException unhandledResponseException(Response<?, ?> resp) {
+    private static IllegalStateException unhandledResponseException(final Response<?, ?> resp) {
         return new IllegalStateException("Unhandled response " + resp.getClass());
     }
 
index c32297f..9fa8ac7 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.controller.cluster.databroker.actors.dds;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Verify;
 import java.util.Optional;
+import java.util.OptionalLong;
 import java.util.function.BiConsumer;
 import java.util.function.Consumer;
 import java.util.function.Supplier;
@@ -189,7 +190,7 @@ final class LocalReadWriteProxyTransaction extends LocalProxyTransaction {
     }
 
     @Override
-    boolean sealAndSend(final Optional<Long> enqueuedTicks) {
+    boolean sealAndSend(final OptionalLong enqueuedTicks) {
         sealModification();
         return super.sealAndSend(enqueuedTicks);
     }
index 8bdf359..d0d7946 100644 (file)
@@ -13,6 +13,7 @@ import com.google.common.util.concurrent.FluentFuture;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.SettableFuture;
 import java.util.Optional;
+import java.util.OptionalLong;
 import java.util.function.Consumer;
 import org.opendaylight.controller.cluster.access.client.RequestTimeoutException;
 import org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest;
@@ -100,17 +101,17 @@ final class RemoteProxyTransaction extends AbstractProxyTransaction {
 
     @Override
     void doDelete(final YangInstanceIdentifier path) {
-        appendModification(new TransactionDelete(path), Optional.empty());
+        appendModification(new TransactionDelete(path), OptionalLong.empty());
     }
 
     @Override
     void doMerge(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
-        appendModification(new TransactionMerge(path, data), Optional.empty());
+        appendModification(new TransactionMerge(path, data), OptionalLong.empty());
     }
 
     @Override
     void doWrite(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
-        appendModification(new TransactionWrite(path, data), Optional.empty());
+        appendModification(new TransactionWrite(path, data), OptionalLong.empty());
     }
 
     private <T> FluentFuture<T> sendReadRequest(final AbstractReadTransactionRequest<?> request,
@@ -150,35 +151,35 @@ final class RemoteProxyTransaction extends AbstractProxyTransaction {
     }
 
     private void ensureFlushedBuider() {
-        ensureFlushedBuider(Optional.empty());
+        ensureFlushedBuider(OptionalLong.empty());
     }
 
-    private void ensureFlushedBuider(final Optional<Long> enqueuedTicks) {
+    private void ensureFlushedBuider(final OptionalLong enqueuedTicks) {
         if (builderBusy) {
             flushBuilder(enqueuedTicks);
         }
     }
 
-    private void flushBuilder(final Optional<Long> enqueuedTicks) {
+    private void flushBuilder(final OptionalLong enqueuedTicks) {
         final ModifyTransactionRequest request = builder.build();
         builderBusy = false;
 
         sendModification(request, enqueuedTicks);
     }
 
-    private void sendModification(final TransactionRequest<?> request, final Optional<Long> enqueuedTicks) {
+    private void sendModification(final TransactionRequest<?> request, final OptionalLong enqueuedTicks) {
         if (enqueuedTicks.isPresent()) {
-            enqueueRequest(request, response -> completeModify(request, response), enqueuedTicks.get().longValue());
+            enqueueRequest(request, response -> completeModify(request, response), enqueuedTicks.getAsLong());
         } else {
             sendRequest(request, response -> completeModify(request, response));
         }
     }
 
     private void appendModification(final TransactionModification modification) {
-        appendModification(modification, Optional.empty());
+        appendModification(modification, OptionalLong.empty());
     }
 
-    private void appendModification(final TransactionModification modification, final Optional<Long> enqueuedTicks) {
+    private void appendModification(final TransactionModification modification, final OptionalLong enqueuedTicks) {
         if (operationFailure == null) {
             ensureInitializedBuilder();
 
@@ -275,7 +276,7 @@ final class RemoteProxyTransaction extends AbstractProxyTransaction {
     }
 
     @Override
-    boolean sealAndSend(final Optional<Long> enqueuedTicks) {
+    boolean sealAndSend(final OptionalLong enqueuedTicks) {
         if (sendReadyOnSeal) {
             ensureInitializedBuilder();
             builder.setReady();
@@ -410,7 +411,7 @@ final class RemoteProxyTransaction extends AbstractProxyTransaction {
     private void replayLocalCommitRequest(final CommitLocalTransactionRequest request,
             final Consumer<Response<?, ?>> callback, final long enqueuedTicks) {
         final DataTreeModification mod = request.getModification();
-        final Optional<Long> optTicks = Optional.of(Long.valueOf(enqueuedTicks));
+        final OptionalLong optTicks = OptionalLong.of(enqueuedTicks);
 
         mod.applyToCursor(new AbstractDataTreeModificationCursor() {
             @Override
@@ -436,7 +437,7 @@ final class RemoteProxyTransaction extends AbstractProxyTransaction {
     void handleReplayedRemoteRequest(final TransactionRequest<?> request, final Consumer<Response<?, ?>> callback,
             final long enqueuedTicks) {
         final Consumer<Response<?, ?>> cb = callback != null ? callback : resp -> { /* NOOP */ };
-        final Optional<Long> optTicks = Optional.of(Long.valueOf(enqueuedTicks));
+        final OptionalLong optTicks = OptionalLong.of(enqueuedTicks);
 
         if (request instanceof ModifyTransactionRequest) {
             handleReplayedModifyTransactionRequest(enqueuedTicks, cb, (ModifyTransactionRequest) request);

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.