BUG-8618: add pause/unpause mechanics for tell-based protocol
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / FrontendTransaction.java
index c0249fd00089d1bd48abe9793ddb8564fb937a94..2a4aeaa49b3d04b30b3859d99e75287e4f308ca5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2016, 2017 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -15,6 +15,8 @@ import java.util.Iterator;
 import java.util.Queue;
 import javax.annotation.Nullable;
 import javax.annotation.concurrent.NotThreadSafe;
+import org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceRequest;
+import org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceSuccess;
 import org.opendaylight.controller.cluster.access.commands.OutOfOrderRequestException;
 import org.opendaylight.controller.cluster.access.commands.TransactionRequest;
 import org.opendaylight.controller.cluster.access.commands.TransactionSuccess;
@@ -120,8 +122,17 @@ abstract class FrontendTransaction implements Identifiable<TransactionIdentifier
 
     // Request order has already been checked by caller and replaySequence()
     @SuppressWarnings("checkstyle:IllegalCatch")
-    final @Nullable TransactionSuccess<?> handleRequest(final TransactionRequest<?> request,
-            final RequestEnvelope envelope, final long now) throws RequestException {
+    @Nullable
+    final TransactionSuccess<?> handleRequest(final TransactionRequest<?> request, final RequestEnvelope envelope,
+            final long now) throws RequestException {
+        if (request instanceof IncrementTransactionSequenceRequest) {
+            final IncrementTransactionSequenceRequest incr = (IncrementTransactionSequenceRequest) request;
+            expectedSequence += incr.getIncrement();
+
+            return recordSuccess(incr.getSequence(),
+                    new IncrementTransactionSequenceSuccess(incr.getTarget(), incr.getSequence()));
+        }
+
         if (previousFailure != null) {
             LOG.debug("{}: Rejecting request {} due to previous failure", persistenceId(), request, previousFailure);
             throw previousFailure;
@@ -131,8 +142,10 @@ abstract class FrontendTransaction implements Identifiable<TransactionIdentifier
             return doHandleRequest(request, envelope, now);
         } catch (RuntimeException e) {
             /*
-             * The request failed to process, we should not attempt to ever apply it again. Furthermore we cannot
-             * accept any further requests from this connection, simply because the transaction state is undefined.
+             * The request failed to process, we should not attempt to ever
+             * apply it again. Furthermore we cannot accept any further requests
+             * from this connection, simply because the transaction state is
+             * undefined.
              */
             LOG.debug("{}: Request {} failed to process", persistenceId(), request, e);
             previousFailure = new RuntimeRequestException("Request " + request + " failed to process", e);
@@ -140,9 +153,12 @@ abstract class FrontendTransaction implements Identifiable<TransactionIdentifier
         }
     }
 
-    abstract @Nullable TransactionSuccess<?> doHandleRequest(TransactionRequest<?> request, RequestEnvelope envelope,
+    @Nullable
+    abstract TransactionSuccess<?> doHandleRequest(TransactionRequest<?> request, RequestEnvelope envelope,
             long now) throws RequestException;
 
+    abstract void retire();
+
     private void recordResponse(final long sequence, final Object response) {
         if (replayQueue.isEmpty()) {
             firstReplaySequence = sequence;
@@ -179,5 +195,4 @@ abstract class FrontendTransaction implements Identifiable<TransactionIdentifier
                 .add("lastPurgedSequence", lastPurgedSequence)
                 .toString();
     }
-
 }