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 final byte[] state;
16 private final List<ReplicatedLogEntry> unAppliedEntries;
17 private final long lastIndex;
18 private final long lastTerm;
19 private final long lastAppliedIndex;
20 private final long lastAppliedTerm;
22 private Snapshot(byte[] state,
23 List<ReplicatedLogEntry> unAppliedEntries, long lastIndex,
24 long lastTerm, long lastAppliedIndex, long lastAppliedTerm) {
26 this.unAppliedEntries = unAppliedEntries;
27 this.lastIndex = lastIndex;
28 this.lastTerm = lastTerm;
29 this.lastAppliedIndex = lastAppliedIndex;
30 this.lastAppliedTerm = lastAppliedTerm;
34 public static Snapshot create(byte[] state,
35 List<ReplicatedLogEntry> entries, long lastIndex, long lastTerm,
36 long lastAppliedIndex, long lastAppliedTerm) {
37 return new Snapshot(state, entries, lastIndex, lastTerm,
38 lastAppliedIndex, lastAppliedTerm);
41 public byte[] getState() {
45 public List<ReplicatedLogEntry> getUnAppliedEntries() {
46 return unAppliedEntries;
49 public long getLastTerm() {
53 public long getLastAppliedIndex() {
54 return lastAppliedIndex;
57 public long getLastAppliedTerm() {
58 return lastAppliedTerm;
61 public long getLastIndex() {
62 return this.lastIndex;
65 public String getLogMessage() {
66 StringBuilder sb = new StringBuilder();
67 return sb.append("Snapshot={")
68 .append("lastTerm:" + this.getLastTerm() + ", ")
69 .append("lastIndex:" + this.getLastIndex() + ", ")
70 .append("LastAppliedIndex:" + this.getLastAppliedIndex() + ", ")
71 .append("LastAppliedTerm:" + this.getLastAppliedTerm() + ", ")
72 .append("UnAppliedEntries size:" + this.getUnAppliedEntries().size() + "}")