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;
15 import org.opendaylight.controller.cluster.mgmt.api.FollowerInfo;
18 * The response to a GetOnDemandRaftState message.
20 * @author Thomas Pantelis
22 public class OnDemandRaftState {
23 private long lastLogIndex = -1L;
24 private long lastLogTerm = -1L;
25 private long currentTerm = -1L;
26 private long commitIndex = -1L;
27 private long lastApplied = -1L;
28 private long lastIndex = -1L;
29 private long lastTerm = -1L;
30 private long snapshotIndex = -1L;
31 private long snapshotTerm = -1L;
32 private long replicatedToAllIndex = -1L;
33 private long inMemoryJournalDataSize;
34 private long inMemoryJournalLogSize;
35 private String leader;
36 private String raftState;
37 private String votedFor;
38 private boolean isSnapshotCaptureInitiated;
39 private String customRaftPolicyClassName;
40 private boolean isVoting;
42 private List<FollowerInfo> followerInfoList = Collections.emptyList();
43 private Map<String, String> peerAddresses = Collections.emptyMap();
44 private Map<String, Boolean> peerVotingStates = Collections.emptyMap();
46 protected OnDemandRaftState() {
49 public static Builder builder() {
53 public long getLastLogIndex() {
57 public long getLastLogTerm() {
61 public long getCurrentTerm() {
65 public long getCommitIndex() {
69 public long getLastApplied() {
73 public long getLastIndex() {
77 public long getLastTerm() {
81 public long getSnapshotIndex() {
85 public long getSnapshotTerm() {
89 public long getReplicatedToAllIndex() {
90 return replicatedToAllIndex;
93 public long getInMemoryJournalDataSize() {
94 return inMemoryJournalDataSize;
97 public long getInMemoryJournalLogSize() {
98 return inMemoryJournalLogSize;
101 public String getLeader() {
105 public String getRaftState() {
109 public String getVotedFor() {
113 public boolean isSnapshotCaptureInitiated() {
114 return isSnapshotCaptureInitiated;
117 public boolean isVoting() {
121 public List<FollowerInfo> getFollowerInfoList() {
122 return followerInfoList;
125 public Map<String, String> getPeerAddresses() {
126 return peerAddresses;
129 public Map<String, Boolean> getPeerVotingStates() {
130 return peerVotingStates;
133 public String getCustomRaftPolicyClassName() {
134 return customRaftPolicyClassName;
137 public abstract static class AbstractBuilder<B extends AbstractBuilder<B, T>, T extends OnDemandRaftState> {
138 @SuppressWarnings("unchecked")
143 protected abstract @NonNull OnDemandRaftState state();
145 public B lastLogIndex(long value) {
146 state().lastLogIndex = value;
150 public B lastLogTerm(long value) {
151 state().lastLogTerm = value;
155 public B currentTerm(long value) {
156 state().currentTerm = value;
160 public B commitIndex(long value) {
161 state().commitIndex = value;
165 public B lastApplied(long value) {
166 state().lastApplied = value;
170 public B lastIndex(long value) {
171 state().lastIndex = value;
175 public B lastTerm(long value) {
176 state().lastTerm = value;
180 public B snapshotIndex(long value) {
181 state().snapshotIndex = value;
185 public B snapshotTerm(long value) {
186 state().snapshotTerm = value;
190 public B replicatedToAllIndex(long value) {
191 state().replicatedToAllIndex = value;
195 public B inMemoryJournalDataSize(long value) {
196 state().inMemoryJournalDataSize = value;
200 public B inMemoryJournalLogSize(long value) {
201 state().inMemoryJournalLogSize = value;
205 public B leader(String value) {
206 state().leader = value;
210 public B raftState(String value) {
211 state().raftState = value;
215 public B votedFor(String value) {
216 state().votedFor = value;
220 public B isVoting(boolean isVoting) {
221 state().isVoting = isVoting;
225 public B followerInfoList(List<FollowerInfo> followerInfoList) {
226 state().followerInfoList = followerInfoList;
230 public B peerAddresses(Map<String, String> peerAddresses) {
231 state().peerAddresses = peerAddresses;
235 public B peerVotingStates(Map<String, Boolean> peerVotingStates) {
236 state().peerVotingStates = ImmutableMap.copyOf(peerVotingStates);
240 public B isSnapshotCaptureInitiated(boolean value) {
241 state().isSnapshotCaptureInitiated = value;
245 public B customRaftPolicyClassName(String className) {
246 state().customRaftPolicyClassName = className;
250 @SuppressWarnings("unchecked")
256 public static class Builder extends AbstractBuilder<Builder, OnDemandRaftState> {
257 private final OnDemandRaftState state = new OnDemandRaftState();
260 protected OnDemandRaftState state() {