Add new cds-access-api proxies
[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 static com.google.common.base.Preconditions.checkArgument;
11
12 import akka.actor.ActorRef;
13 import java.io.IOException;
14 import java.io.ObjectInput;
15 import java.io.ObjectOutput;
16 import org.opendaylight.controller.cluster.access.ABIVersion;
17 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
18 import org.opendaylight.yangtools.concepts.WritableObjects;
19
20 /**
21  * A blank transaction request. This is used to provide backfill requests in converted retransmit scenarios, such as
22  * when a initial request to a transaction (such as a {@link ReadTransactionRequest}) is satisfied by the backend
23  * before the need to replay the transaction to a different remote backend.
24  */
25 public final class IncrementTransactionSequenceRequest extends
26         AbstractReadTransactionRequest<IncrementTransactionSequenceRequest> {
27     interface SerialForm extends AbstractReadTransactionRequest.SerialForm<IncrementTransactionSequenceRequest> {
28         @Override
29         default void writeExternal(final ObjectOutput out, final IncrementTransactionSequenceRequest msg)
30                 throws IOException {
31             AbstractReadTransactionRequest.SerialForm.super.writeExternal(out, msg);
32             WritableObjects.writeLong(out, msg.getIncrement());
33         }
34
35         @Override
36         default IncrementTransactionSequenceRequest readExternal(final ObjectInput in,
37                 final TransactionIdentifier target, final long sequence, final ActorRef replyTo,
38                 final boolean snapshotOnly) throws IOException {
39             return new IncrementTransactionSequenceRequest(target, sequence, replyTo, snapshotOnly,
40                 WritableObjects.readLong(in));
41         }
42     }
43
44     @java.io.Serial
45     private static final long serialVersionUID = 1L;
46
47     private final long increment;
48
49     public IncrementTransactionSequenceRequest(final IncrementTransactionSequenceRequest request,
50             final ABIVersion version) {
51         super(request, version);
52         increment = request.increment;
53     }
54
55     public IncrementTransactionSequenceRequest(final TransactionIdentifier identifier, final long sequence,
56             final ActorRef replyTo, final boolean snapshotOnly, final long increment) {
57         super(identifier, sequence, replyTo, snapshotOnly);
58         checkArgument(increment >= 0, "Unexpected increment %s", increment);
59         this.increment = increment;
60     }
61
62     /**
63      * Return the sequence increment beyond this request's sequence.
64      *
65      * @return Sequence increment, guaranteed to be non-negative.
66      */
67     public long getIncrement() {
68         return increment;
69     }
70
71     @Override
72     protected SerialForm externalizableProxy(final ABIVersion version) {
73         return ABIVersion.MAGNESIUM.lt(version) ? new ITSR(this) : new IncrementTransactionSequenceRequestProxyV1(this);
74     }
75
76     @Override
77     protected IncrementTransactionSequenceRequest cloneAsVersion(final ABIVersion targetVersion) {
78         return new IncrementTransactionSequenceRequest(this, targetVersion);
79     }
80 }