Track skipped transactions
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / commands / SkipTransactionsRequest.java
1 /*
2  * Copyright (c) 2021 PANTHEON.tech, 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.annotations.Beta;
12 import com.google.common.base.MoreObjects.ToStringHelper;
13 import com.google.common.collect.ImmutableList;
14 import com.google.common.primitives.UnsignedLong;
15 import java.util.Collection;
16 import java.util.List;
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.opendaylight.controller.cluster.access.ABIVersion;
19 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
20
21 /**
22  * Request to skip a number of {@link TransactionIdentifier}s within a {code local history}. This request is essentially
23  * equivalent to {@link TransactionPurgeRequest} for {@link #getTarget()}, but also carries additional sibling
24  * {@link TransactionIdentifier}s in {@link #getOthers()}.
25  *
26  * <p>
27  * This request is sent by the frontend to inform the backend that a set of {@link TransactionIdentifier}s are
28  * explicitly retired and are guaranteed to never be used by the frontend.
29  */
30 @Beta
31 public final class SkipTransactionsRequest extends TransactionRequest<SkipTransactionsRequest> {
32     private static final long serialVersionUID = 1L;
33
34     // Note: UnsignedLong is arbitrary, yang.common.Uint64 would work just as well, we really want an immutable
35     //       List<long>, though.
36     private final @NonNull ImmutableList<UnsignedLong> others;
37
38     public SkipTransactionsRequest(final TransactionIdentifier target, final long sequence,
39             final ActorRef replyTo, final Collection<UnsignedLong> others) {
40         super(target, sequence, replyTo);
41         this.others = ImmutableList.copyOf(others);
42     }
43
44     /**
45      * Return this {@link #getTarget()}s sibling {@link TransactionIdentifier}s.
46      *
47      * @return Siblings values of {@link TransactionIdentifier#getTransactionId()}
48      */
49     public List<UnsignedLong> getOthers() {
50         return others;
51     }
52
53     @Override
54     protected SkipTransactionsRequestV1 externalizableProxy(final ABIVersion version) {
55         return new SkipTransactionsRequestV1(this);
56     }
57
58     @Override
59     protected SkipTransactionsRequest cloneAsVersion(final ABIVersion version) {
60         return this;
61     }
62
63     @Override
64     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
65         final var helper = super.addToStringAttributes(toStringHelper);
66         if (!others.isEmpty()) {
67             helper.add("others", others);
68         }
69         return helper;
70     }
71 }