2 * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.raft.messages;
10 import static java.util.Objects.requireNonNull;
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;
19 * Serialization proxy for {@link RequestVote}.
21 final class RV implements Externalizable {
23 private static final long serialVersionUID = 1L;
25 private RequestVote requestVote;
27 @SuppressWarnings("checkstyle:RedundantModifier")
32 RV(final RequestVote requestVote) {
33 this.requestVote = requireNonNull(requestVote);
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());
44 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
45 long term = WritableObjects.readLong(in);
46 String candidateId = (String) in.readObject();
48 final byte hdr = WritableObjects.readLongHeader(in);
49 long lastLogIndex = WritableObjects.readFirstLong(in, hdr);
50 long lastLogTerm = WritableObjects.readSecondLong(in, hdr);
52 requestVote = new RequestVote(term, candidateId, lastLogIndex, lastLogTerm);
56 private Object readResolve() {