-
Notifications
You must be signed in to change notification settings - Fork 33
/
Globals.java
1096 lines (913 loc) · 37.9 KB
/
Globals.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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* 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;
import java.util.Set;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.HashMap;
import java.util.Locale;
import java.util.Properties;
import java.net.InetAddress;
import com.sun.messaging.jmq.jmsserver.data.PacketRouter;
import com.sun.messaging.jmq.jmsserver.service.ConnectionManager;
import com.sun.messaging.jmq.jmsservice.BrokerEvent;
import com.sun.messaging.jmq.jmsserver.service.ServiceManager;
import com.sun.messaging.jmq.jmsserver.resources.BrokerResources;
import com.sun.messaging.jmq.jmsserver.management.mbeans.resources.MBeanResources;
import com.sun.messaging.jmq.jmsserver.service.PortMapper;
import com.sun.messaging.jmq.jmsserver.core.BrokerAddress;
import com.sun.messaging.jmq.jmsserver.core.DestinationList;
import com.sun.messaging.jmq.jmsserver.cluster.api.*;
import com.sun.messaging.jmq.jmsserver.util.BrokerException;
import com.sun.messaging.jmq.jmsserver.util.BrokerShutdownRuntimeException;
import com.sun.messaging.jmq.jmsserver.config.BrokerConfig;
import com.sun.messaging.jmq.jmsserver.cluster.api.ha.*;
import com.sun.messaging.jmq.jmsserver.config.PropertyUpdateException;
import com.sun.messaging.jmq.jmsserver.persist.api.Store;
import com.sun.messaging.jmq.jmsserver.persist.api.StoreManager;
import com.sun.messaging.jmq.jmsserver.service.MetricManager;
import com.sun.messaging.jmq.jmsserver.memory.MemoryManager;
import com.sun.messaging.jmq.util.log.Logger;
import com.sun.messaging.jmq.util.timer.MQTimer;
import com.sun.messaging.jmq.Version;
import com.sun.messaging.jmq.io.MQAddress;
import com.sun.messaging.jmq.io.Status;
import com.sun.messaging.jmq.jmsserver.management.agent.Agent;
import com.sun.messaging.jmq.util.UID;
import com.sun.messaging.bridge.api.BridgeServiceManager;
import com.sun.messaging.jmq.jmsserver.plugin.spi.CoreLifecycleSpi;
import com.sun.messaging.jmq.jmsserver.data.protocol.Protocol;
import com.sun.messaging.jmq.jmsserver.comm.CommGlobals;
import com.sun.messaging.portunif.PUService;
import com.sun.messaging.jmq.jmsserver.tlsutil.KeystoreUtil;
/**
* Singleton class which contains any Globals for the system.
* <P>
*
* Other singleton classes which can be considered static once they are retrieved (they do not need to be retrieved from
* the static method each time they are used) should also be defined here
* <P>
*/
public final class Globals extends CommGlobals {
/**
* Hostname that signifies bind-to-all interfaces
*/
public static final String HOSTNAME_ALL = "*";
/**
* the thread pool OutOfMemory Error handler (if any)
*/
private static GlobalErrorHandler errhandler = null;
private static volatile Globals globals = null;
private static Protocol protocol = null;
private static volatile MBeanResources mbr = null;
private volatile static Version version = null;
private static volatile PUService puService = null;
private static volatile PortMapper portMapper = null;
private static MQAddress mqAddress = null;
private static ServiceManager serviceManager = null;
private static ConnectionManager connectionManager = null;
private static ClusterBroadcast messageBus = null;
private static Object heartbeatService = null;
private static MetricManager metricManager = null;
private static volatile MQTimer timer = null;
private static volatile Boolean HAEnabled = null;
private static volatile Boolean useSharedConfigRecord = null;
private static String clusterID = null;
private static UID HAStoreSession = new UID(-1);
private static UID brokerSession = null;
private static String brokerID = null;
private static String hostname = null;
private static String jmxHostname = null;
private static BrokerAddress myaddr = null;
private static InetAddress brokerInetAddress = null;
private static InetAddress jmxInetAddress = null;
private static PacketRouter[] routers = null;
private static volatile MemoryManager mem_manager = null;
private static boolean useMem = true;
private static Agent agent = null;
private static BrokerStateHandler stateHandler = null;
private static HAMonitorService hasvc = null;
public static final String INTERNAL_PREFIX = "MQ_";
// ------------------------------------------------------------------------
// -- static brokerConfig objects --
// ------------------------------------------------------------------------
/**
* singleton instance of ClusterManager
*/
private static ClusterManager clusterConfig = null;
private static volatile CoreLifecycleSpi coreLifecycle = null;
private static HashMap<String, CoreLifecycleSpi> corePlugins = new HashMap<>();
private static BridgeServiceManager bridgeManager = null;
private static boolean apiDirectTwoThreadSyncReplies = true;
public static void cleanup() {
cleanupComm();
clusterConfig = null;
coreLifecycle = null;
corePlugins.clear();
globals = null;
myaddr = null;
version = null;
puService = null;
portMapper = null;
mqAddress = null;
serviceManager = null;
connectionManager = null;
messageBus = null;
heartbeatService = null;
metricManager = null;
timer = null;
HAEnabled = null;
useSharedConfigRecord = null;
clusterID = null;
HAStoreSession = null;
brokerID = null;
hostname = null;
jmxHostname = null;
brokerInetAddress = null;
jmxInetAddress = null;
routers = null;
mem_manager = null;
agent = null;
stateHandler = null;
bridgeManager = null;
apiDirectTwoThreadSyncReplies = true;
}
private Globals() {
}
/**
* Return whether the property imq.cluster.masterbroker was specified on the command line or read from standard input
*/
public static boolean isMasterBrokerSpecified() {
Properties params = getParameters();
if (params == null) {
return false;
}
return (params.get(ClusterManager.CONFIG_SERVER) != null);
}
public static void setMemMgrOn(boolean setting) {
useMem = setting;
}
public static MemoryManager getMemManager() {
if (!useMem) {
return null;
}
if (mem_manager == null) {
synchronized (lock) {
if (mem_manager == null) {
mem_manager = new MemoryManager();
}
}
}
return mem_manager;
}
public static void setAgent(Agent ag) {
agent = ag;
}
public static Agent getAgent() {
return (agent);
}
public static String getPrimaryOwnerName() {
return (Globals.getConfig().getProperty(PRIMARY_OWNER_NAME_PROPERTY, System.getProperty("user.name")));
}
public static String getPrimaryOwnerContact() {
return (Globals.getConfig().getProperty(PRIMARY_OWNER_CONTACT_PROPERTY, System.getProperty("user.name")));
}
public static String[] getBrokerAdminDefinedRoles() {
String countPropName = BROKER_ADMIN_DEFINED_ROLES_PROPERTY_BASE + ".count";
String countStr = Globals.getConfig().getProperty(countPropName);
int count = 0;
if ((countStr == null) || (countStr.equals(""))) {
return (getDefaultBrokerAdminDefinedRoles());
}
try {
count = Integer.parseInt(countStr);
} catch (Exception e) {
Logger logger = getLogger();
logger.log(Logger.WARNING, "Invalid value for property " + countPropName + ": " + countStr);
return (getDefaultBrokerAdminDefinedRoles());
}
if (count == 0) {
return (getDefaultBrokerAdminDefinedRoles());
}
String ret[] = new String[count];
for (int i = 0; i < count; ++i) {
String propName = BROKER_ADMIN_DEFINED_ROLES_PROPERTY_BASE + ".name" + i;
ret[i] = getConfig().getProperty(propName);
}
return (ret);
}
public static String[] getDefaultBrokerAdminDefinedRoles() {
/*
* Default admin defined role is simply the broker instance name.
*/
String[] ret = { getConfig().getProperty("imq.instancename") };
return (ret);
}
public static void setProtocol(Protocol impl) {
protocol = impl;
}
public static Protocol getProtocol() {
return protocol;
}
public static void setBrokerStateHandler(BrokerStateHandler sh) {
stateHandler = sh;
}
public static BrokerStateHandler getBrokerStateHandler() {
return (stateHandler);
}
public static void setHAMonitorService(HAMonitorService sh) {
hasvc = sh;
}
public static HAMonitorService getHAMonitorService() {
return (hasvc);
}
public static void setBridgeServiceManager(BridgeServiceManager bm) {
bridgeManager = bm;
}
public static BridgeServiceManager getBridgeServiceManager() {
return (bridgeManager);
}
public static boolean bridgeEnabled() {
return BridgeBaseContextAdapter.bridgeEnabled();
}
public static Globals getGlobals() {
if (globals == null) {
synchronized (lock) {
if (globals == null) {
globals = new Globals();
}
}
}
return globals;
}
public static MQTimer getTimer() {
return getTimer(false);
}
public static MQTimer getTimer(boolean purge) {
if (timer == null) {
synchronized (lock) {
if (timer == null) {
timer = new MQTimer(true);
timer.setLogger(getLogger());
timer.initUncaughtExceptionHandler();
}
}
}
if (purge) {
timer.purge();
}
return timer;
}
public static MBeanResources getMBeanResources() {
if (mbr == null) {
synchronized (lock) {
if (mbr == null) {
mbr = MBeanResources.getResources(Locale.getDefault());
}
}
}
return mbr;
}
public static Version getVersion() {
if (version == null) {
synchronized (lock) {
if (version == null) {
version = new Version(false);
}
}
}
return version;
}
public static PUService getPUService() {
if (puService == null) {
synchronized (lock) {
if (puService == null) {
if (isPortUnifEnabled() && !isNucleusManagedBroker()) {
try {
Class c = Class.forName("com.sun.messaging.portunif.PUService");
puService = (PUService) c.getDeclaredConstructor().newInstance();
} catch (Exception e) {
getLogger().logStack(Logger.ERROR, e.getMessage(), e);
Broker.getBroker().exit(-1, "Internal Error: Unable to init PUService. Exiting", BrokerEvent.Type.FATAL_ERROR);
return null;
}
} else {
return null;
}
}
}
}
return puService;
}
public static boolean isPortUnifEnabled() {
return getConfig().getBooleanProperty(PUSERVICE_ENABLED_PROP, false);
}
public static PortMapper getPortMapper() {
if (portMapper == null) {
synchronized (lock) {
if (portMapper == null) {
portMapper = new PortMapper(getConfigName());
try {
portMapper.configure(getConfig());
// Force portmapper to attempt to bind to port
portMapper.bind();
} catch (Exception e) {
portMapper = null;
Logger logger = getLogger();
if (e instanceof PropertyUpdateException) {
logger.log(Logger.ERROR, e.getMessage());
} else {
logger.logStack(Logger.ERROR, e.getMessage(), e);
}
}
}
}
}
return portMapper;
}
/**
* Get the configured hostname. Can be null of imq.hostname is not configured.
*/
public static String getHostname() {
return hostname;
}
/**
* Get the configured hostname for JMX connections/traffic. Can be null if imq.jmx.hostname or imq.hostname is not
* configured.
*/
public static String getJMXHostname() {
if (jmxHostname != null) {
return jmxHostname;
}
return (getHostname());
}
public static boolean isFileStore() {
return StoreManager.isConfiguredFileStore();
}
public static boolean isJDBCStore() {
return StoreManager.isConfiguredJDBCStore();
}
public static boolean getJDBCHAEnabled() {
return StoreManager.isConfiguredJDBCStore() && getHAEnabled();
}
public static boolean getHAEnabled() {
if (HAEnabled == null) {
BrokerConfig conf = getConfig();
boolean isHA = conf.getBooleanProperty(HA_ENABLED_PROPERTY, HA_ENABLED_DEFAULT);
String clusterID = conf.getProperty(Globals.CLUSTERID_PROPERTY);
synchronized (lock) {
if (HAEnabled == null) {
if (isHA) {
if (clusterID == null || clusterID.length() == 0) {
throw new RuntimeException(getBrokerResources().getKString(BrokerResources.X_CID_MUST_BE_SET_HA));
}
Globals.HAEnabled = Boolean.TRUE;
Globals.clusterID = clusterID;
} else {
if (clusterID != null && clusterID.length() != 0) {
Globals.clusterID = clusterID;
}
Globals.HAEnabled = Boolean.FALSE;
}
}
}
}
return HAEnabled.booleanValue();
}
public static ServiceManager getServiceManager() {
return serviceManager;
}
public static MetricManager getMetricManager() {
return metricManager;
}
/** @throws BrokerShutdownRuntimeException */
public static ConnectionManager getConnectionManager() {
ConnectionManager cm = connectionManager;
if (cm != null) {
return cm;
}
throw new BrokerShutdownRuntimeException(getBrokerResources().getKString(BrokerResources.W_BROKER_IS_SHUTDOWN));
}
public static ClusterBroadcast getClusterBroadcast() {
return messageBus;
}
public static void setHostname(String hostname) {
Globals.hostname = hostname;
}
public static void setJMXHostname(String hostname) {
Globals.jmxHostname = hostname;
}
public static String getClusterID() {
return clusterID;
}
public static UID getStoreSession() throws BrokerException {
if (HAStoreSession == null || HAStoreSession.longValue() == -1) {
String emsg = BrokerResources.E_INTERNAL_ERROR + "Globals.getStoreSession(): HA store session UID has not been initialized";
BrokerException be = new BrokerException(emsg);
Globals.getLogger().logStack(Logger.ERROR, emsg, be);
throw be;
}
return HAStoreSession;
}
public static void setStoreSession(UID uid) {
HAStoreSession = uid;
}
public static UID getBrokerSessionID() {
return brokerSession;
}
public static String getBrokerID() {
if (brokerID == null) {
brokerID = getConfig().getProperty(BROKERID_PROPERTY, getConfig().getProperty(JDBCBROKERID_PROPERTY));
// XXX if brokerID is still null, should we use instancename
}
return Globals.brokerID;
}
public static String getIdentityName() {
String id = Globals.getBrokerID();
if (id != null) {
return id;
}
return getConfigName();
}
public static void setServiceManager(ServiceManager sm) {
serviceManager = sm;
}
public static void setMetricManager(MetricManager mm) {
metricManager = mm;
}
public static void setConnectionManager(ConnectionManager cm) {
connectionManager = cm;
}
public static void setClusterBroadcast(ClusterBroadcast mm) {
messageBus = mm;
}
public static void registerHeartbeatService(Object hbs) {
heartbeatService = hbs;
}
public static Object getHeartbeatService() {
return heartbeatService;
}
public static void setMyAddress(BrokerAddress mm) {
myaddr = mm;
setMyAddressObject(mm);
}
public static BrokerAddress getMyAddress() {
return myaddr;
}
/**
* Set the InetAddress for this broker.
*/
public static void setBrokerInetAddress(InetAddress ia) {
brokerInetAddress = ia;
}
/**
* Get the InetAddress for this broker. Must have been previously set
*/
public static InetAddress getBrokerInetAddress() {
return brokerInetAddress;
}
/**
* Set the InetAddress for JMX traffic.
*/
public static void setJMXInetAddress(InetAddress ia) {
jmxInetAddress = ia;
}
/**
* Get the InetAddress for JMX traffic. Must have been previously set
*/
public static InetAddress getJMXInetAddress() {
if (jmxInetAddress != null) {
return jmxInetAddress;
}
return (getBrokerInetAddress());
}
/**
* Get the hostname that this broker is running on. setBrokerInetAddress must be called before calling this method
* otherwise this routine will return null.
*/
public static String getBrokerHostName() {
if (hostname != null && !hostname.equals(Globals.HOSTNAME_ALL)) {
return hostname;
}
if (brokerInetAddress == null) {
return null;
} else {
// This is fast so we don't need to cache it.
return brokerInetAddress.getCanonicalHostName();
}
}
public static void setGlobalErrorHandler(GlobalErrorHandler handler) {
errhandler = handler;
}
public static void handleGlobalError(Throwable thr, String msg) {
handleGlobalError(thr, msg, null);
}
static void handleGlobalError(Throwable thr, String msg, Integer exitCode) {
if (!errhandler.handleGlobalError(thr, msg, exitCode)) {
logger.logStack(Logger.ERROR, BrokerResources.E_INTERNAL_BROKER_ERROR, "received unexpected exception ", thr);
Throwable trace = new Throwable();
trace.fillInStackTrace();
logger.logStack(Logger.DEBUG, "Calling stack trace", trace);
}
}
static void setPacketRouters(PacketRouter[] newrouters) {
routers = newrouters;
}
/** @throws IndexOutOfBoundsException */
public static PacketRouter getPacketRouter(int type) {
if (routers == null || type > routers.length) {
throw new IndexOutOfBoundsException(
getBrokerResources().getKString(BrokerResources.X_INTERNAL_EXCEPTION, "requested invalid packet router " + type));
}
return routers[type];
}
public static DestinationList getDestinationList() {
return getCoreLifecycle().getDestinationList();
}
public static CoreLifecycleSpi getCoreLifecycle() {
if (coreLifecycle == null) {
synchronized (lock) {
if (coreLifecycle == null) {
try {
coreLifecycle = new com.sun.messaging.jmq.jmsserver.core.CoreLifecycleImpl();
if (getConfig().getBooleanProperty(IMQ + ".core.plugin.coherenceMessagePattern.enabled", false)) {
Class c = Class.forName("com.sun.messaging.jmq.jmsserver.plugin.impl.msgpattern.MessagePatternCoreLifecycle");
CoreLifecycleSpi sub = (CoreLifecycleSpi) c.getDeclaredConstructor().newInstance();
corePlugins.put(sub.getType(), sub);
}
} catch (Exception e) {
getLogger().logStack(Logger.ERROR, e.getMessage(), e);
Broker.getBroker().exit(-1, "Internal Error: Unable to init core lifecycle. Exiting", BrokerEvent.Type.FATAL_ERROR);
}
}
}
}
return coreLifecycle;
}
public static CoreLifecycleSpi getCorePlugin(String type) {
return corePlugins.get(type);
}
/**
* @return true if uses NoClusterManager
*/
public static boolean initClusterManager(MQAddress address) throws BrokerException {
synchronized (lock) {
if (clusterConfig != null) {
return (clusterConfig instanceof NoClusterManager);
}
String classname = null;
if (getJDBCHAEnabled()) {
classname = getConfig().getProperty(Globals.IMQ + ".hacluster.jdbc.manager.class");
}
boolean deft = false;
String deftclassname = "com.sun.messaging.jmq.jmsserver.cluster.api.NoClusterManager";
if (classname == null) {
classname = getConfig().getProperty(Globals.IMQ + ".cluster.manager.class");
deft = true;
}
try {
if (Globals.isNucleusManagedBroker()) {
clusterConfig = Globals.getHabitat().getService(ClusterManager.class, classname);
if (clusterConfig == null && deft) {
logger.log(logger.WARNING, "ClassNotFound: " + classname);
classname = deftclassname;
clusterConfig = Globals.getHabitat().getService(ClusterManager.class, classname);
}
if (clusterConfig == null) {
throw new BrokerException("Class " + classname + " not found", Status.NOT_FOUND);
}
} else {
Class c = null;
try {
c = Class.forName(classname);
} catch (ClassNotFoundException e) {
logger.log(logger.WARNING, e.toString());
if (!deft) {
throw e;
}
classname = deftclassname;
c = Class.forName(classname);
}
clusterConfig = (ClusterManager) c.getDeclaredConstructor().newInstance();
}
clusterConfig.initialize(address);
mqAddress = address;
ClusteredBroker bkr = clusterConfig.getLocalBroker();
brokerSession = bkr.getBrokerSessionUID();
return (classname.equals(deftclassname));
} catch (Exception ex) {
if (ex instanceof BrokerException) {
throw (BrokerException) ex;
}
throw new BrokerException(getBrokerResources().getKString(BrokerResources.E_INITING_CLUSTER), ex);
}
}
}
public static ClusterManager getClusterManager() {
return clusterConfig;
}
public static Store getStore() throws BrokerException {
return StoreManager.getStore();
}
/**
* method to release the singleton Store instance
*/
public static void releaseStore() {
StoreManager.releaseStore(true); // always do clean up
}
public static void setMQAddress(MQAddress addr) {
ClusterManager c = getClusterManager();
try {
c.setMQAddress(addr);
} catch (Exception ex) {
logger.logStack(logger.ERROR, BrokerResources.E_INTERNAL_BROKER_ERROR, "Received bad address " + addr + " ignoring", ex);
return;
}
mqAddress = addr;
}
public static MQAddress getMQAddress() {
return mqAddress;
}
public static boolean nowaitForMasterBroker() {
return getConfig().getBooleanProperty(NOWAIT_MASTERBROKER_PROP, false);
}
public static boolean dynamicChangeMasterBrokerEnabled() {
return (getConfig().getBooleanProperty(DYNAMIC_CHANGE_MASTERBROKER_ENABLED_PROP, false));
}
public static boolean useMasterBroker() {
if (getHAEnabled()) {
return false;
}
if (useSharedConfigRecord()) {
return false;
}
return (getClusterManager().getMasterBroker() != null);
}
public static boolean useSharedConfigRecord() {
if (useSharedConfigRecord == null) {
synchronized (lock) {
if (useSharedConfigRecord == null) {
if (getHAEnabled()) {
useSharedConfigRecord = Boolean.FALSE;
} else {
boolean nomb = getConfig().getBooleanProperty(Globals.NO_MASTERBROKER_PROP, false);
if (nomb) {
if (getClusterID() == null) {
throw new RuntimeException(getBrokerResources().getKString(BrokerResources.X_CID_MUST_BE_SET_NOMASTER,
Globals.CLUSTERID_PROPERTY, Globals.NO_MASTERBROKER_PROP + "=true"));
}
useSharedConfigRecord = Boolean.TRUE;
} else {
useSharedConfigRecord = Boolean.FALSE;
}
}
}
}
}
return useSharedConfigRecord.booleanValue();
}
public static boolean isConfigForCluster() {
return (getHAEnabled() || getConfig().getProperty(AUTOCONNECT_CLUSTER_PROPERTY) != null
|| getConfig().getProperty(MANUAL_AUTOCONNECT_CLUSTER_PROPERTY) != null);
}
/*---------------------------------------------
* global static variables
*---------------------------------------------*/
public final static String KEYSTORE_USE_PASSFILE_PROP = Globals.IMQ + ".passfile.enabled", KEYSTORE_PASSDIR_PROP = Globals.IMQ + ".passfile.dirpath",
KEYSTORE_PASSFILE_PROP = Globals.IMQ + ".passfile.name";
/**
* If this property is set to true then the broker will read properties (including passwords) from standard input
*/
public static final String READ_PROPERTIES_FROM_STDIN = Globals.IMQ + ".readstdin.enabled";
// --------------------------------------------------------------
// HA property names
// --------------------------------------------------------------
/**
* The property name to retrieve this brokers id.
*/
public static final String BROKERID_PROPERTY = Globals.IMQ + ".brokerid";
/**
* The property name to retrieve this brokers id.
*/
public static final String JDBCBROKERID_PROPERTY = Globals.IMQ + ".persist.jdbc.brokerid";
/**
* The property name to retrieve the cluster's id.
*/
public static final String CLUSTERID_PROPERTY = Globals.IMQ + ".cluster.clusterid";
/**
* The property name to retrieve if HA is enabled.
*/
public static final String HA_ENABLED_PROPERTY = Globals.IMQ + ".cluster.ha";
public static final boolean HA_ENABLED_DEFAULT = false;
/**
* The property name for this broker's primary owner name. This defaults to the value of the system property user.name.
*
* Brokers can be run for different applications, for different projects, this property helps identify the person/owner
* of a particular broker. This is currently only used by JESMF.
*/
public static final String PRIMARY_OWNER_NAME_PROPERTY = Globals.IMQ + ".primaryowner.name";
/**
* The property name for this broker's primary owner contact info. This defaults to the value of the system property
* user.name.
*
* Brokers can be run for different applications, for different projects, this property helps identify the
* person/owner's contact info of a particular broker. This is currently only used by JESMF.
*/
public static final String PRIMARY_OWNER_CONTACT_PROPERTY = Globals.IMQ + ".primaryowner.contact";
/**
* Property base name for the admin defined roles for the broker. Example setting of this:
*
* imq.broker.adminDefinedRoles.count=2 imq.broker.adminDefinedRoles.name0=JMS provider for domain1 appserver instance
* on host myhost imq.broker.adminDefinedRoles.name1=Used by test harness running on host myhost
*
* This is currently used by JESMF.
*/
public static final String BROKER_ADMIN_DEFINED_ROLES_PROPERTY_BASE = Globals.IMQ + ".broker.adminDefinedRoles";
/**
* Property name for the install root for MQ.
*
* This is currently only used by JESMF.
*/
public static final String INSTALL_ROOT = Globals.IMQ + ".install.root";
public static final String NOWAIT_MASTERBROKER_PROP = IMQ + ".cluster.nowaitForMasterBroker";
public static final String DYNAMIC_CHANGE_MASTERBROKER_ENABLED_PROP = IMQ + ".cluster.dynamicChangeMasterBrokerEnabled";
public static final String NO_MASTERBROKER_PROP = IMQ + ".cluster.nomasterbroker";
public static final String AUTOCONNECT_CLUSTER_PROPERTY = IMQ + ".cluster.brokerlist";
public static final String MANUAL_AUTOCONNECT_CLUSTER_PROPERTY = IMQ + ".cluster.brokerlist.manual";
public static final String AUTOCLUSTER_BROKERMAP_CLASS_PROP = IMQ + ".cluster.autocluster.brokermapclass";
public static final String PUSERVICE_ENABLED_PROP = IMQ + ".portunif.enabled";
public static boolean txnLogEnabled() {
return StoreManager.txnLogEnabled();
}
public static boolean isNewTxnLogEnabled() {
return StoreManager.newTxnLogEnabled();
}
// whether non-transacted persistent message sent should be logged
private static volatile Boolean _logNonTransactedMsgSend = null;
public static final String LOG_NONTRANSACTEDMSGSEND_PROP = Globals.IMQ + ".persist.file.txnLog.nonTransactedMsgSend.enabled";
public static boolean logNonTransactedMsgSend() {
if (_logNonTransactedMsgSend == null) {
synchronized (lock) {
if (_logNonTransactedMsgSend == null) {
_logNonTransactedMsgSend = Boolean.valueOf(txnLogEnabled() && getConfig().getBooleanProperty(LOG_NONTRANSACTEDMSGSEND_PROP));
}
}
}
return _logNonTransactedMsgSend.booleanValue();
}
/**
* whether to use minimum write optimisations
*/
private static volatile Boolean _minimizeWritesFileStore = null;
private static volatile Boolean _minimizePersist = null;
private static volatile Boolean _minimizePersistLevel2 = null;
public static final String MINIMIZE_WRITES_FILESTORE_PROP = Globals.IMQ + ".persist.file.minimizeWrites";
public static final String MINIMIZE_PERSIST_PROP = Globals.IMQ + ".persist.minimizeWrites";
public static final String MINIMIZE_PERSIST_LEVEL2_PROP = Globals.IMQ + ".persist.minimizeWritesLevel2";
public static boolean isMinimumWritesFileStore() {
if (_minimizeWritesFileStore == null) {
synchronized (lock) {
if (_minimizeWritesFileStore == null) {
_minimizeWritesFileStore = Boolean.valueOf(getConfig().getBooleanProperty(MINIMIZE_WRITES_FILESTORE_PROP, false));
getLogger().log(Logger.INFO, MINIMIZE_WRITES_FILESTORE_PROP + "=" + _minimizeWritesFileStore);
}
}
}
return _minimizeWritesFileStore.booleanValue();
}
public static boolean isMinimumPersist() {
if (_minimizePersist == null) {
synchronized (lock) {
if (_minimizePersist == null) {
_minimizePersist = Boolean.valueOf(getConfig().getBooleanProperty(MINIMIZE_PERSIST_PROP, true));
getLogger().log(Logger.INFO, MINIMIZE_PERSIST_PROP + "=" + _minimizePersist);
}
}
}
if (isFileStore() && isMinimumWritesFileStore()) {
return true;
}
return _minimizePersist.booleanValue();
}
public static boolean isMinimumPersistLevel2() {
if (_minimizePersistLevel2 == null) {
synchronized (lock) {
if (_minimizePersistLevel2 == null) {
_minimizePersistLevel2 = Boolean.valueOf(getConfig().getBooleanProperty(MINIMIZE_PERSIST_LEVEL2_PROP, true));
if ((isNewTxnLogEnabled() || // for self doc
!isJDBCStore()) && _minimizePersistLevel2.booleanValue()) {
getLogger().log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.W_IGNORE_PROP_SETTING,
MINIMIZE_PERSIST_LEVEL2_PROP + "=" + _minimizePersistLevel2));
_minimizePersistLevel2 = Boolean.FALSE;
} else {
getLogger().log(Logger.INFO, MINIMIZE_PERSIST_LEVEL2_PROP + "=" + _minimizePersistLevel2);
}
}
}
}
return _minimizePersistLevel2.booleanValue();
}
/**
* whether delivery data is persisted
*/
private static volatile Boolean _deliveryStateNotPersisted = null;
public static final String DELIVERY_STATE_NOT_PERSITED_PROP = Globals.IMQ + ".persist.file.deliveryStateNotPersisted";
public static boolean isDeliveryStateNotPersisted() {