2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.cluster.raft.messages;
11 import java.io.Externalizable;
12 import java.io.IOException;
13 import java.io.ObjectInput;
14 import java.io.ObjectOutput;
16 public class InstallSnapshotReply extends AbstractRaftRPC {
17 private static final long serialVersionUID = 642227896390779503L;
19 // The followerId - this will be used to figure out which follower is
21 private final String followerId;
22 private final int chunkIndex;
23 private final boolean success;
25 public InstallSnapshotReply(long term, String followerId, int chunkIndex, boolean success) {
27 this.followerId = followerId;
28 this.chunkIndex = chunkIndex;
29 this.success = success;
32 public String getFollowerId() {
36 public int getChunkIndex() {
40 public boolean isSuccess() {
45 public String toString() {
46 StringBuilder builder = new StringBuilder();
47 builder.append("InstallSnapshotReply [term=").append(getTerm()).append(", followerId=").append(followerId)
48 .append(", chunkIndex=").append(chunkIndex).append(", success=").append(success).append("]");
49 return builder.toString();
52 private Object writeReplace() {
53 return new Proxy(this);
56 private static class Proxy implements Externalizable {
57 private static final long serialVersionUID = 1L;
59 private InstallSnapshotReply installSnapshotReply;
61 // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
62 // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
63 @SuppressWarnings("checkstyle:RedundantModifier")
67 Proxy(InstallSnapshotReply installSnapshotReply) {
68 this.installSnapshotReply = installSnapshotReply;
72 public void writeExternal(ObjectOutput out) throws IOException {
73 out.writeLong(installSnapshotReply.getTerm());
74 out.writeObject(installSnapshotReply.followerId);
75 out.writeInt(installSnapshotReply.chunkIndex);
76 out.writeBoolean(installSnapshotReply.success);
80 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
81 long term = in.readLong();
82 String followerId = (String) in.readObject();
83 int chunkIndex = in.readInt();
84 boolean success = in.readBoolean();
86 installSnapshotReply = new InstallSnapshotReply(term, followerId, chunkIndex, success);
89 private Object readResolve() {
90 return installSnapshotReply;