2 * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.access.commands;
10 import akka.actor.ActorRef;
11 import com.google.common.base.MoreObjects.ToStringHelper;
12 import com.google.common.collect.ImmutableList;
13 import com.google.common.primitives.UnsignedLong;
14 import java.io.IOException;
15 import java.io.ObjectInput;
16 import java.io.ObjectOutput;
17 import java.util.Collection;
18 import java.util.List;
19 import org.eclipse.jdt.annotation.NonNull;
20 import org.opendaylight.controller.cluster.access.ABIVersion;
21 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
22 import org.opendaylight.yangtools.concepts.WritableObjects;
25 * Request to skip a number of {@link TransactionIdentifier}s within a {code local history}. This request is essentially
26 * equivalent to {@link TransactionPurgeRequest} for {@link #getTarget()}, but also carries additional sibling
27 * {@link TransactionIdentifier}s in {@link #getOthers()}.
30 * This request is sent by the frontend to inform the backend that a set of {@link TransactionIdentifier}s are
31 * explicitly retired and are guaranteed to never be used by the frontend.
33 public final class SkipTransactionsRequest extends TransactionRequest<SkipTransactionsRequest> {
34 interface SerialForm extends TransactionRequest.SerialForm<SkipTransactionsRequest> {
36 default SkipTransactionsRequest readExternal(final ObjectInput in, final TransactionIdentifier target,
37 final long sequence, final ActorRef replyTo) throws IOException {
38 final int size = in.readInt();
39 final var builder = ImmutableList.<UnsignedLong>builderWithExpectedSize(size);
42 builder.add(UnsignedLong.fromLongBits(WritableObjects.readLong(in)));
47 for (; idx < size; idx += 2) {
48 final byte hdr = WritableObjects.readLongHeader(in);
49 builder.add(UnsignedLong.fromLongBits(WritableObjects.readFirstLong(in, hdr)));
50 builder.add(UnsignedLong.fromLongBits(WritableObjects.readSecondLong(in, hdr)));
53 return new SkipTransactionsRequest(target, sequence, replyTo, builder.build());
57 default void writeExternal(final ObjectOutput out, final SkipTransactionsRequest msg) throws IOException {
58 TransactionRequest.SerialForm.super.writeExternal(out, msg);
60 final var others = msg.others;
61 final int size = others.size();
66 WritableObjects.writeLong(out, others.get(0).longValue());
71 for (; idx < size; idx += 2) {
72 WritableObjects.writeLongs(out, others.get(idx).longValue(), others.get(idx + 1).longValue());
78 private static final long serialVersionUID = 1L;
80 // Note: UnsignedLong is arbitrary, yang.common.Uint64 would work just as well, we really want an immutable
81 // List<long>, though.
82 private final @NonNull ImmutableList<UnsignedLong> others;
84 public SkipTransactionsRequest(final TransactionIdentifier target, final long sequence,
85 final ActorRef replyTo, final Collection<UnsignedLong> others) {
86 super(target, sequence, replyTo);
87 this.others = ImmutableList.copyOf(others);
90 private SkipTransactionsRequest(final SkipTransactionsRequest request, final ABIVersion version) {
91 super(request, version);
92 others = request.others;
96 * Return this {@link #getTarget()}s sibling {@link TransactionIdentifier}s.
98 * @return Siblings values of {@link TransactionIdentifier#getTransactionId()}
100 public List<UnsignedLong> getOthers() {
105 protected SerialForm externalizableProxy(final ABIVersion version) {
106 return new STR(this);
110 protected SkipTransactionsRequest cloneAsVersion(final ABIVersion version) {
111 return new SkipTransactionsRequest(this, version);
115 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
116 final var helper = super.addToStringAttributes(toStringHelper);
117 if (!others.isEmpty()) {
118 helper.add("others", others);