Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / persisted / ST.java
1 /*
2  * Copyright (c) 2022 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.datastore.persisted;
9
10 import static com.google.common.base.Verify.verifyNotNull;
11 import static java.util.Objects.requireNonNull;
12
13 import com.google.common.io.ByteStreams;
14 import java.io.IOException;
15 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
16 import org.opendaylight.controller.cluster.datastore.persisted.AbstractIdentifiablePayload.SerialForm;
17 import org.opendaylight.controller.cluster.datastore.utils.ImmutableUnsignedLongSet;
18
19 /**
20  * Serialization proxy for {@link SkipTransactionsPayload}.
21  */
22 final class ST implements SerialForm {
23     @java.io.Serial
24     private static final long serialVersionUID = 1L;
25
26     private ImmutableUnsignedLongSet transactionIds;
27     private LocalHistoryIdentifier identifier;
28     private byte[] bytes;
29
30     @SuppressWarnings("checkstyle:RedundantModifier")
31     public ST() {
32         // For Externalizable
33     }
34
35     ST(final byte[] bytes) {
36         this.bytes = requireNonNull(bytes);
37     }
38
39     @Override
40     public byte[] bytes() {
41         return bytes;
42     }
43
44     @Override
45     public void readExternal(final byte[] newBytes) throws IOException {
46         bytes = requireNonNull(newBytes);
47
48         final var in = ByteStreams.newDataInput(newBytes);
49         identifier = LocalHistoryIdentifier.readFrom(in);
50         transactionIds = verifyNotNull(ImmutableUnsignedLongSet.readFrom(in));
51     }
52
53     @Override
54     public Object readResolve() {
55         return new SkipTransactionsPayload(identifier, bytes, transactionIds);
56     }
57 }