a369c25ddf41bad10e788669b225e233dbff47ec
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / Snapshot.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.raft;
9
10 import java.io.Serializable;
11 import java.util.List;
12
13
14 public class Snapshot implements Serializable {
15     private static final long serialVersionUID = -8298574936724056236L;
16
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
26     private Snapshot(byte[] state, List<ReplicatedLogEntry> unAppliedEntries, long lastIndex, long lastTerm,
27             long lastAppliedIndex, long lastAppliedTerm, long electionTerm, String electionVotedFor) {
28         this.state = state;
29         this.unAppliedEntries = unAppliedEntries;
30         this.lastIndex = lastIndex;
31         this.lastTerm = lastTerm;
32         this.lastAppliedIndex = lastAppliedIndex;
33         this.lastAppliedTerm = lastAppliedTerm;
34         this.electionTerm = electionTerm;
35         this.electionVotedFor = electionVotedFor;
36     }
37
38     public static Snapshot create(byte[] state, List<ReplicatedLogEntry> entries, long lastIndex, long lastTerm,
39             long lastAppliedIndex, long lastAppliedTerm) {
40         return new Snapshot(state, entries, lastIndex, lastTerm, lastAppliedIndex, lastAppliedTerm, -1, null);
41     }
42
43     public static Snapshot create(byte[] state, List<ReplicatedLogEntry> entries, long lastIndex, long lastTerm,
44             long lastAppliedIndex, long lastAppliedTerm, long electionTerm, String electionVotedFor) {
45         return new Snapshot(state, entries, lastIndex, lastTerm, lastAppliedIndex, lastAppliedTerm,
46                 electionTerm, electionVotedFor);
47     }
48
49     public byte[] getState() {
50         return state;
51     }
52
53     public List<ReplicatedLogEntry> getUnAppliedEntries() {
54         return unAppliedEntries;
55     }
56
57     public long getLastTerm() {
58         return lastTerm;
59     }
60
61     public long getLastAppliedIndex() {
62         return lastAppliedIndex;
63     }
64
65     public long getLastAppliedTerm() {
66         return lastAppliedTerm;
67     }
68
69     public long getLastIndex() {
70         return this.lastIndex;
71     }
72
73     public long getElectionTerm() {
74         return electionTerm;
75     }
76
77
78     public String getElectionVotedFor() {
79         return electionVotedFor;
80     }
81
82     @Override
83     public String toString() {
84         return "Snapshot [lastIndex=" + lastIndex + ", lastTerm=" + lastTerm + ", lastAppliedIndex=" + lastAppliedIndex
85                 + ", lastAppliedTerm=" + lastAppliedTerm + ", unAppliedEntries size=" + unAppliedEntries.size()
86                 + ", state size=" + state.length + ", electionTerm=" + electionTerm + ", electionVotedFor=" + electionVotedFor
87                 + "]";
88     }
89 }