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 = 1L;
16 private final byte[] state;
17 private final List<ReplicatedLogEntry> unAppliedEntries;
18 private final long lastIndex;
19 private final long lastTerm;
20 private final long lastAppliedIndex;
21 private final long lastAppliedTerm;
23 private Snapshot(byte[] state,
24 List<ReplicatedLogEntry> unAppliedEntries, long lastIndex,
25 long lastTerm, long lastAppliedIndex, long lastAppliedTerm) {
27 this.unAppliedEntries = unAppliedEntries;
28 this.lastIndex = lastIndex;
29 this.lastTerm = lastTerm;
30 this.lastAppliedIndex = lastAppliedIndex;
31 this.lastAppliedTerm = lastAppliedTerm;
35 public static Snapshot create(byte[] state,
36 List<ReplicatedLogEntry> entries, long lastIndex, long lastTerm,
37 long lastAppliedIndex, long lastAppliedTerm) {
38 return new Snapshot(state, entries, lastIndex, lastTerm,
39 lastAppliedIndex, lastAppliedTerm);
42 public byte[] getState() {
46 public List<ReplicatedLogEntry> getUnAppliedEntries() {
47 return unAppliedEntries;
50 public long getLastTerm() {
54 public long getLastAppliedIndex() {
55 return lastAppliedIndex;
58 public long getLastAppliedTerm() {
59 return lastAppliedTerm;
62 public long getLastIndex() {
63 return this.lastIndex;
66 public String getLogMessage() {
67 StringBuilder sb = new StringBuilder();
68 return sb.append("Snapshot={")
69 .append("lastTerm:" + this.getLastTerm() + ", ")
70 .append("lastIndex:" + this.getLastIndex() + ", ")
71 .append("LastAppliedIndex:" + this.getLastAppliedIndex() + ", ")
72 .append("LastAppliedTerm:" + this.getLastAppliedTerm() + ", ")
73 .append("UnAppliedEntries size:" + this.getUnAppliedEntries().size() + "}")