*/
package org.opendaylight.controller.cluster.raft.behaviors;
-import com.google.common.base.Throwables;
import com.google.common.io.ByteSource;
import java.io.IOException;
import java.io.InputStream;
private long snapshotSize;
private InputStream snapshotInputStream;
- LeaderInstallSnapshotState(int snapshotChunkSize, String logName) {
+ LeaderInstallSnapshotState(final int snapshotChunkSize, final String logName) {
this.snapshotChunkSize = snapshotChunkSize;
this.logName = logName;
}
- void setSnapshotBytes(ByteSource snapshotBytes) throws IOException {
+ void setSnapshotBytes(final ByteSource snapshotBytes) throws IOException {
if (this.snapshotBytes != null) {
return;
}
boolean canSendNextChunk() {
// we only send a false if a chunk is sent but we have not received a reply yet
- return snapshotBytes != null && replyReceivedForOffset == offset;
+ return snapshotBytes != null && (nextChunkHashCode == INITIAL_LAST_CHUNK_HASH_CODE
+ || replyReceivedForOffset == offset);
}
- boolean isLastChunk(int index) {
+ boolean isLastChunk(final int index) {
return totalChunks == index;
}
- void markSendStatus(boolean success) {
+ void markSendStatus(final boolean success) {
if (success) {
// if the chunk sent was successful
replyReceivedForOffset = offset;
int numRead = snapshotInputStream.read(nextChunk);
if (numRead != size) {
throw new IOException(String.format(
- "The # of bytes read from the imput stream, %d, does not match the expected # %d", numRead, size));
+ "The # of bytes read from the input stream, %d, does not match the expected # %d", numRead, size));
}
nextChunkHashCode = Arrays.hashCode(nextChunk);
try {
snapshotInputStream = snapshotBytes.openStream();
} catch (IOException e) {
- throw Throwables.propagate(e);
+ throw new RuntimeException(e);
}
}