Annotate AbstractRaftRPC with java.io.Serial
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / messages / RequestVoteReply.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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 java.io.Externalizable;
11 import java.io.IOException;
12 import java.io.ObjectInput;
13 import java.io.ObjectOutput;
14
15 public final class RequestVoteReply extends AbstractRaftRPC {
16     @java.io.Serial
17     private static final long serialVersionUID = 8427899326488775660L;
18
19     // true means candidate received vote
20     private final boolean voteGranted;
21
22     public RequestVoteReply(final long term, final boolean voteGranted) {
23         super(term);
24         this.voteGranted = voteGranted;
25     }
26
27     public boolean isVoteGranted() {
28         return voteGranted;
29     }
30
31     @Override
32     public String toString() {
33         return "RequestVoteReply [term=" + getTerm() + ", voteGranted=" + voteGranted + "]";
34     }
35
36     @Override
37     Object writeReplace() {
38         return new VR(this);
39     }
40
41     @Deprecated(since = "7.0.0", forRemoval = true)
42     private static class Proxy implements Externalizable {
43         @java.io.Serial
44         private static final long serialVersionUID = 1L;
45
46         private RequestVoteReply requestVoteReply;
47
48         // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
49         // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
50         @SuppressWarnings("checkstyle:RedundantModifier")
51         public Proxy() {
52         }
53
54         @Override
55         public void writeExternal(final ObjectOutput out) {
56             throw new UnsupportedOperationException();
57         }
58
59         @Override
60         public void readExternal(final ObjectInput in) throws IOException {
61             long term = in.readLong();
62             boolean voteGranted = in.readBoolean();
63
64             requestVoteReply = new RequestVoteReply(term, voteGranted);
65         }
66
67         @java.io.Serial
68         private Object readResolve() {
69             return requestVoteReply;
70         }
71     }
72 }