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