Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / persisted / LE.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.raft.persisted;
9
10 import java.io.Externalizable;
11 import java.io.IOException;
12 import java.io.ObjectInput;
13 import java.io.ObjectOutput;
14 import org.opendaylight.controller.cluster.raft.messages.Payload;
15 import org.opendaylight.yangtools.concepts.WritableObjects;
16
17 /**
18  * Serialization proxy for {@link SimpleReplicatedLogEntry}.
19  */
20 final class LE implements Externalizable {
21     @java.io.Serial
22     private static final long serialVersionUID = 1L;
23
24     private long index;
25     private long term;
26     private Payload data;
27
28     @SuppressWarnings("checkstyle:RedundantModifier")
29     public LE() {
30         // For Externalizable
31     }
32
33     // For size estimation only, use full bit size
34     LE(final Void dummy) {
35         index = Long.MIN_VALUE;
36         term = Long.MIN_VALUE;
37         data = null;
38     }
39
40     LE(final SimpleReplicatedLogEntry logEntry) {
41         index = logEntry.getIndex();
42         term = logEntry.getTerm();
43         data = logEntry.getData();
44     }
45
46     @Override
47     public void writeExternal(final ObjectOutput out) throws IOException {
48         WritableObjects.writeLongs(out, index, term);
49         out.writeObject(data);
50     }
51
52     @Override
53     public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
54         final byte hdr = WritableObjects.readLongHeader(in);
55         index = WritableObjects.readFirstLong(in, hdr);
56         term = WritableObjects.readSecondLong(in, hdr);
57         data = (Payload) in.readObject();
58     }
59
60     @java.io.Serial
61     private Object readResolve() {
62         return new SimpleReplicatedLogEntry(index, term, data);
63     }
64 }