Merge "Cleanup root pom "name"."
[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
24     private Snapshot(byte[] state,
25         List<ReplicatedLogEntry> unAppliedEntries, long lastIndex,
26         long lastTerm, long lastAppliedIndex, long lastAppliedTerm) {
27         this.state = state;
28         this.unAppliedEntries = unAppliedEntries;
29         this.lastIndex = lastIndex;
30         this.lastTerm = lastTerm;
31         this.lastAppliedIndex = lastAppliedIndex;
32         this.lastAppliedTerm = lastAppliedTerm;
33     }
34
35
36     public static Snapshot create(byte[] state,
37         List<ReplicatedLogEntry> entries, long lastIndex, long lastTerm,
38         long lastAppliedIndex, long lastAppliedTerm) {
39         return new Snapshot(state, entries, lastIndex, lastTerm,
40             lastAppliedIndex, lastAppliedTerm);
41     }
42
43     public byte[] getState() {
44         return state;
45     }
46
47     public List<ReplicatedLogEntry> getUnAppliedEntries() {
48         return unAppliedEntries;
49     }
50
51     public long getLastTerm() {
52         return lastTerm;
53     }
54
55     public long getLastAppliedIndex() {
56         return lastAppliedIndex;
57     }
58
59     public long getLastAppliedTerm() {
60         return lastAppliedTerm;
61     }
62
63     public long getLastIndex() {
64         return this.lastIndex;
65     }
66
67     public String getLogMessage() {
68         StringBuilder sb = new StringBuilder();
69         return sb.append("Snapshot={")
70             .append("lastTerm:" + this.getLastTerm() + ", ")
71             .append("lastIndex:" + this.getLastIndex()  + ", ")
72             .append("LastAppliedIndex:" + this.getLastAppliedIndex()  + ", ")
73             .append("LastAppliedTerm:" + this.getLastAppliedTerm()  + ", ")
74             .append("UnAppliedEntries size:" + this.getUnAppliedEntries().size()  + "}")
75             .toString();
76
77     }
78 }