Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / messages / RV.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.messages;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.io.Externalizable;
13 import java.io.IOException;
14 import java.io.ObjectInput;
15 import java.io.ObjectOutput;
16 import org.opendaylight.yangtools.concepts.WritableObjects;
17
18 /**
19  * Serialization proxy for {@link RequestVote}.
20  */
21 final class RV implements Externalizable {
22     @java.io.Serial
23     private static final long serialVersionUID = 1L;
24
25     private RequestVote requestVote;
26
27     @SuppressWarnings("checkstyle:RedundantModifier")
28     public RV() {
29         // For Externalizable
30     }
31
32     RV(final RequestVote requestVote) {
33         this.requestVote = requireNonNull(requestVote);
34     }
35
36     @Override
37     public void writeExternal(final ObjectOutput out) throws IOException {
38         WritableObjects.writeLong(out, requestVote.getTerm());
39         out.writeObject(requestVote.getCandidateId());
40         WritableObjects.writeLongs(out, requestVote.getLastLogIndex(), requestVote.getLastLogTerm());
41     }
42
43     @Override
44     public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
45         long term = WritableObjects.readLong(in);
46         String candidateId = (String) in.readObject();
47
48         final byte hdr = WritableObjects.readLongHeader(in);
49         long lastLogIndex = WritableObjects.readFirstLong(in, hdr);
50         long lastLogTerm = WritableObjects.readSecondLong(in, hdr);
51
52         requestVote = new RequestVote(term, candidateId, lastLogIndex, lastLogTerm);
53     }
54
55     @java.io.Serial
56     private Object readResolve() {
57         return requestVote;
58     }
59 }