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