Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / persisted / PT.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.TransactionIdentifier;
16 import org.opendaylight.controller.cluster.datastore.persisted.AbstractIdentifiablePayload.SerialForm;
17
18 /**
19  * Serialization proxy for {@link PurgeTransactionPayload}.
20  */
21 final class PT implements SerialForm {
22     @java.io.Serial
23     private static final long serialVersionUID = 1L;
24
25     private TransactionIdentifier identifier;
26     private byte[] bytes;
27
28     @SuppressWarnings("checkstyle:RedundantModifier")
29     public PT() {
30         // For Externalizable
31     }
32
33     PT(final byte[] bytes) {
34         this.bytes = requireNonNull(bytes);
35     }
36
37     @Override
38     public byte[] bytes() {
39         return bytes;
40     }
41
42     @Override
43     public void readExternal(final byte[] newBytes) throws IOException {
44         bytes = requireNonNull(newBytes);
45         identifier = verifyNotNull(TransactionIdentifier.readFrom(ByteStreams.newDataInput(newBytes)));
46     }
47
48     @Override
49     public Object readResolve() {
50         return new PurgeTransactionPayload(identifier, bytes);
51     }
52 }