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 com.google.protobuf.ByteString;
12 import org.opendaylight.controller.protobuff.messages.cluster.raft.InstallSnapshotMessages;
14 public class InstallSnapshot extends AbstractRaftRPC {
16 public static final Class SERIALIZABLE_CLASS = InstallSnapshotMessages.InstallSnapshot.class;
18 private final String leaderId;
19 private final long lastIncludedIndex;
20 private final long lastIncludedTerm;
21 private final ByteString data;
22 private final int chunkIndex;
23 private final int totalChunks;
25 public InstallSnapshot(long term, String leaderId, long lastIncludedIndex,
26 long lastIncludedTerm, ByteString data, int chunkIndex, int totalChunks) {
28 this.leaderId = leaderId;
29 this.lastIncludedIndex = lastIncludedIndex;
30 this.lastIncludedTerm = lastIncludedTerm;
32 this.chunkIndex = chunkIndex;
33 this.totalChunks = totalChunks;
36 public String getLeaderId() {
40 public long getLastIncludedIndex() {
41 return lastIncludedIndex;
44 public long getLastIncludedTerm() {
45 return lastIncludedTerm;
48 public ByteString getData() {
52 public int getChunkIndex() {
56 public int getTotalChunks() {
60 public <T extends Object> Object toSerializable(){
61 return InstallSnapshotMessages.InstallSnapshot.newBuilder()
62 .setLeaderId(this.getLeaderId())
63 .setChunkIndex(this.getChunkIndex())
64 .setData(this.getData())
65 .setLastIncludedIndex(this.getLastIncludedIndex())
66 .setLastIncludedTerm(this.getLastIncludedTerm())
67 .setTotalChunks(this.getTotalChunks()).build();
71 public static InstallSnapshot fromSerializable (Object o) {
72 InstallSnapshotMessages.InstallSnapshot from =
73 (InstallSnapshotMessages.InstallSnapshot) o;
75 InstallSnapshot installSnapshot = new InstallSnapshot(from.getTerm(),
76 from.getLeaderId(), from.getLastIncludedIndex(),
77 from.getLastIncludedTerm(), from.getData(),
78 from.getChunkIndex(), from.getTotalChunks());
80 return installSnapshot;