* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.controller.cluster.raft.messages;
import com.google.common.annotations.VisibleForTesting;
/**
* Reply for the AppendEntries message.
*/
-public class AppendEntriesReply extends AbstractRaftRPC {
+public final class AppendEntriesReply extends AbstractRaftRPC {
+ @java.io.Serial
private static final long serialVersionUID = -7487547356392536683L;
// true if follower contained entry matching
private final short recipientRaftVersion;
@VisibleForTesting
- public AppendEntriesReply(String followerId, long term, boolean success, long logLastIndex, long logLastTerm,
- short payloadVersion) {
+ public AppendEntriesReply(final String followerId, final long term, final boolean success, final long logLastIndex,
+ final long logLastTerm, final short payloadVersion) {
this(followerId, term, success, logLastIndex, logLastTerm, payloadVersion, false, false,
RaftVersions.CURRENT_VERSION);
}
- public AppendEntriesReply(String followerId, long term, boolean success, long logLastIndex, long logLastTerm,
- short payloadVersion, boolean forceInstallSnapshot, boolean needsLeaderAddress,
- short recipientRaftVersion) {
+ public AppendEntriesReply(final String followerId, final long term, final boolean success, final long logLastIndex,
+ final long logLastTerm, final short payloadVersion, final boolean forceInstallSnapshot,
+ final boolean needsLeaderAddress, final short recipientRaftVersion) {
this(followerId, term, success, logLastIndex, logLastTerm, payloadVersion, forceInstallSnapshot,
needsLeaderAddress, RaftVersions.CURRENT_VERSION, recipientRaftVersion);
-
}
- private AppendEntriesReply(String followerId, long term, boolean success, long logLastIndex, long logLastTerm,
- short payloadVersion, boolean forceInstallSnapshot, boolean needsLeaderAddress, short raftVersion,
- short recipientRaftVersion) {
+ AppendEntriesReply(final String followerId, final long term, final boolean success, final long logLastIndex,
+ final long logLastTerm, final short payloadVersion, final boolean forceInstallSnapshot,
+ final boolean needsLeaderAddress, final short raftVersion, final short recipientRaftVersion) {
super(term);
this.followerId = followerId;
this.success = success;
+ ", recipientRaftVersion=" + recipientRaftVersion + "]";
}
- private Object writeReplace() {
- return recipientRaftVersion >= RaftVersions.FLUORINE_VERSION ? new Proxy2(this) : new Proxy(this);
+ @Override
+ Object writeReplace() {
+ return recipientRaftVersion <= RaftVersions.FLUORINE_VERSION ? new Proxy2(this) : new AR(this);
}
/**
* Fluorine version that adds the needsLeaderAddress flag.
*/
private static class Proxy2 implements Externalizable {
+ @java.io.Serial
private static final long serialVersionUID = 1L;
private AppendEntriesReply appendEntriesReply;
public Proxy2() {
}
- Proxy2(AppendEntriesReply appendEntriesReply) {
+ Proxy2(final AppendEntriesReply appendEntriesReply) {
this.appendEntriesReply = appendEntriesReply;
}
@Override
- public void writeExternal(ObjectOutput out) throws IOException {
+ public void writeExternal(final ObjectOutput out) throws IOException {
out.writeShort(appendEntriesReply.raftVersion);
out.writeLong(appendEntriesReply.getTerm());
out.writeObject(appendEntriesReply.followerId);
}
@Override
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
short raftVersion = in.readShort();
long term = in.readLong();
String followerId = (String) in.readObject();
RaftVersions.CURRENT_VERSION);
}
- private Object readResolve() {
- return appendEntriesReply;
- }
- }
-
- /**
- * Pre-Fluorine version.
- */
- @Deprecated
- private static class Proxy implements Externalizable {
- private static final long serialVersionUID = 1L;
-
- private AppendEntriesReply appendEntriesReply;
-
- // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
- // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
- @SuppressWarnings("checkstyle:RedundantModifier")
- public Proxy() {
- }
-
- Proxy(AppendEntriesReply appendEntriesReply) {
- this.appendEntriesReply = appendEntriesReply;
- }
-
- @Override
- public void writeExternal(ObjectOutput out) throws IOException {
- out.writeShort(appendEntriesReply.raftVersion);
- out.writeLong(appendEntriesReply.getTerm());
- out.writeObject(appendEntriesReply.followerId);
- out.writeBoolean(appendEntriesReply.success);
- out.writeLong(appendEntriesReply.logLastIndex);
- out.writeLong(appendEntriesReply.logLastTerm);
- out.writeShort(appendEntriesReply.payloadVersion);
- out.writeBoolean(appendEntriesReply.forceInstallSnapshot);
- }
-
- @Override
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- short raftVersion = in.readShort();
- long term = in.readLong();
- String followerId = (String) in.readObject();
- boolean success = in.readBoolean();
- long logLastIndex = in.readLong();
- long logLastTerm = in.readLong();
- short payloadVersion = in.readShort();
- boolean forceInstallSnapshot = in.readBoolean();
-
- appendEntriesReply = new AppendEntriesReply(followerId, term, success, logLastIndex, logLastTerm,
- payloadVersion, forceInstallSnapshot, false, raftVersion, RaftVersions.CURRENT_VERSION);
- }
-
+ @java.io.Serial
private Object readResolve() {
return appendEntriesReply;
}