Add serialVersionUID fields
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / commands / SkipTransactionsRequestV1.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.collect.ImmutableList;
12 import com.google.common.primitives.UnsignedLong;
13 import java.io.IOException;
14 import java.io.ObjectInput;
15 import java.io.ObjectOutput;
16 import java.io.Serial;
17 import java.util.List;
18 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
19 import org.opendaylight.yangtools.concepts.WritableObjects;
20
21 /**
22  * Externalizable proxy for use with {@link SkipTransactionsRequest}. It implements the initial
23  * (Phosphorus SR1) serialization format.
24  */
25 final class SkipTransactionsRequestV1 extends AbstractTransactionRequestProxy<SkipTransactionsRequest> {
26     @Serial
27     private static final long serialVersionUID = -7493419007644462643L;
28
29     private List<UnsignedLong> others;
30
31     // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to
32     // be able to create instances via reflection.
33     @SuppressWarnings("checkstyle:RedundantModifier")
34     public SkipTransactionsRequestV1() {
35         // For Externalizable
36     }
37
38     SkipTransactionsRequestV1(final SkipTransactionsRequest request) {
39         super(request);
40         others = request.getOthers();
41     }
42
43     @Override
44     public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
45         super.readExternal(in);
46
47         final int size = in.readInt();
48         final var builder = ImmutableList.<UnsignedLong>builderWithExpectedSize(size);
49         int idx;
50         if (size % 2 != 0) {
51             builder.add(UnsignedLong.fromLongBits(WritableObjects.readLong(in)));
52             idx = 1;
53         } else {
54             idx = 0;
55         }
56         for (; idx < size; idx += 2) {
57             final byte hdr = WritableObjects.readLongHeader(in);
58             builder.add(UnsignedLong.fromLongBits(WritableObjects.readFirstLong(in, hdr)));
59             builder.add(UnsignedLong.fromLongBits(WritableObjects.readSecondLong(in, hdr)));
60         }
61         others = builder.build();
62     }
63
64     @Override
65     public void writeExternal(final ObjectOutput out) throws IOException {
66         super.writeExternal(out);
67
68         final int size = others.size();
69         out.writeInt(size);
70
71         int idx;
72         if (size % 2 != 0) {
73             WritableObjects.writeLong(out, others.get(0).longValue());
74             idx = 1;
75         } else {
76             idx = 0;
77         }
78         for (; idx < size; idx += 2) {
79             WritableObjects.writeLongs(out, others.get(idx).longValue(), others.get(idx + 1).longValue());
80         }
81     }
82
83     @Override
84     protected SkipTransactionsRequest createRequest(final TransactionIdentifier target, final long sequence,
85             final ActorRef replyToActor) {
86         return new SkipTransactionsRequest(target, sequence, replyToActor, others);
87     }
88 }