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 edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
11 import java.io.Serializable;
12 import java.util.List;
13 import org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload;
16 * Represents a snapshot of the raft data.
19 * @author Thomas Pantelis
21 * @deprecated Use {@link org.opendaylight.controller.cluster.raft.persisted.Snapshot} instead.
24 public class Snapshot implements Serializable {
25 private static final long serialVersionUID = -8298574936724056236L;
27 private final byte[] state;
28 private final List<ReplicatedLogEntry> unAppliedEntries;
29 private final long lastIndex;
30 private final long lastTerm;
31 private final long lastAppliedIndex;
32 private final long lastAppliedTerm;
33 private final long electionTerm;
34 private final String electionVotedFor;
35 private final ServerConfigurationPayload serverConfig;
37 private Snapshot(byte[] state, List<ReplicatedLogEntry> unAppliedEntries, long lastIndex, long lastTerm,
38 long lastAppliedIndex, long lastAppliedTerm, long electionTerm, String electionVotedFor,
39 ServerConfigurationPayload serverConfig) {
41 this.unAppliedEntries = unAppliedEntries;
42 this.lastIndex = lastIndex;
43 this.lastTerm = lastTerm;
44 this.lastAppliedIndex = lastAppliedIndex;
45 this.lastAppliedTerm = lastAppliedTerm;
46 this.electionTerm = electionTerm;
47 this.electionVotedFor = electionVotedFor;
48 this.serverConfig = serverConfig;
51 public static Snapshot create(byte[] state, List<ReplicatedLogEntry> entries, long lastIndex, long lastTerm,
52 long lastAppliedIndex, long lastAppliedTerm) {
53 return new Snapshot(state, entries, lastIndex, lastTerm, lastAppliedIndex, lastAppliedTerm, -1, null, null);
56 public static Snapshot create(byte[] state, List<ReplicatedLogEntry> entries, long lastIndex, long lastTerm,
57 long lastAppliedIndex, long lastAppliedTerm, long electionTerm, String electionVotedFor) {
58 return new Snapshot(state, entries, lastIndex, lastTerm, lastAppliedIndex, lastAppliedTerm,
59 electionTerm, electionVotedFor, null);
62 public static Snapshot create(byte[] state, List<ReplicatedLogEntry> entries, long lastIndex, long lastTerm,
63 long lastAppliedIndex, long lastAppliedTerm, long electionTerm, String electionVotedFor,
64 ServerConfigurationPayload serverConfig) {
65 return new Snapshot(state, entries, lastIndex, lastTerm, lastAppliedIndex, lastAppliedTerm,
66 electionTerm, electionVotedFor, serverConfig);
69 @SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "Exposes a mutable object stored in a field but "
70 + "this is OK since this class is merely a DTO and does not process the byte[] internally. "
71 + "Also it would be inefficient to create a return copy as the byte[] could be large.")
72 public byte[] getState() {
76 public List<ReplicatedLogEntry> getUnAppliedEntries() {
77 return unAppliedEntries;
80 public long getLastTerm() {
84 public long getLastAppliedIndex() {
85 return lastAppliedIndex;
88 public long getLastAppliedTerm() {
89 return lastAppliedTerm;
92 public long getLastIndex() {
93 return this.lastIndex;
96 public long getElectionTerm() {
101 public String getElectionVotedFor() {
102 return electionVotedFor;
105 public ServerConfigurationPayload getServerConfiguration() {
110 public String toString() {
111 return "Snapshot [lastIndex=" + lastIndex + ", lastTerm=" + lastTerm + ", lastAppliedIndex=" + lastAppliedIndex
112 + ", lastAppliedTerm=" + lastAppliedTerm + ", unAppliedEntries size=" + unAppliedEntries.size()
113 + ", state size=" + state.length + ", electionTerm=" + electionTerm + ", electionVotedFor="
114 + electionVotedFor + ", ServerConfigPayload=" + serverConfig + "]";