Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / messages / VR.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 com.google.common.base.Verify.verifyNotNull;
11 import static java.util.Objects.requireNonNull;
12
13 import java.io.Externalizable;
14 import java.io.IOException;
15 import java.io.ObjectInput;
16 import java.io.ObjectOutput;
17 import org.opendaylight.yangtools.concepts.WritableObjects;
18
19 /**
20  * Serialization proxy for {@link RequestVoteReply}.
21  */
22 final class VR implements Externalizable {
23     @java.io.Serial
24     private static final long serialVersionUID = 1L;
25
26     // Flags
27     private static final int VOTE_GRANTED = 0x10;
28
29     private RequestVoteReply requestVoteReply;
30
31     @SuppressWarnings("checkstyle:RedundantModifier")
32     public VR() {
33         // For Externalizable
34     }
35
36     VR(final RequestVoteReply requestVoteReply) {
37         this.requestVoteReply = requireNonNull(requestVoteReply);
38     }
39
40     @Override
41     public void writeExternal(final ObjectOutput out) throws IOException {
42         WritableObjects.writeLong(out, requestVoteReply.getTerm(), requestVoteReply.isVoteGranted() ? VOTE_GRANTED : 0);
43     }
44
45     @Override
46     public void readExternal(final ObjectInput in) throws IOException {
47         final byte hdr = WritableObjects.readLongHeader(in);
48         requestVoteReply = new RequestVoteReply(WritableObjects.readLongBody(in, hdr),
49             (WritableObjects.longHeaderFlags(hdr) & VOTE_GRANTED) != 0);
50     }
51
52     @java.io.Serial
53     private Object readResolve() {
54         return verifyNotNull(requestVoteReply);
55     }
56 }