-
Notifications
You must be signed in to change notification settings - Fork 33
/
LifecycleManagedBroker.java
1698 lines (1523 loc) · 72.9 KB
/
LifecycleManagedBroker.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, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2020 Payara Services Ltd.
*
* 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.jms.blc;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;
import jakarta.jms.Connection;
import jakarta.jms.DeliveryMode;
import jakarta.jms.JMSException;
import jakarta.jms.Message;
import jakarta.jms.MessageConsumer;
import jakarta.jms.MessageProducer;
import jakarta.jms.ObjectMessage;
import jakarta.jms.Queue;
import jakarta.jms.Session;
import javax.management.remote.JMXServiceURL;
import jakarta.resource.spi.ResourceAdapterInternalException;
import com.sun.messaging.AdminConnectionConfiguration;
import com.sun.messaging.jmq.admin.bkrutil.BrokerConstants;
import com.sun.messaging.jmq.jmsserver.Globals;
import com.sun.messaging.jmq.jmsservice.JMSService;
import com.sun.messaging.jmq.jmsspi.PropertiesHolder;
import com.sun.messaging.jmq.util.admin.MessageType;
import com.sun.messaging.jmq.util.service.PortMapperClientHandler;
import com.sun.messaging.jms.ra.ResourceAdapter;
/**
* An instance of this class represents a broker whose lifecycle is managed by this broker. <br/>
* <br/>
* To use this class,<br/>
* <ul>
* <li>create an instance</li>
* <li>configure it by setting the required javabean properties</li>
* <li>call {@link #start() start} to start the broker</li>
* <li>call {@link #stop() stop} to shut down the broker</li>
* </ul>
*
*
*/
public class LifecycleManagedBroker {
/**
* Pass this value to setBrokerType() to specify that the broker type is REMOTE.<br/>
* This means that this instance will not manage a broker. Calling start() and stop() will have no effect.
*/
public static final String BROKER_TYPE_REMOTE = "REMOTE";
/**
* Pass this value to setBrokerType() to specify that the broker type is LOCAL.<br/>
* This means that when start() is called a broker will be started in a separate JVM, and a subsequent call to stop()
* will shut it down
*/
public static final String BROKER_TYPE_LOCAL = "LOCAL";
/**
* Pass this value to setBrokerType() to specify that the broker type is EMBEDDED.<br/>
* This means that when start() is called a broker will be started in the same JVM.<br/>
* Clients running in this JVM will connect to it using TCP connections.<br/>
* <b>Note, however, that currently if this value is specified then DIRECT will be used instead</b><br/>
*/
public static final String BROKER_TYPE_EMBEDDED = "EMBEDDED";
/**
* Pass this value to setBrokerType() to specify that the broker type is DIRECT.<br/>
* This means that when start() is called a broker will be started in the same JVM.<br/>
* Clients running in this JVM will connect to it using direct (non-TCP) connections.DB. <br/>
*/
public static final String BROKER_TYPE_DIRECT = "DIRECT";
/* Loggers */
private static final String _className = "com.sun.messaging.jms.ra.LifecycleManagedBroker";
private static final String _lgrNameLifecycle = "javax.resourceadapter.mqjmsra.lifecycle";
private static final Logger _loggerL = Logger.getLogger(_lgrNameLifecycle);
private static final String _lgrMIDPrefix = "MQJMSRA_RA";
private static final String _lgrMID_INF = _lgrMIDPrefix + "1101: ";
private static final String _lgrMID_WRN = _lgrMIDPrefix + "2001: ";
private static final String _lgrMID_ERR = _lgrMIDPrefix + "3001: ";
private static final String _lgrMID_EXC = _lgrMIDPrefix + "4001: ";
// private fields related to broker lifecycle
private EmbeddedBrokerRunner ebr = null;
private LocalBrokerRunner lbr = null;
// JMSService object used by RADirect clients
// This is for use by DirectConnectionFactory#_createConnectionId
// when _getJMSService() doesn't work. This seems to be here as a quick and dirty fix to a bug
// and it would be good to get rid of this
private static JMSService jmsservice = null;
// private fields used to keep track of current state
private boolean started;
/*
* whether a the lifecycle managed broker should start a PortMapper thread listening on the configured PortMapper port
*/
private boolean doBind = true;
/* Globally started at least once data */
private static boolean _startedAtLeastOnce;
private static int _rmiRegistryPort;
/* Indicate type for broker lifecycle control */
private String brokerType = LifecycleManagedBroker.BROKER_TYPE_REMOTE;
/**
* Specifies the instance name of the lifecycle managed broker.<br/>
* For an embedded broker this sets the <tt>-name</tt> broker argument.<br/>
* In the case of a local broker this is used to specify the logfile directory
*/
private String brokerInstanceName = "imqbroker"; // Default is 'imqbroker'
/*
* The admin userName to be used for JMX connections
*/
private String adminUsername = "admin";
/*
* The admin password to be used for JMX connections
*/
private String adminPassword = null;
/**
* the brokerBindAddress for the lifecycle managed broker.<br/>
* This specifies the network address that the broker must bind to and is typically needed in cases where two or more
* hosts are available (such as when more than one network interface card is installed in a computer), If null, the
* broker will bind to all addresses on the host machine.<br/>
* <br/>
* This is used to set the <tt>imq.hostname</tt> property
*/
private String brokerBindAddress = null; // Default is 'all addresses'
/*
* Indicate the port for the Rmi Registry in the broker when its lifecycle is controlled by the RA
*/
private int rmiRegistryPort = 1099;
/*
* Indicate whether the broker should start its own RMI Registry its lifecycle is controlled by the RA
*/
private boolean startRmiRegistry = false;
/* The JMXServiceURL String that can be used to acquire JMX connections */
private String jmxServiceURL = null;
/* Indicate main port for broker when its lifecycle is controlled by the RA */
private int brokerPort = 7676;
/**
* Specifies the brokerHomeDir of the lifecycle managed broker.<br/>
* For an embedded broker this sets the <tt>-imqhome</tt> broker argument.<br/>
* In the case of a local broker this must be set to the parent of the <tt>bin</tt> directory containing the broker
* executable.
*/
private String brokerHomeDir = null;
/*
* Indicate Lib Directory for broker when its lifecycle is controlled by the RA
*/
private String brokerLibDir = null;
/**
* the location of the var directory of the lifecycle managed broker.
*/
private String brokerVarDir = null;
/*
* * The brokerJavaDir of the lifecycle managed broker.<br/> This is used in the case of a local broker to set the
* <-tt>javahome</tt> argument passed to the broker executable and must be set to a directory containg a Java JRE<tt/>
* It is not used in the case of an embedded broker.
*/
private String brokerJavaDir = null;
/**
* Additional command-line arguments for the lifecycle managed broker
*/
private String brokerArgs = null;
/*
* Indicate whether the JNDI form of the JMXServiceURL is to be used in the broker when its lifecycle is controlled by
* the RA
*/
private boolean useJNDIRmiServiceURL = true;
/*
* Indicate whether SSL must be used for the JMXConnector in the broker when its lifecycle is controlled by the RA
*/
private boolean useSSLJMXConnector = true;
/**
* If set this is used to set the broker property imq.cluster.nowaitForMasterBrokerTimeoutInSeconds
*/
private int nowaitForMasterBrokerTimeoutInSeconds = -1;
/**
* The broker identifier of the lifecycle managed broker. For brokers using HA, which use a shared JDBC-based data
* store, this string is appended to the names of all database tables to identify each table with a particular broker.
* It is not required for non-HA brokers.
*/
private String brokerId = null;
/**
* The maximum time allowed in ms for a local broker to start. Default = 10000ms
*/
private int brokerStartTimeout = 20000;
/*
* The admin password file to be used when starting the broker w/ admin user/password checking
*/
private String adminPassFile = null;
/**
* Specifies whether the lifecycle managed broker is part of a HA (enhanced) cluster
*/
private boolean brokerEnableHA = false;
/**
* The cluster identifier for the lifecycle managed broker
*/
private String clusterId = null;
/**
* The database type for the lifecycle managed broker. Possible values are define dby the constants DB_TYPE_DERBY,
* DB_TYPE_ORACLE, DB_TYPE_POINTBASE and DB_TYPE_CLOUDSCAPE
*/
private String dbType = null;
/**
* If the lifecycle managed broker is to be part of a non-HA clusters, specifies a list of broker addresses belonging to
* the cluster.
*/
private String connectionURL = "";
// possible values of dbType
/** Pass this value to setDbType to specify that the database type is Derby */
public static final String DB_TYPE_DERBY = "derby";
/** Pass this value to setDbType to specify that the database type is MYSQL */
public static final String DB_TYPE_MYSQL = "mysql";
/** Pass this value to setDbType to specify that the database type is Oracle */
public static final String DB_TYPE_ORACLE = "oracle";
/**
* Pass this value to setDbType to specify that the database type is Pointbase
*/
public static final String DB_TYPE_POINTBASE = "pointbase";
/**
* Pass this value to setDbType to specify that the database type is Cloudscape
*/
public static final String DB_TYPE_CLOUDSCAPE = "cloudscape";
/* private constants */// Broker common defs
private static String IMQ_BROKERID = "imq.brokerid";
private static String IMQ_JDBC_VENDOR = "imq.persist.jdbc.dbVendor";
// MYSQL Properties that are passed into this class using setDBProps()
private static String MYSQL_USER = DB_TYPE_MYSQL + ".user";
private static String MYSQL_PASSWORD = DB_TYPE_MYSQL + ".password";
private static String MYSQL_URL = DB_TYPE_MYSQL + "property.url";
// general DB Properties that are passed into this class using setDBProps()
private static String FALLBACK_DATABASE_PASSWORD = "jdbc.password";
// Properties to be passed to a managed broker
private static String IMQ_MYSQL = "imq.persist.jdbc.mysql";
private static String IMQ_MYSQL_DSPROP = IMQ_MYSQL + ".property";
private static String IMQ_MYSQL_USER = IMQ_MYSQL + ".user";
private static String IMQ_MYSQL_PASSWORD = IMQ_MYSQL + ".password";
private static String IMQ_MYSQL_DSPROP_URL = IMQ_MYSQL_DSPROP + ".url";
// general DB Properties that are passed to a managed broker
private static String IMQ_FALLBACK_DATABASE_PASSWORD = "imq.persist.jdbc.password";
/**
* database type-specific config properties for the lifecycle managed broker
*/
private Properties dbProps = new Properties();
/**
* Broker properties for the lifecycle managed broker
*/
private Properties brokerProps = new Properties();
/**
* dataSource-specific properties for the lifecycle-managed broker
*/
private Properties dsProps = new Properties();
/**
* The JMXConnectorEnv HashMap that is used to acquire JMX connections This is a read-only property constructed from the
* properties adminUsername and adminPassword It is a HashMap whose key is "jmx.remote.credentials" and whose
* corresponding value is a string array containing admin username and admin password
*/
private HashMap<String, String[]> jmxConnectorEnv = null;
/*
* The JMXServiceURLList String that can be used to acquire JMX connections to all brokers specified on connectionURL
*/
private String jmxServiceURLList = null;
/*
* Indicate whether the JMXServiceURLList is valid or needs to be re-acquired
*/
private boolean isJMXServiceURLListValid = false;
/**
* Value used to set the broker property imq.cluster.masterbroker
*/
private String masterBroker = null;
/**
* Value used to set the broker property imq.cluster.brokerlist
*/
private String clusterBrokerList = null;
/**
* Starts the lifecycle managed broker.
*/
public synchronized void start() throws ResourceAdapterInternalException {
if (BROKER_TYPE_LOCAL.equals(brokerType)) {
try {
lbr = new LocalBrokerRunner(getBrokerUrl(), brokerInstanceName, brokerBindAddress, brokerPort, brokerHomeDir, brokerLibDir, brokerVarDir,
brokerJavaDir, brokerArgs, useJNDIRmiServiceURL, rmiRegistryPort, startRmiRegistry, useSSLJMXConnector, brokerStartTimeout,
adminUsername, adminPassFile, new EffectiveBrokerProps());
lbr.start();
} catch (Exception lbse) {
ResourceAdapterInternalException raie = new ResourceAdapterInternalException(
_lgrMID_EXC + "start:Aborting:Exception starting LOCAL broker=" + lbse.getMessage());
raie.initCause(lbse);
_loggerL.severe(raie.getMessage());
_loggerL.info(this.toString());
lbse.printStackTrace();
_loggerL.throwing(_className, "start()", raie);
throw raie;
}
} else {
if (isInProcess()) {
try {
if (!_startedAtLeastOnce) {
_rmiRegistryPort = rmiRegistryPort;
}
if (ebr == null) {
ebr = new EmbeddedBrokerRunner(brokerInstanceName, brokerBindAddress, brokerPort, brokerHomeDir, brokerLibDir, brokerVarDir,
brokerJavaDir, brokerArgs, useJNDIRmiServiceURL, _rmiRegistryPort, startRmiRegistry, useSSLJMXConnector, doBind,
_getEffectiveBrokerProps());
ebr.init();
}
ebr.start();
_setRAJMSService(ebr.getJMSService());
_startedAtLeastOnce = true;
} catch (Exception ebse) {
ResourceAdapterInternalException raie = new ResourceAdapterInternalException(
_lgrMID_EXC + "start:Aborting:Exception starting EMBEDDED broker=" + ebse.getMessage());
raie.initCause(ebse);
_loggerL.severe(raie.getMessage());
_loggerL.info(this.toString());
ebse.printStackTrace();
_loggerL.throwing(_className, "start()", raie);
throw raie;
}
}
}
started = true;
}
/**
* Return whether this lifecycle managed broker has been started
*
* @return whether this lifecycle managed broker has been started
*/
public boolean isStarted() {
return started;
}
/**
* Stops the lifecycle managed broker
*/
public void stop() {
if (ebr != null) {
ebr.stop();
ebr = null;
}
if (lbr != null) {
lbr.stop();
lbr = null;
}
started = false;
}
/**
* Return all properties that need to be passed to the managed broker.
*/
private Properties _getEffectiveBrokerProps() {
Properties props = new Properties();
// start with the brokerProps specified by the user
// these may be overridden by properties set later in this method
for (Iterator<Entry<Object, Object>> iterator = brokerProps.entrySet().iterator(); iterator.hasNext();) {
Entry<Object, Object> thisEntry = iterator.next();
props.put(thisEntry.getKey(), thisEntry.getValue());
}
// Set this property to tell the broker that it is being managed
props.setProperty("imq.jmsra.managed", "true");
// Set this always to ensure that broker accepts connections from
// clients
// before it is able to establish a connection with its MasterBroker
props.setProperty("imq.cluster.nowaitForMasterBroker", "true");
if (isInProcess()) {
props.setProperty("imq.service.activate", "jmsdirect");
}
if (brokerEnableHA) {
props.setProperty("imq.cluster.ha", "true");
if (clusterId != null) {
props.setProperty("imq.cluster.clusterid", clusterId);
}
} else {
if ((clusterBrokerList != null) && !clusterBrokerList.equals("")) {
// set imq.cluster.brokerlist
// override any already value set via brokerProps
props.setProperty(BrokerConstants.PROP_NAME_BKR_CLS_BKRLIST, clusterBrokerList);
} else if (!props.containsKey(BrokerConstants.PROP_NAME_BKR_CLS_BKRLIST) && connectionURL != null && !("".equals(connectionURL))) {
// if it is not specified via setClusterBrokerList or setBrokerProps, set imq.cluster.brokerlist from connectionURL
// not sure when this is needed, but it must be here for a reason
props.setProperty(BrokerConstants.PROP_NAME_BKR_CLS_BKRLIST, connectionURL);
}
if ((masterBroker != null) && !masterBroker.equals("")) {
// set imq.cluster.masterbroker
// override any already value set via brokerProps
props.setProperty("imq.cluster.masterbroker", masterBroker);
}
if (nowaitForMasterBrokerTimeoutInSeconds > -1) {
String strVal = String.valueOf(nowaitForMasterBrokerTimeoutInSeconds);
props.setProperty("imq.cluster.nowaitForMasterBrokerTimeoutInSeconds", strVal);
}
}
if (dbType != null) {
props.setProperty("imq.persist.store", "jdbc");
if (dbProps.containsKey(FALLBACK_DATABASE_PASSWORD)) {
props.setProperty(IMQ_FALLBACK_DATABASE_PASSWORD, dbProps.getProperty(FALLBACK_DATABASE_PASSWORD));
}
if (DB_TYPE_MYSQL.equals(dbType)) {
props.setProperty(IMQ_JDBC_VENDOR, dbType);
props.setProperty(IMQ_BROKERID, brokerId);
if (dbProps.containsKey(MYSQL_USER)) {
props.setProperty(IMQ_MYSQL_USER, dbProps.getProperty(MYSQL_USER));
}
if (dbProps.containsKey(MYSQL_PASSWORD)) {
props.setProperty(IMQ_MYSQL_PASSWORD, dbProps.getProperty(MYSQL_PASSWORD));
}
if (dsProps.containsKey(MYSQL_URL)) {
props.setProperty(IMQ_MYSQL_DSPROP_URL, dsProps.getProperty(MYSQL_URL));
}
}
}
// admin password can be set by either setAdminPassword or by setting brokerProp imq.imqcmd.password
// decide which to use of both are set, and set default if neither are set
String defaultAdminPassword = "admin";
if (props.containsKey("imq.imqcmd.password")) {
if (adminPassword == null) {
adminPassword = props.getProperty("imq.imqcmd.password");
} else {
// password set via setAdminPassword() overrides password set by setBrokerProps()
props.setProperty("imq.imqcmd.password", adminPassword);
}
} else {
if (adminPassword == null) {
// both null, set default
adminPassword = defaultAdminPassword;
props.setProperty("imq.imqcmd.password", defaultAdminPassword);
} else {
props.setProperty("imq.imqcmd.password", adminPassword);
}
}
return props;
}
/**
* Return the JMSService instance that a RADirect client can use to communicate with the in-VM broker.<br/>
* <br/>
*
* @return the JMSService instance or null
*/
public synchronized JMSService _getJMSService() {
if (ebr != null) {
// get from the EBR
JMSService result = ebr.getJMSService();
if (_getRAJMSService() == null) {
_setRAJMSService(result);
}
return result;
} else {
// EBR unavailable
return null;
}
}
/**
* Static version of _getJMSService(), for use by DirectConnectionFactory#_createConnectionId when _getJMSService()
* doesn't work. This seems to be here as a quick and dirty fix to a bug and it would be good to get rid of this
*/
public static final JMSService _getRAJMSService() {
return jmsservice;
}
/**
* Save the specified JMSService in a static field, for use by DirectConnectionFactory#_createConnectionId when
* _getJMSService() doesn't work. This seems to be here as a quick and dirty fix to a bug and it would be good to be
* able to get rid of this
*
*/
public static void _setRAJMSService(JMSService jmsserviceArg) {
jmsservice = jmsserviceArg;
}
/**
* Specifies whether the lifecycle managed broker should start a new RMI registry<br/>
* This property only takes affect if the <tt>useINDIRmiServiceURL</tt> property is also set to true.<br/>
* Causes the broker arguments <tt>-startRmiRegistry -rmiRegistryPort</tt> <i>rmiRegistryPort</i><br/>
* to be used.
*
* @param startRmiRegistry whether the lifecycle managed broker should start a new RMI registry
*/
public synchronized void setStartRmiRegistry(boolean startRmiRegistry) {
_loggerL.entering(_className, "setStartRmiRegistry()", Boolean.valueOf(startRmiRegistry));
if (started || (_startedAtLeastOnce && (isInProcess()))) {
_loggerL.warning(_lgrMID_WRN + "setStartRmiRegistry:RA already started OR run once as EMBEDDED:Disallowing change from:" + this.startRmiRegistry
+ ":to:" + startRmiRegistry);
return;
}
this.startRmiRegistry = startRmiRegistry;
}
/**
* Specifies whether the lifecycle manager should start a RMI registry
*
* @return startRmiRegistry
*/
public synchronized boolean getStartRmiRegistry() {
_loggerL.entering(_className, "getStartRmiRegistry()", Boolean.valueOf(startRmiRegistry));
return startRmiRegistry;
}
/**
* Specifies the rmiRegistryPort used by the lifecycle managed broker.<br/>
* This property only takes effect if the <tt>useINDIRmiServiceURL</tt> property is also set to true.</br>
* Whether a new RMI registry is started or whether an existing RMI registry is used depends on the value of the
* <tt>startRMIRegistry</tt> property.
*
* @param rmiRegistryPort the rmiRegistryPort used by the lifecycle managed brokers
*/
public synchronized void setRmiRegistryPort(int rmiRegistryPort) {
_loggerL.entering(_className, "setRmiRegistryPort()", Integer.valueOf(rmiRegistryPort));
if (started || (_startedAtLeastOnce && (isInProcess()))) {
_loggerL.warning(_lgrMID_WRN + "setRmiRegistryPort:RA already started OR run once as EMBEDDED:Disallowing change from:" + this.rmiRegistryPort
+ ":to:" + rmiRegistryPort);
return;
}
this.rmiRegistryPort = rmiRegistryPort;
}
/**
* Returns the specified rmiRegistryPort to be used by the lifecycle managed broker
*
* @return the specified rmiRegistryPort to be used by the lifecycle managed broker
*/
public synchronized int getRmiRegistryPort() {
_loggerL.entering(_className, "getRmiRegistryPort()", Integer.valueOf(rmiRegistryPort));
return rmiRegistryPort;
}
/**
* Return the brokerType of the lifecycle managed broker.
*
* This returns the value that was specified with {@link #setBrokerType(java.lang.String) setBrokerType}, or the default
* value if {@link #setBrokerType(java.lang.String) setBrokerType} was not called
*/
public synchronized String getBrokerType() {
return brokerType;
}
/**
* Specifies whether the broker should run in the same or a separate JVM. Possible values of brokerType are:
* <ul>
* <li><tt>LOCAL</tt> ({@link #BROKER_TYPE_LOCAL BROKER_TYPE_LOCAL}) - Broker will be started in a separate JVM<br/>
* <li><tt>EMBEDDED</tt> ({@link #BROKER_TYPE_EMBEDDED BROKER_TYPE_EMBEDDED}) -- A broker will be started in the same
* JVM. Identical to <tt>DIRECT</tt>.
* <li><tt>DIRECT</tt> ({@link #BROKER_TYPE_DIRECT BROKER_TYPE_DIRECT}) - A broker will be started in the same JVM.
* Identical to <tt>EMBEDDED</tt>
* <li><tt>REMOTE</tt> ({@link #BROKER_TYPE_REMOTE BROKER_TYPE_REMOTE}) - No broker will be started. Calling
* <tt>start()</tt> and <tt>stop()</tt> will have no effect.
* </ul>
*
* @param brokerType One of <tt>LOCAL</tt>,<tt>EMBEDDED</tt>,<tt>DIRECT</tt> or <tt>REMOTE</tt>.
*/
public synchronized void setBrokerType(String brokerType) {
_loggerL.entering(_className, "setBrokerType()", brokerType);
if (started) {
_loggerL.warning(
_lgrMID_WRN + "setBrokerType:lifecycle managed broker already started:Disallowing change from:" + this.brokerType + ":to:" + brokerType);
return;
}
if ((BROKER_TYPE_DIRECT.equals(brokerType)) || (BROKER_TYPE_EMBEDDED.equals(brokerType)) || (BROKER_TYPE_LOCAL.equals(brokerType))
|| (BROKER_TYPE_REMOTE.equals(brokerType))) {
this.brokerType = brokerType;
} else {
_loggerL.warning(_lgrMID_WRN + "setBrokerType:Invalid value:" + brokerType + ":remaining at brokerType=" + this.brokerType);
}
}
/**
* Return whether the specified broker type is LOCAL
*/
public boolean isLocal() {
return (ResourceAdapter.BROKER_TYPE_LOCAL.equals(brokerType));
}
/**
* Return whether the specified broker type is DIRECT or EMBEDDED
*/
public boolean isInProcess() {
return (ResourceAdapter.BROKER_TYPE_DIRECT.equals(brokerType) | ResourceAdapter.BROKER_TYPE_EMBEDDED.equals(brokerType));
}
/**
* Return whether the specified broker type is REMOTE
*/
public boolean isRemote() {
return (ResourceAdapter.BROKER_TYPE_REMOTE.equals(brokerType));
}
/**
* Returns the instance name of the lifecycle managed broker.
*
* @return the instance name of the lifecycle managed broker.
*/
public synchronized String getBrokerInstanceName() {
_loggerL.entering(_className, "getBrokerInstanceName()", brokerInstanceName);
return brokerInstanceName;
}
/**
* Specifies the instance name of the lifecycle managed broker.<br/>
* For an embedded broker this sets the <tt>-name</tt> broker argument.<br/>
* In the case of a local broker this is used to determine the logfile directory
*
* @param brokerInstanceName The Broker Home Directory
*/
public synchronized void setBrokerInstanceName(String brokerInstanceName) {
_loggerL.entering(_className, "setBrokerInstanceName()", brokerInstanceName);
if (isNameValidAlphaNumeric_(brokerInstanceName)) {
this.brokerInstanceName = brokerInstanceName;
} else {
_loggerL.warning(_lgrMID_WRN + "setBrokerInstanceName:Invalid value:" + brokerInstanceName);
}
}
/**
* Sets the brokerBindAddress for the lifecycle managed broker.<br/>
* This specifies the network address that the broker must bind to and is typically needed in cases where two or more
* hosts are available (such as when more than one network interface card is installed in a computer), If null, the
* broker will bind to all addresses on the host machine.<br/>
* <br/>
* This sets the <tt>imq.hostname</tt> property
*
* @param brokerBindAddress for the lifecycle managed broker
*/
public synchronized void setBrokerBindAddress(String brokerBindAddress) {
_loggerL.entering(_className, "setBrokerBindAddress()", brokerBindAddress);
if (started) {
_loggerL.warning(
_lgrMID_WRN + "setBrokerBindAddress:RA already started:Disallowing change from:" + this.brokerBindAddress + ":to:" + brokerBindAddress);
return;
}
try {
// validate the specified address (throws an exception if invalid)
InetAddress.getByName(brokerBindAddress);
this.brokerBindAddress = brokerBindAddress;
} catch (UnknownHostException e) {
_loggerL.warning(_lgrMID_WRN + "setBrokerBindAddress:Ignoring Invalid Address:" + brokerBindAddress + ":ExceptionMsg=" + e.getMessage());
}
}
/**
* Returns the brokerBindAddress for the lifecycle managed broker.<br/>
*
* @return the brokerBindAddress for the lifecycle managed broker
*/
public synchronized String getBrokerBindAddress() {
_loggerL.entering(_className, "getBrokerBindAddress()", brokerBindAddress);
return brokerBindAddress;
}
/**
* Specifies the port on which the lifecycle managed broker's port mapper will listen for connections.
*
* @param brokerPort The port on which the lifecycle managed broker's port mapper will listen for connections.
*/
public synchronized void setBrokerPort(int brokerPort) {
_loggerL.entering(_className, "setBrokerPort()", Integer.valueOf(brokerPort));
if (started) {
_loggerL.warning(_lgrMID_WRN + "setBrokerPort:RA already started:Disallowing change from:" + this.brokerPort + ":to:" + brokerPort);
return;
}
this.brokerPort = brokerPort;
}
/**
* Returns the brokerPort for the lifecycle managed broker
*
* @return the brokerPort for the lifecycle managed broker
*/
public synchronized int getBrokerPort() {
_loggerL.entering(_className, "getBrokerPort()", Integer.valueOf(brokerPort));
return brokerPort;
}
/**
* Return the maximum time (milliseconds) allowed for a local broker to start
*
* @return the maximum time (milliseconds) allowed for a local broker to start
*/
public int getBrokerStartTimeout() {
return brokerStartTimeout;
}
/**
* Specify the maximum time (milliseconds) allowed for a local broker to start
*
* @param brokerStartTimeout the maximum time (milliseconds) allowed for a local broker to start
*/
public void setBrokerStartTimeout(int brokerStartTimeout) {
this.brokerStartTimeout = brokerStartTimeout;
}
/**
* Specifies the brokerHomeDir of the lifecycle managed broker.<br/>
* For an embedded broker this sets the <tt>-imqhome</tt> broker argument.<br/>
* In the case of a local broker this must be set to the parent of the <tt>bin</tt> directory containing the broker
* executable.
*
* @param brokerHomeDir The Broker Home Directory
*/
public synchronized void setBrokerHomeDir(String brokerHomeDir) {
_loggerL.entering(_className, "setBrokerHomeDir()", brokerHomeDir);
if (started) {
_loggerL.warning(_lgrMID_WRN + "setBrokerHomeDir:RA already started:Disallowing change from:" + this.brokerHomeDir + ":to:" + brokerHomeDir);
return;
}
try {
String path = new File(brokerHomeDir).getCanonicalPath();
this.brokerHomeDir = path;
} catch (IOException e) {
_loggerL.warning(_lgrMID_WRN + "setBrokerHomeDir:Invalid value:" + brokerHomeDir + ":Exception Message=" + e.getMessage());
}
}
/**
* Returns the brokerHomeDir of the lifecycle managed broker
*
* @return The brokerHomeDir of the lifecycle managed broker
*/
public synchronized String getBrokerHomeDir() {
_loggerL.entering(_className, "getBrokerHomeDir()", brokerHomeDir);
return brokerHomeDir;
}
/**
* Specifies the lib directory for the lifecycle managed broker.<br/>
* This is used in the case of an embedded broker to set the <-tt>-libhome</tt> argument passed to the broker
* executable.
*
* @param brokerLibDir the lib directory for the lifecycle managed broker.
*/
public synchronized void setBrokerLibDir(String brokerLibDir) {
_loggerL.entering(_className, "setBrokerLibDir()", brokerLibDir);
if (started) {
_loggerL.warning(_lgrMID_WRN + "setBrokerLibDir:RA already started:Disallowing change from:" + this.brokerLibDir + ":to:" + brokerLibDir);
return;
}
try {
String path = new File(brokerLibDir).getCanonicalPath();
this.brokerLibDir = path;
} catch (IOException e) {
_loggerL.warning(_lgrMID_WRN + "setBrokerLibDir:Invalid value:" + brokerLibDir + ":Exception Message=" + e.getMessage());
}
}
/**
* Returns the specified lib directory for the lifecycle managed broker.
*
* @return the specified lib directory for the lifecycle managed broker.
*/
public synchronized String getBrokerLibDir() {
_loggerL.entering(_className, "getBrokerLibDir()", brokerLibDir);
return brokerLibDir;
}
/**
* Specifies the location of the var directory of the lifecycle managed broker.<br/>
* This sets the <tt>-varhome</tt> broker argument.<br/>
*
* @param brokerVarDir The Broker var Directory
*/
public synchronized void setBrokerVarDir(String brokerVarDir) {
_loggerL.entering(_className, "setBrokerVarDir()", brokerVarDir);
if (started) {
_loggerL.warning(_lgrMID_WRN + "setBrokerVarDir:RA already started:Disallowing change from:" + this.brokerVarDir + ":to:" + brokerVarDir);
return;
}
try {
String path = new File(brokerVarDir).getCanonicalPath();
this.brokerVarDir = path;
} catch (IOException e) {
_loggerL.warning(_lgrMID_WRN + "setBrokerVarDir:Invalid value:" + brokerVarDir + ":Exception Message=" + e.getMessage());
}
}
/**
* Returns the specified location of the var directory of the lifecycle managed broker
*
* @return the specified location of the var directory of the lifecycle managed broker
*/
public synchronized String getBrokerVarDir() {
_loggerL.entering(_className, "getBrokerVarDir()", brokerVarDir);
return brokerVarDir;
}
/**
* Specifies the Java home directory for the lifecycle managed broker.<br/>
* This is used in the case of a local broker to set the <-tt>javahome</tt> argument passed to the broker executable and
* must be set to a directory containg a Java JRE.<br/>
* It is not used in the case of an embedded broker.
*
* @param brokerJavaDir the Java home directory for the lifecycle managed broker
*/
public synchronized void setBrokerJavaDir(String brokerJavaDir) {
_loggerL.entering(_className, "setBrokerJavaDir()", brokerJavaDir);
if (started) {
_loggerL.warning(_lgrMID_WRN + "setBrokerJavaDir:RA already started:Disallowing change from:" + this.brokerJavaDir + ":to:" + brokerJavaDir);
return;
}
try {
String path = new File(brokerJavaDir).getCanonicalPath();
this.brokerJavaDir = path;
} catch (IOException e) {
_loggerL.warning(_lgrMID_WRN + "setBrokerJavaDir:Invalid value:" + brokerJavaDir + ":Exception Message=" + e.getMessage());
}
}
/**
* Returns the specified Java home directory for the lifecycle managed broker.
*
* @return the specified Java home directory for the lifecycle managed broker.
*/
public synchronized String getBrokerJavaDir() {
_loggerL.entering(_className, "getBrokerJavaDir()", brokerJavaDir);
return brokerJavaDir;
}
/**
* Specifies additional command-line arguments for the lifecycle managed broker
*
* @param brokerArgs additional command-line arguments for the lifecycle managed broker
*/
public synchronized void setBrokerArgs(String brokerArgs) {
_loggerL.entering(_className, "setBrokerArgs()", brokerArgs);
if (started) {
_loggerL.warning(_lgrMID_WRN + "setBrokerArgs:RA already started:Disallowing change from:" + this.brokerArgs + ":to:" + brokerArgs);
return;
}
this.brokerArgs = brokerArgs;
}
/**
* Returns the additional command-line arguments what were specified for the lifecycle managed broker
*
* @return the additional command-line arguments what were specified for the lifecycle managed broker
*/
public synchronized String getBrokerArgs() {
_loggerL.entering(_className, "getBrokerArgs()", brokerArgs);
return brokerArgs;
}
/**
* Configure the lifecycle managed broker to use a RMI registry, so that the JMX runtime uses a static JMX service URL
* to perform a JNDI lookup of the JMX connector stub in the RMI registry.<br/>
* <br/>
* By default, the broker does not use an RMI registry, and the JMX runtime obtains a JMX connector stub by extracting
* it from a dynamic JMX service URL. However, if the broker is configured to use an RMI registry, then JMX runtime uses
* a static JMX service URL to perform a JNDI lookup of the JMX connector stub in the RMI registry. This approach has
* the advantage of providing a fixed location at which the connector stub resides, one that does not change across
* broker startups.<br/>
* <br/>
* So if this property is set to true then an RMI registry will be configured using the port specified by the
* <i>rmiRegistryPort</i> property.<br/>
* If the <i>startRmiRegistry</i> property is set a new RMI registry is started using the broker arguments
* <tt>-startRmiRegistry -rmiRegistryPort</tt> <i>rmiRegistryPort</i><br/>
* If the <i>startRmiRegistry</i> property is not set an external RMI registry is used using the broker arguments
* <tt>-useRmiRegistry -rmiRegistryPort</tt> <i>rmiRegistryPort</i><br/>
*
* @param useJNDIRmiServiceURL whether the lifecycle managed broker should use a RMI registry.
*/
public synchronized void setUseJNDIRmiServiceURL(boolean useJNDIRmiServiceURL) {
_loggerL.entering(_className, "setUseJNDIRmiServiceURL()", Boolean.valueOf(useJNDIRmiServiceURL));
if (started) {
_loggerL.warning(_lgrMID_WRN + "setUseJNDIRmiServiceURL:RA already started:Disallowing change from:" + this.useJNDIRmiServiceURL + ":to:"
+ useJNDIRmiServiceURL);
return;
}
this.useJNDIRmiServiceURL = useJNDIRmiServiceURL;
}
/**
* Return the JMXConnectorEnv for the broker that this RA is configured to connect to
*
* This is a HashMap whose key is "jmx.remote.credentials" and whose corresponding value is a string array containing
* admin username and admin password
*
* @return The JMXConnectorEnv
*/
public synchronized HashMap getJMXConnectorEnv() {
_loggerL.entering(_className, "getJMXConnectorEnv()");
if (jmxConnectorEnv == null) {
jmxConnectorEnv = new HashMap<>();
String[] credentials = new String[] { getAdminUsername(), getAdminPassword() };
jmxConnectorEnv.put(javax.management.remote.JMXConnector.CREDENTIALS, credentials);
}
return jmxConnectorEnv;
}
/**
* Return the JMXServiceURL for the lifecycle managed broker This is a String that can be used to acquire JMX
* connections
*
* Returns null if the broker is REMOTE
*
* @return The JMXServiceURL
*/
public synchronized String getJMXServiceURL() {
_loggerL.entering(_className, "getJMXServiceURL()");
if (!started) {
_loggerL.warning(_lgrMID_WRN + "getJMXServiceURL:RA not started:Returning null");
return null;
}
if ((jmxServiceURL == null) && !ResourceAdapter.BROKER_TYPE_REMOTE.equals(brokerType)) {
com.sun.messaging.AdminConnectionFactory tacf = new com.sun.messaging.AdminConnectionFactory();
try {
tacf.setProperty(AdminConnectionConfiguration.imqAddress, "mq://"
+ (((getBrokerBindAddress() != null) ? getBrokerBindAddress() : "localhost") + ":" + Integer.toString(getBrokerPort())) + "/jmxrmi");
tacf.setProperty(AdminConnectionConfiguration.imqDefaultAdminUsername, getAdminUsername());
tacf.setProperty(AdminConnectionConfiguration.imqDefaultAdminPassword, getAdminPassword());
} catch (Exception e) {
_loggerL.warning(_lgrMID_EXC + "getJMXServiceURL:Exception configuring AdminConnectionFactory:Message=" + e.getMessage());
}
try {
JMXServiceURL _jmxserviceURL = tacf.getJMXServiceURL();
jmxServiceURL = _jmxserviceURL.toString();
} catch (Exception e) {
_loggerL.warning(_lgrMID_EXC + "getJMXServiceURL:Exception:Message=" + e.getMessage());
}