Add OnDemandShardState to report additional Shard state
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / client / messages / OnDemandRaftState.java
1 /*
2  * Copyright (c) 2015 Brocade Communications 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 package org.opendaylight.controller.cluster.raft.client.messages;
9
10 import com.google.common.collect.ImmutableMap;
11 import java.util.Collections;
12 import java.util.List;
13 import java.util.Map;
14 import javax.annotation.Nonnull;
15
16 /**
17  * The response to a GetOnDemandRaftState message.
18  *
19  * @author Thomas Pantelis
20  */
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;
40
41     private List<FollowerInfo> followerInfoList = Collections.emptyList();
42     private Map<String, String> peerAddresses = Collections.emptyMap();
43     private Map<String, Boolean> peerVotingStates = Collections.emptyMap();
44
45     protected OnDemandRaftState() {
46     }
47
48     public static Builder builder() {
49         return new Builder();
50     }
51
52     public long getLastLogIndex() {
53         return lastLogIndex;
54     }
55
56     public long getLastLogTerm() {
57         return lastLogTerm;
58     }
59
60     public long getCurrentTerm() {
61         return currentTerm;
62     }
63
64     public long getCommitIndex() {
65         return commitIndex;
66     }
67
68     public long getLastApplied() {
69         return lastApplied;
70     }
71
72     public long getLastIndex() {
73         return lastIndex;
74     }
75
76     public long getLastTerm() {
77         return lastTerm;
78     }
79
80     public long getSnapshotIndex() {
81         return snapshotIndex;
82     }
83
84     public long getSnapshotTerm() {
85         return snapshotTerm;
86     }
87
88     public long getReplicatedToAllIndex() {
89         return replicatedToAllIndex;
90     }
91
92     public long getInMemoryJournalDataSize() {
93         return inMemoryJournalDataSize;
94     }
95
96     public long getInMemoryJournalLogSize() {
97         return inMemoryJournalLogSize;
98     }
99
100     public String getLeader() {
101         return leader;
102     }
103
104     public String getRaftState() {
105         return raftState;
106     }
107
108     public String getVotedFor() {
109         return votedFor;
110     }
111
112     public boolean isSnapshotCaptureInitiated() {
113         return isSnapshotCaptureInitiated;
114     }
115
116     public boolean isVoting() {
117         return isVoting;
118     }
119
120     public List<FollowerInfo> getFollowerInfoList() {
121         return followerInfoList;
122     }
123
124     public Map<String, String> getPeerAddresses() {
125         return peerAddresses;
126     }
127
128     public Map<String, Boolean> getPeerVotingStates() {
129         return peerVotingStates;
130     }
131
132     public String getCustomRaftPolicyClassName() {
133         return customRaftPolicyClassName;
134     }
135
136     public abstract static class AbstractBuilder<T extends AbstractBuilder<T>> {
137         @SuppressWarnings("unchecked")
138         protected T self() {
139             return (T) this;
140         }
141
142         @Nonnull
143         protected abstract OnDemandRaftState state();
144
145         public T lastLogIndex(long value) {
146             state().lastLogIndex = value;
147             return self();
148         }
149
150         public T lastLogTerm(long value) {
151             state().lastLogTerm = value;
152             return self();
153         }
154
155         public T currentTerm(long value) {
156             state().currentTerm = value;
157             return self();
158         }
159
160         public T commitIndex(long value) {
161             state().commitIndex = value;
162             return self();
163         }
164
165         public T lastApplied(long value) {
166             state().lastApplied = value;
167             return self();
168         }
169
170         public T lastIndex(long value) {
171             state().lastIndex = value;
172             return self();
173         }
174
175         public T lastTerm(long value) {
176             state().lastTerm = value;
177             return self();
178         }
179
180         public T snapshotIndex(long value) {
181             state().snapshotIndex = value;
182             return self();
183         }
184
185         public T snapshotTerm(long value) {
186             state().snapshotTerm = value;
187             return self();
188         }
189
190         public T replicatedToAllIndex(long value) {
191             state().replicatedToAllIndex = value;
192             return self();
193         }
194
195         public T inMemoryJournalDataSize(long value) {
196             state().inMemoryJournalDataSize = value;
197             return self();
198         }
199
200         public T inMemoryJournalLogSize(long value) {
201             state().inMemoryJournalLogSize = value;
202             return self();
203         }
204
205         public T leader(String value) {
206             state().leader = value;
207             return self();
208         }
209
210         public T raftState(String value) {
211             state().raftState = value;
212             return self();
213         }
214
215         public T votedFor(String value) {
216             state().votedFor = value;
217             return self();
218         }
219
220         public T isVoting(boolean isVoting) {
221             state().isVoting = isVoting;
222             return self();
223         }
224
225         public T followerInfoList(List<FollowerInfo> followerInfoList) {
226             state().followerInfoList = followerInfoList;
227             return self();
228         }
229
230         public T peerAddresses(Map<String, String> peerAddresses) {
231             state().peerAddresses = peerAddresses;
232             return self();
233         }
234
235         public T peerVotingStates(Map<String, Boolean> peerVotingStates) {
236             state().peerVotingStates = ImmutableMap.copyOf(peerVotingStates);
237             return self();
238         }
239
240         public T isSnapshotCaptureInitiated(boolean value) {
241             state().isSnapshotCaptureInitiated = value;
242             return self();
243         }
244
245         public T customRaftPolicyClassName(String className) {
246             state().customRaftPolicyClassName = className;
247             return self();
248         }
249
250         public OnDemandRaftState build() {
251             return state();
252         }
253     }
254
255     public static class Builder extends AbstractBuilder<Builder> {
256         private final OnDemandRaftState state = new OnDemandRaftState();
257
258         @Override
259         protected OnDemandRaftState state() {
260             return state;
261         }
262     }
263 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.