X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fraft%2Fmessages%2FInstallSnapshot.java;h=b64e902f3ff9f93e782c4114e6e690bbef971b0a;hb=bfe4439155b27fbf9ae300252420c8a81fcbdb80;hp=5b6f030431e217016f7156b3c56172ba9e09fae1;hpb=bad1f8b8f3c1780cd37ec8a817ef4b0f23901654;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/messages/InstallSnapshot.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/messages/InstallSnapshot.java index 5b6f030431..b64e902f3f 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/messages/InstallSnapshot.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/messages/InstallSnapshot.java @@ -9,12 +9,16 @@ package org.opendaylight.controller.cluster.raft.messages; import com.google.common.base.Optional; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload; +/** + * Message sent from a leader to install a snapshot chunk on a follower. + */ public class InstallSnapshot extends AbstractRaftRPC { private static final long serialVersionUID = 1L; @@ -27,8 +31,12 @@ public class InstallSnapshot extends AbstractRaftRPC { private final Optional lastChunkHashCode; private final Optional serverConfig; + @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "Stores a reference to an externally mutable byte[] " + + "object but this is OK since this class is merely a DTO and does not process byte[] internally. " + + "Also it would be inefficient to create a copy as the byte[] could be large.") public InstallSnapshot(long term, String leaderId, long lastIncludedIndex, long lastIncludedTerm, byte[] data, - int chunkIndex, int totalChunks, Optional lastChunkHashCode, Optional serverConfig) { + int chunkIndex, int totalChunks, Optional lastChunkHashCode, + Optional serverConfig) { super(term); this.leaderId = leaderId; this.lastIncludedIndex = lastIncludedIndex; @@ -58,6 +66,9 @@ public class InstallSnapshot extends AbstractRaftRPC { return lastIncludedTerm; } + @SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "Exposes a mutable object stored in a field but " + + "this is OK since this class is merely a DTO and does not process the byte[] internally. " + + "Also it would be inefficient to create a return copy as the byte[] could be large.") public byte[] getData() { return data; } @@ -79,7 +90,7 @@ public class InstallSnapshot extends AbstractRaftRPC { } - public Object toSerializable(short version) { + public Object toSerializable(short version) { return this; } @@ -100,6 +111,9 @@ public class InstallSnapshot extends AbstractRaftRPC { private InstallSnapshot installSnapshot; + // 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() { } @@ -117,12 +131,12 @@ public class InstallSnapshot extends AbstractRaftRPC { out.writeInt(installSnapshot.totalChunks); out.writeByte(installSnapshot.lastChunkHashCode.isPresent() ? 1 : 0); - if(installSnapshot.lastChunkHashCode.isPresent()) { + if (installSnapshot.lastChunkHashCode.isPresent()) { out.writeInt(installSnapshot.lastChunkHashCode.get().intValue()); } out.writeByte(installSnapshot.serverConfig.isPresent() ? 1 : 0); - if(installSnapshot.serverConfig.isPresent()) { + if (installSnapshot.serverConfig.isPresent()) { out.writeObject(installSnapshot.serverConfig.get()); } @@ -140,13 +154,13 @@ public class InstallSnapshot extends AbstractRaftRPC { Optional lastChunkHashCode = Optional.absent(); boolean chunkHashCodePresent = in.readByte() == 1; - if(chunkHashCodePresent) { + if (chunkHashCodePresent) { lastChunkHashCode = Optional.of(in.readInt()); } Optional serverConfig = Optional.absent(); boolean serverConfigPresent = in.readByte() == 1; - if(serverConfigPresent) { + if (serverConfigPresent) { serverConfig = Optional.of((ServerConfigurationPayload)in.readObject()); }