2 * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.raft.client.messages;
10 import com.google.common.collect.ImmutableMap;
11 import java.util.Collections;
12 import java.util.List;
16 * The response to a GetOnDemandRaftState message,
18 * @author Thomas Pantelis
20 public class OnDemandRaftState {
21 private long lastLogIndex = -1L;
22 private long lastLogTerm = -1L;
23 private long currentTerm = -1L;
24 private long commitIndex = -1L;
25 private long lastApplied = -1L;
26 private long lastIndex = -1L;
27 private long lastTerm = -1L;
28 private long snapshotIndex = -1L;
29 private long snapshotTerm = -1L;
30 private long replicatedToAllIndex = -1L;
31 private long inMemoryJournalDataSize;
32 private long inMemoryJournalLogSize;
33 private String leader;
34 private String raftState;
35 private String votedFor;
36 private boolean isSnapshotCaptureInitiated;
37 private String customRaftPolicyClassName;
38 private boolean isVoting;
40 private List<FollowerInfo> followerInfoList = Collections.emptyList();
41 private Map<String, String> peerAddresses = Collections.emptyMap();
42 private Map<String, Boolean> peerVotingStates = Collections.emptyMap();
44 private OnDemandRaftState() {
47 public static Builder builder() {
51 public long getLastLogIndex() {
55 public long getLastLogTerm() {
59 public long getCurrentTerm() {
63 public long getCommitIndex() {
67 public long getLastApplied() {
71 public long getLastIndex() {
75 public long getLastTerm() {
79 public long getSnapshotIndex() {
83 public long getSnapshotTerm() {
87 public long getReplicatedToAllIndex() {
88 return replicatedToAllIndex;
91 public long getInMemoryJournalDataSize() {
92 return inMemoryJournalDataSize;
95 public long getInMemoryJournalLogSize() {
96 return inMemoryJournalLogSize;
99 public String getLeader() {
103 public String getRaftState() {
107 public String getVotedFor() {
111 public boolean isSnapshotCaptureInitiated() {
112 return isSnapshotCaptureInitiated;
115 public boolean isVoting() {
119 public List<FollowerInfo> getFollowerInfoList() {
120 return followerInfoList;
123 public Map<String, String> getPeerAddresses() {
124 return peerAddresses;
127 public Map<String, Boolean> getPeerVotingStates() {
128 return peerVotingStates;
131 public String getCustomRaftPolicyClassName() {
132 return customRaftPolicyClassName;
135 public static class Builder {
136 private final OnDemandRaftState stats = new OnDemandRaftState();
138 public Builder lastLogIndex(long value) {
139 stats.lastLogIndex = value;
143 public Builder lastLogTerm(long value) {
144 stats.lastLogTerm = value;
148 public Builder currentTerm(long value) {
149 stats.currentTerm = value;
153 public Builder commitIndex(long value) {
154 stats.commitIndex = value;
158 public Builder lastApplied(long value) {
159 stats.lastApplied = value;
163 public Builder lastIndex(long value) {
164 stats.lastIndex = value;
168 public Builder lastTerm(long value) {
169 stats.lastTerm = value;
173 public Builder snapshotIndex(long value) {
174 stats.snapshotIndex = value;
178 public Builder snapshotTerm(long value) {
179 stats.snapshotTerm = value;
183 public Builder replicatedToAllIndex(long value) {
184 stats.replicatedToAllIndex = value;
188 public Builder inMemoryJournalDataSize(long value) {
189 stats.inMemoryJournalDataSize = value;
193 public Builder inMemoryJournalLogSize(long value) {
194 stats.inMemoryJournalLogSize = value;
198 public Builder leader(String value) {
199 stats.leader = value;
203 public Builder raftState(String value) {
204 stats.raftState = value;
208 public Builder votedFor(String value) {
209 stats.votedFor = value;
213 public Builder isVoting(boolean isVoting) {
214 stats.isVoting = isVoting;
218 public Builder followerInfoList(List<FollowerInfo> followerInfoList) {
219 stats.followerInfoList = followerInfoList;
223 public Builder peerAddresses(Map<String, String> peerAddresses) {
224 stats.peerAddresses = peerAddresses;
228 public Builder peerVotingStates(Map<String, Boolean> peerVotingStates) {
229 stats.peerVotingStates = ImmutableMap.copyOf(peerVotingStates);
233 public Builder isSnapshotCaptureInitiated(boolean value) {
234 stats.isSnapshotCaptureInitiated = value;
238 public Builder customRaftPolicyClassName(String className) {
239 stats.customRaftPolicyClassName = className;
243 public OnDemandRaftState build() {