Merge "Bug 1029: Remove dead code: p2site"
[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 = 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;
22
23     private Snapshot(byte[] state,
24         List<ReplicatedLogEntry> unAppliedEntries, long lastIndex,
25         long lastTerm, long lastAppliedIndex, long lastAppliedTerm) {
26         this.state = state;
27         this.unAppliedEntries = unAppliedEntries;
28         this.lastIndex = lastIndex;
29         this.lastTerm = lastTerm;
30         this.lastAppliedIndex = lastAppliedIndex;
31         this.lastAppliedTerm = lastAppliedTerm;
32     }
33
34
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);
40     }
41
42     public byte[] getState() {
43         return state;
44     }
45
46     public List<ReplicatedLogEntry> getUnAppliedEntries() {
47         return unAppliedEntries;
48     }
49
50     public long getLastTerm() {
51         return lastTerm;
52     }
53
54     public long getLastAppliedIndex() {
55         return lastAppliedIndex;
56     }
57
58     public long getLastAppliedTerm() {
59         return lastAppliedTerm;
60     }
61
62     public long getLastIndex() {
63         return this.lastIndex;
64     }
65
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()  + "}")
74             .toString();
75
76     }
77 }