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;
14 import org.eclipse.jdt.annotation.NonNull;
17 * The response to a GetOnDemandRaftState message.
19 * @author Thomas Pantelis
21 public class OnDemandRaftState {
22 private long lastLogIndex = -1L;
23 private long lastLogTerm = -1L;
24 private long currentTerm = -1L;
25 private long commitIndex = -1L;
26 private long lastApplied = -1L;
27 private long lastIndex = -1L;
28 private long lastTerm = -1L;
29 private long snapshotIndex = -1L;
30 private long snapshotTerm = -1L;
31 private long replicatedToAllIndex = -1L;
32 private long inMemoryJournalDataSize;
33 private long inMemoryJournalLogSize;
34 private String leader;
35 private String raftState;
36 private String votedFor;
37 private boolean isSnapshotCaptureInitiated;
38 private String customRaftPolicyClassName;
39 private boolean isVoting;
41 private List<FollowerInfo> followerInfoList = Collections.emptyList();
42 private Map<String, String> peerAddresses = Collections.emptyMap();
43 private Map<String, Boolean> peerVotingStates = Collections.emptyMap();
45 protected OnDemandRaftState() {
48 public static Builder builder() {
52 public long getLastLogIndex() {
56 public long getLastLogTerm() {
60 public long getCurrentTerm() {
64 public long getCommitIndex() {
68 public long getLastApplied() {
72 public long getLastIndex() {
76 public long getLastTerm() {
80 public long getSnapshotIndex() {
84 public long getSnapshotTerm() {
88 public long getReplicatedToAllIndex() {
89 return replicatedToAllIndex;
92 public long getInMemoryJournalDataSize() {
93 return inMemoryJournalDataSize;
96 public long getInMemoryJournalLogSize() {
97 return inMemoryJournalLogSize;
100 public String getLeader() {
104 public String getRaftState() {
108 public String getVotedFor() {
112 public boolean isSnapshotCaptureInitiated() {
113 return isSnapshotCaptureInitiated;
116 public boolean isVoting() {
120 public List<FollowerInfo> getFollowerInfoList() {
121 return followerInfoList;
124 public Map<String, String> getPeerAddresses() {
125 return peerAddresses;
128 public Map<String, Boolean> getPeerVotingStates() {
129 return peerVotingStates;
132 public String getCustomRaftPolicyClassName() {
133 return customRaftPolicyClassName;
136 public abstract static class AbstractBuilder<B extends AbstractBuilder<B, T>, T extends OnDemandRaftState> {
137 @SuppressWarnings("unchecked")
142 protected abstract @NonNull OnDemandRaftState state();
144 public B lastLogIndex(long value) {
145 state().lastLogIndex = value;
149 public B lastLogTerm(long value) {
150 state().lastLogTerm = value;
154 public B currentTerm(long value) {
155 state().currentTerm = value;
159 public B commitIndex(long value) {
160 state().commitIndex = value;
164 public B lastApplied(long value) {
165 state().lastApplied = value;
169 public B lastIndex(long value) {
170 state().lastIndex = value;
174 public B lastTerm(long value) {
175 state().lastTerm = value;
179 public B snapshotIndex(long value) {
180 state().snapshotIndex = value;
184 public B snapshotTerm(long value) {
185 state().snapshotTerm = value;
189 public B replicatedToAllIndex(long value) {
190 state().replicatedToAllIndex = value;
194 public B inMemoryJournalDataSize(long value) {
195 state().inMemoryJournalDataSize = value;
199 public B inMemoryJournalLogSize(long value) {
200 state().inMemoryJournalLogSize = value;
204 public B leader(String value) {
205 state().leader = value;
209 public B raftState(String value) {
210 state().raftState = value;
214 public B votedFor(String value) {
215 state().votedFor = value;
219 public B isVoting(boolean isVoting) {
220 state().isVoting = isVoting;
224 public B followerInfoList(List<FollowerInfo> followerInfoList) {
225 state().followerInfoList = followerInfoList;
229 public B peerAddresses(Map<String, String> peerAddresses) {
230 state().peerAddresses = peerAddresses;
234 public B peerVotingStates(Map<String, Boolean> peerVotingStates) {
235 state().peerVotingStates = ImmutableMap.copyOf(peerVotingStates);
239 public B isSnapshotCaptureInitiated(boolean value) {
240 state().isSnapshotCaptureInitiated = value;
244 public B customRaftPolicyClassName(String className) {
245 state().customRaftPolicyClassName = className;
249 @SuppressWarnings("unchecked")
255 public static class Builder extends AbstractBuilder<Builder, OnDemandRaftState> {
256 private final OnDemandRaftState state = new OnDemandRaftState();
259 protected OnDemandRaftState state() {