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