Bug 7521: Convert Snapshot to store a State instance
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / base / messages / CaptureSnapshot.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
9 package org.opendaylight.controller.cluster.raft.base.messages;
10
11 import java.util.Collections;
12 import java.util.List;
13 import org.opendaylight.controller.cluster.raft.ReplicatedLogEntry;
14
15 public class CaptureSnapshot {
16     private final long lastAppliedIndex;
17     private final long lastAppliedTerm;
18     private final long lastIndex;
19     private final long lastTerm;
20     private final long replicatedToAllIndex;
21     private final long replicatedToAllTerm;
22     private final List<ReplicatedLogEntry> unAppliedEntries;
23
24     public CaptureSnapshot(long lastIndex, long lastTerm, long lastAppliedIndex,
25             long lastAppliedTerm, long replicatedToAllIndex, long replicatedToAllTerm,
26             List<ReplicatedLogEntry> unAppliedEntries) {
27         this.lastIndex = lastIndex;
28         this.lastTerm = lastTerm;
29         this.lastAppliedIndex = lastAppliedIndex;
30         this.lastAppliedTerm = lastAppliedTerm;
31         this.replicatedToAllIndex = replicatedToAllIndex;
32         this.replicatedToAllTerm = replicatedToAllTerm;
33         this.unAppliedEntries = unAppliedEntries != null ? unAppliedEntries :
34             Collections.<ReplicatedLogEntry>emptyList();
35     }
36
37     public long getLastAppliedIndex() {
38         return lastAppliedIndex;
39     }
40
41     public long getLastAppliedTerm() {
42         return lastAppliedTerm;
43     }
44
45     public long getLastIndex() {
46         return lastIndex;
47     }
48
49     public long getLastTerm() {
50         return lastTerm;
51     }
52
53     public long getReplicatedToAllIndex() {
54         return replicatedToAllIndex;
55     }
56
57     public long getReplicatedToAllTerm() {
58         return replicatedToAllTerm;
59     }
60
61     public List<ReplicatedLogEntry> getUnAppliedEntries() {
62         return unAppliedEntries;
63     }
64
65     @Override
66     public String toString() {
67         StringBuilder builder = new StringBuilder();
68         builder.append("CaptureSnapshot [lastAppliedIndex=").append(lastAppliedIndex).append(", lastAppliedTerm=")
69                 .append(lastAppliedTerm).append(", lastIndex=").append(lastIndex).append(", lastTerm=")
70                 .append(lastTerm).append(", installSnapshotInitiated=")
71                 .append(", replicatedToAllIndex=").append(replicatedToAllIndex).append(", replicatedToAllTerm=")
72                 .append(replicatedToAllTerm).append(", unAppliedEntries size=")
73                 .append(unAppliedEntries.size()).append("]");
74         return builder.toString();
75     }
76
77
78 }