BUG-8402: fix sequencing with read/exists requests
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / commands / IncrementTransactionSequenceRequest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.access.commands;
9
10 import akka.actor.ActorRef;
11 import com.google.common.base.Preconditions;
12 import org.opendaylight.controller.cluster.access.ABIVersion;
13 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
14
15 /**
16  * A blank transaction request. This is used to provide backfill requests in converted retransmit scenarios, such as
17  * when a initial request to a transaction (such as a {@link ReadTransactionRequest}) is satisfied by the backend
18  * before the need to replay the transaction to a different remote backend.
19  *
20  * @author Robert Varga
21  */
22 public final class IncrementTransactionSequenceRequest extends TransactionRequest<IncrementTransactionSequenceRequest> {
23     private static final long serialVersionUID = 1L;
24
25     private final long increment;
26
27     public IncrementTransactionSequenceRequest(final TransactionIdentifier identifier, final long sequence,
28             final ActorRef replyTo, final long increment) {
29         super(identifier, sequence, replyTo);
30         Preconditions.checkArgument(increment >= 0);
31         this.increment = increment;
32     }
33
34     @Override
35     protected IncrementTransactionSequenceRequestProxyV1 externalizableProxy(final ABIVersion version) {
36         return new IncrementTransactionSequenceRequestProxyV1(this);
37     }
38
39     @Override
40     protected IncrementTransactionSequenceRequest cloneAsVersion(final ABIVersion targetVersion) {
41         return this;
42     }
43
44     /**
45      * Return the sequence increment beyond this request's sequence.
46      *
47      * @return Sequence increment, guaranteed to be non-negative.
48      */
49     public long getIncrement() {
50         return increment;
51     }
52 }