-
Notifications
You must be signed in to change notification settings - Fork 33
/
NoClusteredBroker.java
354 lines (314 loc) · 10.2 KB
/
NoClusteredBroker.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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
/*
* Copyright (c) 2000, 2017 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022 Contributors to the Eclipse Foundation
*
* 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 com.sun.messaging.jmq.io.MQAddress;
import com.sun.messaging.jmq.util.UID;
import com.sun.messaging.jmq.util.log.Logger;
import com.sun.messaging.jmq.jmsserver.Globals;
import com.sun.messaging.jmq.jmsserver.util.BrokerException;
public class NoClusteredBroker implements ClusteredBroker {
private Logger logger = Globals.getLogger();
// private BrokerResources br = Globals.getBrokerResources();
/**
* Name associated with this broker. For non-ha clusters it is of the form broker# and is not the same across all
* brokers in the cluster (although it is unique on this broker).
*/
String brokerName = null;
/**
* The portmapper for this broker.
*/
MQAddress address = null;
/**
* The instance name of this broker
*/
String instanceName = null;
/**
* Current status of the broker.
*/
Integer status = Integer.valueOf(BrokerStatus.BROKER_UNKNOWN);
/**
* Current state of the broker.
*/
BrokerState state = BrokerState.INITIALIZING;
/**
* Broker SessionUID for this broker. This uid changes on each restart of the broker.
*/
UID brokerSessionUID = null;
/**
* has brokerID been generated
*/
boolean isgen = false;
/**
* Create a instace of ClusteredBroker.
*
* @param url the portmapper address of this broker
*/
public NoClusteredBroker(MQAddress url, UID id) {
this.address = url;
brokerSessionUID = id;
brokerName = Globals.getBrokerID();
instanceName = Globals.getConfigName();
if (brokerName == null) {
isgen = true;
brokerName = "broker0";
}
}
@Override
public boolean equals(Object o) {
if (!(o instanceof ClusteredBroker)) {
return false;
}
return this.getBrokerName().equals(((ClusteredBroker) o).getBrokerName());
}
@Override
public int hashCode() {
return this.getBrokerName().hashCode();
}
/**
* String representation of this broker.
*/
@Override
public String toString() {
return brokerName + "* (" + address + ")";
}
/**
* a unique identifier assigned to the broker (randomly assigned).
* <P>
*
* This name is only unique to this broker. The broker at this URL may be assigned a different name on another broker in
* the cluster.
*
* @return the name of the broker
*/
@Override
public String getBrokerName() {
return brokerName;
}
/**
* the URL to the portmapper of this broker.
*
* @return the URL of this broker
*/
@Override
public MQAddress getBrokerURL() {
return address;
}
/**
* @return the instance name of this broker, null if not available
*/
@Override
public String getInstanceName() {
return instanceName;
}
/**
* @param instName Set the instance name of this broker, can be null
*/
@Override
public void setInstanceName(String instName) {
instanceName = instName;
}
/**
* sets the URL to the portmapper of this broker.
*
* @param address the URL of this broker
* @throws UnsupportedOperationException if this change can not be made on this broker
*/
@Override
public void setBrokerURL(MQAddress address) throws Exception {
this.address = address;
}
@Override
public boolean isLocalBroker() {
return true;
}
/**
* gets the status of the broker.
*
* @see BrokerStatus
* @return the status of the broker
*/
@Override
public synchronized int getStatus() {
return status.intValue();
}
/**
* gets the protocol version of the broker .
*
* @return the current cluster protocol version (if known) or 0 if not known
*/
@Override
public synchronized int getVersion() {
return 0;
}
@Override
public void setVersion(int version) throws Exception {
}
/**
* sets the status of the broker (and notifies listeners).
*
* @param newstatus the status to set
* @param userData optional user data associated with the status change
* @see ConfigListener
*/
@Override
public void setStatus(int newstatus, Object userData) {
// ok - for standalone case, adjust so that LINK_DOWN=DOWN
if (BrokerStatus.getBrokerIsDown(newstatus)) {
newstatus = BrokerStatus.setBrokerLinkIsDown(newstatus);
} else if (BrokerStatus.getBrokerLinkIsDown(newstatus)) {
newstatus = BrokerStatus.setBrokerIsDown(newstatus);
} else if (BrokerStatus.getBrokerLinkIsUp(newstatus)) {
newstatus = BrokerStatus.setBrokerIsUp(newstatus);
} else if (BrokerStatus.getBrokerIsUp(newstatus)) {
newstatus = BrokerStatus.setBrokerLinkIsUp(newstatus);
}
synchronized (this) {
this.status = Integer.valueOf(newstatus);
}
try {
if (BrokerStatus.getBrokerIsUp(newstatus)) {
setState(BrokerState.OPERATING);
}
if (BrokerStatus.getBrokerIsDown(newstatus)) {
setState(BrokerState.SHUTDOWN_COMPLETE);
}
} catch (Exception ex) {
logger.logStack(Logger.DEBUG, "Error setting state ", ex);
}
}
/**
* Updates the BROKER_UP bit flag on status.
*
* @param userData optional user data associated with the status change
* @param up setting for the bit flag (true/false)
*/
@Override
public void setBrokerIsUp(boolean up, UID brokerSession, Object userData) {
synchronized (this) {
if (up) {
int newStatus = BrokerStatus.setBrokerIsUp(this.status.intValue());
status = Integer.valueOf(newStatus);
} else {
int newStatus = BrokerStatus.setBrokerIsDown(this.status.intValue());
status = Integer.valueOf(newStatus);
}
}
try {
if (up) {
setState(BrokerState.OPERATING);
} else {
setState(BrokerState.SHUTDOWN_COMPLETE);
}
} catch (Exception ex) {
logger.logStack(Logger.DEBUG, "Error setting state ", ex);
}
}
/**
* Updates the BROKER_LINK_UP bit flag on status.
*
* @param userData optional user data associated with the status change
* @param up setting for the bit flag (true/false)
*/
@Override
public void setBrokerLinkUp(boolean up, Object userData) {
synchronized (this) {
int newStatus = 0;
if (up) {
newStatus = BrokerStatus.setBrokerLinkIsUp(BrokerStatus.setBrokerIsUp(this.status.intValue()));
} else {
newStatus = BrokerStatus.setBrokerLinkIsDown(BrokerStatus.setBrokerIsDown(this.status.intValue()));
}
this.status = Integer.valueOf(newStatus);
}
try {
if (up) {
setState(BrokerState.OPERATING);
} else {
setState(BrokerState.SHUTDOWN_COMPLETE);
}
} catch (Exception ex) {
logger.logStack(Logger.DEBUG, "Error setting state ", ex);
}
}
/**
* Updates the BROKER_INDOUBT bit flag on status.
*
* @param userData optional user data associated with the status change
* @param up setting for the bit flag (true/false)
*/
@Override
public void setBrokerInDoubt(boolean up, Object userData) {
throw new UnsupportedOperationException("Unexpected call: " + getClass().getName() + ".setBrokerInDoubt()");
}
/**
* marks this broker as destroyed. This is equivalent to setting the status of the broker to DOWN.
*
* @see BrokerStatus#DOWN
*/
@Override
public void destroy() {
synchronized (this) {
status = Integer.valueOf(BrokerStatus.setBrokerIsDown(status.intValue()));
}
}
/**
* gets the state of the broker .
*
* @return the current state
*/
@Override
public BrokerState getState() {
return state;
}
/**
* sets the state of the broker (and notifies any listeners).
*
* @throws IllegalAccessException if the broker does not have permission to change the broker (e.g. one broker is
* updating anothers state).
* @throws IllegalStateException if the broker state changed unexpectedly.
* @throws IllegalArgumentException if the state is not supported for this cluster type.
* @param state the state to set for this broker
* @see ConfigListener
*/
@Override
public void setState(BrokerState state) throws IllegalAccessException {
this.state = state;
}
/**
* Is the broker static or dynmically configured
*/
@Override
public boolean isConfigBroker() {
return true;
}
@Override
public synchronized UID getBrokerSessionUID() {
return brokerSessionUID;
}
@Override
public synchronized void setBrokerSessionUID(UID session) {
brokerSessionUID = session;
}
@Override
public boolean isBrokerIDGenerated() {
return isgen;
}
@Override
public String getNodeName() throws BrokerException {
throw new UnsupportedOperationException("Unexpected call: " + getClass().getName() + ".getNodeName()");
}
}