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

©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.