-
Notifications
You must be signed in to change notification settings - Fork 33
/
BrokerState.java
298 lines (261 loc) · 9.79 KB
/
BrokerState.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/*
* Copyright (c) 2000, 2017 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022 Contributors to Eclipse Foundation. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package com.sun.messaging.jmq.jmsserver.cluster.api;
import java.util.*;
/**
* This class is a type-safe enum which contains the valid lifecycle states for a broker. It is used by ClusterConfig to
* set the state of the broker. State is stored as an int in JDBC and used as a typesafe enum within the code.
* <p>
* The states are as follows:
*
* <table border=1>
* <TR>
* <TH>State</TH>
* <TH>Description</TH>
* <TH>Behavior</TH>
* </TR>
* <TR>
* <TD>INITIALIZING</TD>
* <TD>a new broker is starting</TD>
* <TD>set by ClusterConfig.addBroker()</TD>
* </TR>
* <TR>
* <TD>OPERATING</TD>
* <TD>The broker is processing messages</TD>
* <TD>set by Broker at startup</TD>
* </TR>
* <TR>
* <TD>QUIESCE_STARTED</TD>
* <TD>The broker has started to quiesce, this means that new jms connections will not longer be accepted</TD>
* <TD>called by BrokerStateHandler.quiesce()</TD>
* </TR>
* <TR>
* <TD>QUIESCE_COMPLETED</TD>
* <TD>Quiesce has completed, this means that all jms connections have exited, the broker can not be safely
* shutdown.</TD>
* <TD>called by BrokerStateHandler.quiesce()</TD>
* </TR>
* <TR>
* <TD>SHUTDOWN_STARTED</TD>
* <TD>The broker is starting to shutdown. It may shutdown immediately or wait some period of time</TD>
* <TD>set by BrokerStateHandler.shutdown()</TD>
* </TR>
* <TR>
* <TD>SHUTDOWN_FAILOVER</TD>
* <TD>the broker has finished shutting down, all resources have been released it should be taken over (the broker may
* or may not shutdown, depending on whether it is running inprocess)</TD>
* <TD>set by BrokerStateHandler.shutdown()</TD>
* </TR>
* <TR>
* <TD>SHUTDOWN_COMPLETE</TD>
* <TD>the broker has finished shutting down, all resources have been released but is should NOT be taken over (the
* broker may or may not shutdown, depending on whether it is running inprocess)</TD>
* <TD>set by BrokerStateHandler.shutdown()</TD>
* </TR>
* <TR>
* <TD>FAILOVER_PENDING</TD>
* <TD>a takeover is pending (not stored to disk)
* <TD>set by the TakeoverThread of HAMonitorService()</TD>
* </TR>
* <TR>
* <TD>FAILOVER_STARTED</TD>
* <TD>another broker in the cluster has started to takeover the state of this broker (the broker handling takeover can
* be retrieved with HAClusteredBroker.getTakeoverBroker()</TD>
* <TD>set by the TakeoverThread of HAMonitorService()</TD>
* </TR>
* <TR>
* <TD>FAILOVER_COMPLETE</TD>
* <TD>takeover of a broker has completed</TD>
* <TD>set by the TakeoverThread of HAMonitorService()</TD>
* </TR>
* <TR>
* <TD>FAILOVER_FAILED</TD>
* <TD>a takeover failed (not stored to disk)
* <TD>set by the TakeoverThread of HAMonitorService()</TD>
* </TR>
* </TABLE>
* <P>
* <b>NOTE:</b>
* <UL>
* <LI>in the non-ha case, states remain in memory</LI>
* <LI>for HA, states are stored to the database</LI>
* </UL>
*
* <p>
* <b>XXX-TBD:</b> should we store a string or letter not an int in jdbc for readability.
*
*
*/
public class BrokerState {
/**
* descriptive string associated with the state
*/
private final String name;
/**
* int value for the state used when the state is stored in the jdbc store.
*/
private final int value;
/**
* value for INITIALIZING used when the state is stored in the jdbc store.
*/
public static final int I_INITIALIZING = 0;
/**
* value for OPERATING used when the state is stored in the jdbc store.
*/
public static final int I_OPERATING = 1;
/**
* value for QUIESCE_STARTED used when the state is stored in the jdbc store.
*/
public static final int I_QUIESCE_STARTED = 2;
/**
* value for QUIESCE_COMPLETE used when the state is stored in the jdbc store.
*/
public static final int I_QUIESCE_COMPLETED = 3;
/**
* value for SHUTDOWN_STARTED used when the state is stored in the jdbc store.
*/
public static final int I_SHUTDOWN_STARTED = 4;
/**
* value for SHUTDOWN_COMPLETE used when the state is stored in the jdbc store.
*/
public static final int I_SHUTDOWN_FAILOVER = 5;
/**
* value for SHUTDOWN_COMPLETE used when the state is stored in the jdbc store.
*/
public static final int I_SHUTDOWN_COMPLETE = 6;
/**
* value for FAILOVER_PENDING
*/
public static final int I_FAILOVER_PENDING = 9;
/**
* value for FAILOVER_STARTED used when the state is stored in the jdbc store.
*/
public static final int I_FAILOVER_STARTED = 7;
/**
* value for FAILOVER_COMPLETE used when the state is stored in the jdbc store.
*/
public static final int I_FAILOVER_COMPLETE = 8;
/**
* value for FAILOVER_FALIED
*/
public static final int I_FAILOVER_FAILED = 10; // not stored
/**
* value for FAILOVER_PROCESSED
*/
public static final int I_FAILOVER_PROCESSED = 11; // not stored
/**
* value for FAILOVER_PREPARED //4.6, BDB store only
*/
public static final int I_FAILOVER_PREPARED = 12;
/**
* mapping of jdbc values to BrokerStates
*/
private static BrokerState[] bs = new BrokerState[13];
/**
* private constructor for BrokerState
*/
private BrokerState(String name, int value) {
this.name = name;
this.value = value;
bs[value] = this;
}
public static List getAllStates() {
return Arrays.asList(bs);
}
/**
* method which takes an int (retrieved from the persistent store) and converts it to a state
*/
public static BrokerState getState(int value) {
return bs[value];
}
/**
* method which returns the int value associated with the state. This method should only be used when the state is
* stored in the jdbc store or during the INFO_REQUEST protocol.
*/
public int intValue() {
return value;
}
/**
* a string representation of the object
*/
@Override
public String toString() {
return "BrokerState[" + name + "]";
}
/**
* method which return true if it is in an active state
*/
public boolean isActiveState() {
boolean notRunning = (value == BrokerState.I_FAILOVER_COMPLETE || value == BrokerState.I_SHUTDOWN_FAILOVER || value == BrokerState.I_SHUTDOWN_COMPLETE);
return !notRunning;
}
/**
* State when a new broker is added to the cluster.
*/
public static final BrokerState INITIALIZING = new BrokerState("INITIALIZING", I_INITIALIZING);
/**
* State used to indicate that the broker is actively processing messages.
*/
public static final BrokerState OPERATING = new BrokerState("OPERATING", I_OPERATING);
/**
* State when a broker has stopped accepting new connections. This means that the broker is being prepared for a safe
* shutdown.
*/
public static final BrokerState QUIESCE_STARTED = new BrokerState("QUIESCE_STARTED", I_QUIESCE_STARTED);
/**
* State when a broker has no remaining jms connections or non-persistent messages after quiesce has been called. The
* broker may now be safely shutdown without losing non-persistent messages.
*/
public static final BrokerState QUIESCE_COMPLETED = new BrokerState("QUIESCE_COMPLETED", I_QUIESCE_COMPLETED);
/**
* The broker has started shutdown processing.
*/
public static final BrokerState SHUTDOWN_STARTED = new BrokerState("SHUTDOWN_STARTED", I_SHUTDOWN_STARTED);
/**
* The broker has started shutdown processing.
*/
public static final BrokerState SHUTDOWN_FAILOVER = new BrokerState("SHUTDOWN_FAILOVER", I_SHUTDOWN_FAILOVER);
/**
* The broker has completed shutdown processing and is about to exit.
*/
public static final BrokerState SHUTDOWN_COMPLETE = new BrokerState("SHUTDOWN_COMPLETE", I_SHUTDOWN_COMPLETE);
/**
* Another broker is about to be taken over
*/
public static final BrokerState FAILOVER_PENDING = new BrokerState("FAILOVER_PENDING", I_FAILOVER_PENDING);
/**
* Another broker has begun to take over this brokers store.
*/
public static final BrokerState FAILOVER_STARTED = new BrokerState("FAILOVER_STARTED", I_FAILOVER_STARTED);
/**
* The failover of a broker has completed. A new broker is now handling all of the brokers persistent state, this
* includes all messages to non-local destinations and the responsibility to reap transactions as necessary.
*/
public static final BrokerState FAILOVER_COMPLETE = new BrokerState("FAILOVER_COMPLETE", I_FAILOVER_COMPLETE);
/**
* The store migration has been prepared by the target broker - used only by BDB store
*/
public static final BrokerState FAILOVER_PREPARED = new BrokerState("FAILOVER_PREPARED", I_FAILOVER_PREPARED);
/**
* The failover of a broker has been processed.
*/
public static final BrokerState FAILOVER_PROCESSED = new BrokerState("FAILOVER_PROCESSED", I_FAILOVER_PROCESSED);
/**
* The failover of a broker failed for some reason (somone else may have taken over the store)
*/
public static final BrokerState FAILOVER_FAILED = new BrokerState("FAILOVER_FAILED", I_FAILOVER_FAILED);
}