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;
12 import org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload;
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;
23 private final long electionTerm;
24 private final String electionVotedFor;
25 private final ServerConfigurationPayload serverConfig;
27 private Snapshot(byte[] state, List<ReplicatedLogEntry> unAppliedEntries, long lastIndex, long lastTerm,
28 long lastAppliedIndex, long lastAppliedTerm, long electionTerm, String electionVotedFor,
29 ServerConfigurationPayload serverConfig) {
31 this.unAppliedEntries = unAppliedEntries;
32 this.lastIndex = lastIndex;
33 this.lastTerm = lastTerm;
34 this.lastAppliedIndex = lastAppliedIndex;
35 this.lastAppliedTerm = lastAppliedTerm;
36 this.electionTerm = electionTerm;
37 this.electionVotedFor = electionVotedFor;
38 this.serverConfig = serverConfig;
41 public static Snapshot create(byte[] state, List<ReplicatedLogEntry> entries, long lastIndex, long lastTerm,
42 long lastAppliedIndex, long lastAppliedTerm) {
43 return new Snapshot(state, entries, lastIndex, lastTerm, lastAppliedIndex, lastAppliedTerm, -1, null, null);
46 public static Snapshot create(byte[] state, List<ReplicatedLogEntry> entries, long lastIndex, long lastTerm,
47 long lastAppliedIndex, long lastAppliedTerm, long electionTerm, String electionVotedFor) {
48 return new Snapshot(state, entries, lastIndex, lastTerm, lastAppliedIndex, lastAppliedTerm,
49 electionTerm, electionVotedFor, null);
52 public static Snapshot create(byte[] state, List<ReplicatedLogEntry> entries, long lastIndex, long lastTerm,
53 long lastAppliedIndex, long lastAppliedTerm, long electionTerm, String electionVotedFor,
54 ServerConfigurationPayload serverConfig) {
55 return new Snapshot(state, entries, lastIndex, lastTerm, lastAppliedIndex, lastAppliedTerm,
56 electionTerm, electionVotedFor, serverConfig);
59 public byte[] getState() {
63 public List<ReplicatedLogEntry> getUnAppliedEntries() {
64 return unAppliedEntries;
67 public long getLastTerm() {
71 public long getLastAppliedIndex() {
72 return lastAppliedIndex;
75 public long getLastAppliedTerm() {
76 return lastAppliedTerm;
79 public long getLastIndex() {
80 return this.lastIndex;
83 public long getElectionTerm() {
88 public String getElectionVotedFor() {
89 return electionVotedFor;
92 public ServerConfigurationPayload getServerConfiguration() {
97 public String toString() {
98 return "Snapshot [lastIndex=" + lastIndex + ", lastTerm=" + lastTerm + ", lastAppliedIndex=" + lastAppliedIndex
99 + ", lastAppliedTerm=" + lastAppliedTerm + ", unAppliedEntries size=" + unAppliedEntries.size()
100 + ", state size=" + state.length + ", electionTerm=" + electionTerm + ", electionVotedFor=" + electionVotedFor
101 + ", ServerConfigPayload=" + serverConfig + "]";