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<InstallSnapshotMessages.InstallSnapshot> SERIALIZABLE_CLASS = InstallSnapshotMessages.InstallSnapshot.class;
17 private static final long serialVersionUID = 1L;
19 private final String leaderId;
20 private final long lastIncludedIndex;
21 private final long lastIncludedTerm;
22 private final ByteString data;
23 private final int chunkIndex;
24 private final int totalChunks;
26 public InstallSnapshot(long term, String leaderId, long lastIncludedIndex,
27 long lastIncludedTerm, ByteString data, int chunkIndex, int totalChunks) {
29 this.leaderId = leaderId;
30 this.lastIncludedIndex = lastIncludedIndex;
31 this.lastIncludedTerm = lastIncludedTerm;
33 this.chunkIndex = chunkIndex;
34 this.totalChunks = totalChunks;
37 public String getLeaderId() {
41 public long getLastIncludedIndex() {
42 return lastIncludedIndex;
45 public long getLastIncludedTerm() {
46 return lastIncludedTerm;
49 public ByteString getData() {
53 public int getChunkIndex() {
57 public int getTotalChunks() {
61 public <T extends Object> Object toSerializable(){
62 return InstallSnapshotMessages.InstallSnapshot.newBuilder()
63 .setLeaderId(this.getLeaderId())
64 .setChunkIndex(this.getChunkIndex())
65 .setData(this.getData())
66 .setLastIncludedIndex(this.getLastIncludedIndex())
67 .setLastIncludedTerm(this.getLastIncludedTerm())
68 .setTotalChunks(this.getTotalChunks()).build();
72 public static InstallSnapshot fromSerializable (Object o) {
73 InstallSnapshotMessages.InstallSnapshot from =
74 (InstallSnapshotMessages.InstallSnapshot) o;
76 InstallSnapshot installSnapshot = new InstallSnapshot(from.getTerm(),
77 from.getLeaderId(), from.getLastIncludedIndex(),
78 from.getLastIncludedTerm(), from.getData(),
79 from.getChunkIndex(), from.getTotalChunks());
81 return installSnapshot;