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
8 package org.opendaylight.controller.cluster.raft;
10 import java.io.Serializable;
11 import java.util.List;
14 public class Snapshot implements Serializable {
15 private static final long serialVersionUID = -8298574936724056236L;
17 private final byte[] state;
18 private final List<ReplicatedLogEntry> unAppliedEntries;
19 private final long lastIndex;
20 private final long lastTerm;
21 private final long lastAppliedIndex;
22 private final long lastAppliedTerm;
24 private Snapshot(byte[] state,
25 List<ReplicatedLogEntry> unAppliedEntries, long lastIndex,
26 long lastTerm, long lastAppliedIndex, long lastAppliedTerm) {
28 this.unAppliedEntries = unAppliedEntries;
29 this.lastIndex = lastIndex;
30 this.lastTerm = lastTerm;
31 this.lastAppliedIndex = lastAppliedIndex;
32 this.lastAppliedTerm = lastAppliedTerm;
36 public static Snapshot create(byte[] state,
37 List<ReplicatedLogEntry> entries, long lastIndex, long lastTerm,
38 long lastAppliedIndex, long lastAppliedTerm) {
39 return new Snapshot(state, entries, lastIndex, lastTerm,
40 lastAppliedIndex, lastAppliedTerm);
43 public byte[] getState() {
47 public List<ReplicatedLogEntry> getUnAppliedEntries() {
48 return unAppliedEntries;
51 public long getLastTerm() {
55 public long getLastAppliedIndex() {
56 return lastAppliedIndex;
59 public long getLastAppliedTerm() {
60 return lastAppliedTerm;
63 public long getLastIndex() {
64 return this.lastIndex;
67 public String getLogMessage() {
68 StringBuilder sb = new StringBuilder();
69 return sb.append("Snapshot={")
70 .append("lastTerm:" + this.getLastTerm() + ", ")
71 .append("lastIndex:" + this.getLastIndex() + ", ")
72 .append("LastAppliedIndex:" + this.getLastAppliedIndex() + ", ")
73 .append("LastAppliedTerm:" + this.getLastAppliedTerm() + ", ")
74 .append("UnAppliedEntries size:" + this.getUnAppliedEntries().size() + "}")