-
Notifications
You must be signed in to change notification settings - Fork 33
/
JMSAdminImpl.java
1363 lines (1152 loc) · 49.3 KB
/
JMSAdminImpl.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
*
* 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.admin.jmsspi;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import jakarta.jms.Connection;
import jakarta.jms.DeliveryMode;
import jakarta.jms.ExceptionListener;
import jakarta.jms.InvalidSelectorException;
import jakarta.jms.JMSException;
import jakarta.jms.Message;
import jakarta.jms.ObjectMessage;
import jakarta.jms.Queue;
import jakarta.jms.QueueConnection;
import jakarta.jms.QueueReceiver;
import jakarta.jms.QueueSender;
import jakarta.jms.QueueSession;
import jakarta.jms.Session;
import jakarta.jms.TemporaryQueue;
import com.sun.messaging.AdministeredObject;
import com.sun.messaging.ConnectionConfiguration;
import com.sun.messaging.DestinationConfiguration;
import com.sun.messaging.QueueConnectionFactory;
import com.sun.messaging.jmq.ClientConstants;
import com.sun.messaging.jmq.Version;
import com.sun.messaging.jmq.admin.apps.broker.BrokerCmdOptions;
import com.sun.messaging.jmq.admin.bkrutil.BrokerConstants;
import com.sun.messaging.jmq.admin.resources.AdminResources;
import com.sun.messaging.jmq.admin.util.Globals;
import com.sun.messaging.jmq.admin.util.JMSObjFactory;
import com.sun.messaging.jmq.jmsclient.ConnectionImpl;
import com.sun.messaging.jmq.jmsclient.JMSXAWrappedConnectionFactoryImpl;
import com.sun.messaging.jmq.jmsspi.JMSAdmin;
import com.sun.messaging.jmq.jmsspi.PropertiesHolder;
import com.sun.messaging.jmq.util.BrokerExitCode;
import com.sun.messaging.jmq.util.DestType;
import com.sun.messaging.jmq.util.admin.DestinationInfo;
import com.sun.messaging.jmq.util.admin.MessageType;
public class JMSAdminImpl implements JMSAdmin, ExceptionListener {
private static AdminResources ar = Globals.getAdminResources();
public static final long DEFAULT_TIMEOUT = 5000;
private String adminuserName = null;
private String adminPassword = null;
private long timeout = -1;
private QueueConnectionFactory qcf;
private QueueConnection connection;
private QueueSession session;
private Queue requestQueue;
private TemporaryQueue replyQueue;
private QueueSender sender;
protected QueueReceiver receiver;
private AdministeredObject tmpDestination = null;
private AdministeredObject tmpConnFactory = null;
private boolean secureTransportUsed = false;
// When this class is used to start a broker, these properties are passed to the broker
private PropertiesHolder brokerPropertiesHolder;
// use this logger name as enabling Glassfish jms logging uses loggers of the form javax.resourceadapter.mqjmsra
protected static final String loggerName = "javax.resourceadapter.mqjmsra.lifecycle";
protected static final Logger logger = Logger.getLogger(loggerName);
/*
* This class should only be instantiated via JMSAdminFactoryImpl. REVISIT: hard-coded error messages
*/
protected JMSAdminImpl(Properties connectionProps, PropertiesHolder brokerPropertiesHolder, String username, String adminPassword) throws JMSException {
this.timeout = DEFAULT_TIMEOUT;
this.adminuserName = username;
this.adminPassword = adminPassword;
this.brokerPropertiesHolder = brokerPropertiesHolder;
createFactory(connectionProps); // init the qcf !!
String connType = connectionProps.getProperty(ConnectionConfiguration.imqConnectionType, "");
if (connType.equals("TLS") || connType.equals("SSL")) {
secureTransportUsed = true;
}
}
/**
* Return the SPI version
*/
@Override
public String getVersion() {
Version version = new Version();
return (version.getJMSAdminSpiVersion());
}
/**
* Create a ConnectionFactory administered object
*
* @param type Either QUEUE or TOPIC.
* @param properties Connection specific properties.
* @return New created ConnectionFactory administered object.
* @exception JMSException thrown if connectionFactory could not be created.
*/
@Override
public Object createConnectionFactoryObject(int type, java.util.Map properties) throws JMSException {
Object cf = null;
Properties tmpProps = getProperties(properties);
fillDefaultConnectionFactoryProperties(tmpProps);
if (type == TOPIC) {
cf = JMSObjFactory.createTopicConnectionFactory(tmpProps);
} else if (type == QUEUE) {
cf = JMSObjFactory.createQueueConnectionFactory(tmpProps);
} else {
throw new jakarta.jms.JMSException(ar.getKString(ar.X_JMSSPI_INVALID_DOMAIN_TYPE));
}
return cf;
}
/**
* Create a XAConnectionFactory administered object
*
* @param type Either QUEUE or TOPIC.
* @param properties Connection specific properties.
* @return New created JMSXAConnectionFactory administered object. ^^^^^
* @exception JMSException thrown if XAConnectionFactory could not be created.
*/
@Override
public Object createXAConnectionFactoryObject(int type, java.util.Map properties) throws JMSException {
Object xcf = null;
Properties tmpProps = getProperties(properties);
fillDefaultConnectionFactoryProperties(tmpProps);
if (type == TOPIC) {
xcf = new com.sun.messaging.jmq.jmsclient.JMSXATopicConnectionFactoryImpl();
setProperties((AdministeredObject) xcf, tmpProps);
} else if (type == QUEUE) {
xcf = new com.sun.messaging.jmq.jmsclient.JMSXAQueueConnectionFactoryImpl();
setProperties((AdministeredObject) xcf, tmpProps);
} else {
throw new jakarta.jms.JMSException(ar.getKString(ar.X_JMSSPI_INVALID_DOMAIN_TYPE));
}
return xcf;
}
/**
* Create a Destination administered object
*
* @param destinationName The destination name.
* @param type Either QUEUE or TOPIC.
* @param properties destination specific properties.
* @return New created Destination administered object.
* @exception JMSException thrown if destination object could not be created.
*/
@Override
public Object createDestinationObject(String destinationName, int type, java.util.Map properties) throws JMSException {
Map props = properties;
if (props == null) {
props = new Properties();
}
props.put(DestinationConfiguration.imqDestinationName, destinationName);
return createDestinationObject(type, props);
}
/**
* Create a Destination administered object. The destination name is assumed in properties like imqDestinationName=xxxxx
*
* @param type Either QUEUE or TOPIC.
* @param properties destination specific properties.
* @return New created Destination administered object.
* @exception JMSException thrown if destination object could not be created.
*/
@Override
public Object createDestinationObject(int type, java.util.Map properties) throws JMSException {
if (properties == null || properties.get(DestinationConfiguration.imqDestinationName) == null) {
throw new JMSException(ar.getKString(ar.X_JMSSPI_NO_DESTINATION_NAME));
}
Object dest = null;
Properties tmpProps = getProperties(properties);
if (type == TOPIC) {
dest = JMSObjFactory.createTopic(tmpProps);
} else if (type == QUEUE) {
dest = JMSObjFactory.createQueue(tmpProps);
} else {
throw new jakarta.jms.JMSException(ar.getKString(ar.X_JMSSPI_INVALID_DOMAIN_TYPE));
}
return dest;
}
/**
* Wrap a standard JMS ConnectionFactory administered object
*
* @param obj a XAQueue/TopicConnectionFactory or Queue/TopicConnectionFactory object
* @return a JMSXAConnectionFactory object ^^^^^
* @exception JMSException if fail to wrap
*/
@Override
public Object wrapJMSConnectionFactoryObject(Object obj) throws JMSException {
if (obj instanceof jakarta.jms.XAQueueConnectionFactory) {
return new JMSXAWrappedConnectionFactoryImpl((jakarta.jms.XAQueueConnectionFactory) obj);
}
if (obj instanceof jakarta.jms.XATopicConnectionFactory) {
return new JMSXAWrappedConnectionFactoryImpl((jakarta.jms.XATopicConnectionFactory) obj);
}
if (obj instanceof jakarta.jms.QueueConnectionFactory) {
return new JMSXAWrappedConnectionFactoryImpl((jakarta.jms.QueueConnectionFactory) obj);
}
if (obj instanceof jakarta.jms.TopicConnectionFactory) {
return new JMSXAWrappedConnectionFactoryImpl((jakarta.jms.TopicConnectionFactory) obj);
}
throw new JMSException(ar.getKString(ar.X_JMSSPI_INVALID_OBJECT_TYPE));
}
@Override
public void validateJMSSelector(String selector) throws JMSException {
com.sun.messaging.jmq.jmsselector.JMSSelector jmsselector = new com.sun.messaging.jmq.jmsselector.JMSSelector();
try {
jmsselector.validateSelectorPattern(selector);
} catch (com.sun.messaging.jmq.jmsselector.InvalidJMSSelectorException e) {
throw new InvalidSelectorException(e.getMessage());
} catch (Exception e) {
throw new JMSException(e.getMessage());
}
}
/**
* @return the client-id property name
*/
@Override
public String clientIDPropertyName() {
return ConnectionConfiguration.imqConfiguredClientID;
}
/**
* Returns a map of all the properties that a destination object has.
* <P>
* For each property name returned, a corresponding label that can be used for output display purposes is also returned.
* The Map returned contains the property names and property labels as key-value pairs. This information can be used to
* display more readable output containing property labels and not property names.
*
* @param type Either QUEUE or TOPIC.
* @return Map containing attribute value pairs of property names and their display labels.
*/
@Override
public Map getAllDestinationObjectProperties(int type) throws JMSException {
Properties ret;
if (tmpDestination == null) {
tmpDestination = (AdministeredObject) JMSObjFactory.createTopic(new Properties());
}
ret = new Properties();
for (Enumeration e = tmpDestination.enumeratePropertyNames(); e.hasMoreElements();) {
String propName = (String) e.nextElement();
String propLabel = tmpDestination.getPropertyLabel(propName);
ret.setProperty(propName, propLabel);
}
return (ret);
}
/**
* Returns a subset of all the properties that a destination object has.
* <P>
* This collection of properties can be used to construct a user interface where not all of the object's properties will
* be displayed, and only a selected few (more important) ones are.
* <P>
* For each property name returned, a corresponding label that can be used for output display purposes is also returned.
* The Map returned contains the property names and property labels as key-value pairs. This information can be used to
* display more readable output containing property labels and not property names.
*
* @param type Either QUEUE or TOPIC.
* @return Map containing attribute value pairs of property names and their display labels.
*/
@Override
public Map getDisplayedDestinationObjectProperties(int type) throws JMSException {
Properties ret;
String propName, propLabel;
if (tmpDestination == null) {
tmpDestination = (AdministeredObject) JMSObjFactory.createTopic(new Properties());
}
ret = new Properties();
propName = DestinationConfiguration.imqDestinationName;
propLabel = tmpDestination.getPropertyLabel(propName);
ret.setProperty(propName, propLabel);
return (ret);
}
/**
* Returns a map of all the properties that a connection factory object has.
* <P>
* For each property name returned, a corresponding label that can be used for output display purposes is also returned.
* The Map returned contains the property names and property labels as key-value pairs. This information can be used to
* display more readable output containing property labels and not property names.
*
* @param type Either QUEUE or TOPIC.
* @return Map containing attribute value pairs of property names and their display labels.
*/
@Override
public Map getAllConnectionFactoryObjectProperies(int type) throws JMSException {
Properties ret;
if (tmpConnFactory == null) {
tmpConnFactory = (AdministeredObject) JMSObjFactory.createTopicConnectionFactory(new Properties());
}
ret = new Properties();
for (Enumeration e = tmpConnFactory.enumeratePropertyNames(); e.hasMoreElements();) {
String propName = (String) e.nextElement();
String propLabel = tmpConnFactory.getPropertyLabel(propName);
ret.setProperty(propName, propLabel);
}
return (ret);
}
/**
* Returns a subset of all the properties that a connection factory object has.
* <P>
* This collection of properties can be used to construct a user interface where not all of the object's properties will
* be displayed, and only a selected few (more important) ones are.
* <P>
* For each property name returned, a corresponding label that can be used for output display purposes is also returned.
* The Map returned contains the property names and property labels as key-value pairs. This information can be used to
* display more readable output containing property labels and not property names.
*
* @param type Either QUEUE or TOPIC.
* @return Map containing attribute value pairs of property names and their display labels.
*/
@Override
public Map getDisplayedConnectionFactoryObjectProperies(int type) throws JMSException {
Properties ret;
String propName, propLabel;
if (tmpConnFactory == null) {
tmpConnFactory = (AdministeredObject) JMSObjFactory.createTopicConnectionFactory(new Properties());
}
ret = new Properties();
propName = ConnectionConfiguration.imqBrokerHostName;
propLabel = tmpConnFactory.getPropertyLabel(propName);
ret.setProperty(propName, propLabel);
propName = ConnectionConfiguration.imqBrokerHostPort;
propLabel = tmpConnFactory.getPropertyLabel(propName);
ret.setProperty(propName, propLabel);
propName = ConnectionConfiguration.imqConfiguredClientID;
propLabel = tmpConnFactory.getPropertyLabel(propName);
ret.setProperty(propName, propLabel);
return (ret);
}
/**
* Connect to the provider.
*
* @exception JMSException thrown if connection to the provider cannot be established or if an error occurs
*/
@Override
public void connectToProvider() throws JMSException {
connection = qcf.createQueueConnection(adminuserName, adminPassword);
connection.setExceptionListener(this);
connection.start();
session = connection.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
requestQueue = session.createQueue(MessageType.JMQ_ADMIN_DEST);
replyQueue = session.createTemporaryQueue();
sender = session.createSender(requestQueue);
sender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
receiver = session.createReceiver(replyQueue);
hello();
}
/**
* Disconnect from the provider.
*
* @exception JMSException thrown if connection to the provider cannot be closed or ir an error occurs
*/
@Override
public void disconnectFromProvider() throws JMSException {
sender.close();
receiver.close();
session.close();
try {
connection.close();
} catch (JMSException jmse) {
if (!secureTransportUsed) {
throw (jmse);
}
}
}
/**
* Create a physical Destination within the JMS Provider using the provided properties to define provider specific
* attributes. Destination is not automatically bound into JNDI namespace.
*
* @param destinationType QUEUE or TOPIC
* @param properties creation properties.
* @exception JMSException thrown if Queue could not be created.
*/
@Override
public void createProviderDestination(String destinationName, int destinationType, java.util.Map properties) throws JMSException {
ObjectMessage requestMesg = null;
Message replyMesg = null;
// Create DestinationInfo.
DestinationInfo di = new DestinationInfo();
di.setName(destinationName);
// REVISIT:
// We only check for queueDeliveryPolicy in the properties
// hard-coded string; left here because we are not sure
// if we are going to expose this attribute yet
String qPolicy = null;
/*
* Early initialization to be used in error messages
*/
int typeMask = this.getDestTypeMask(destinationType, null);
if (properties != null) {
if (properties.containsKey("queueDeliveryPolicy")) {
qPolicy = (String) properties.get("queueDeliveryPolicy");
typeMask = this.getDestTypeMask(destinationType, qPolicy);
}
if (properties.containsKey(BrokerCmdOptions.PROP_NAME_MAX_ACTIVE_CONSUMER_COUNT)) {
Object tmp = null;
String val = null;
tmp = properties.get(BrokerCmdOptions.PROP_NAME_MAX_ACTIVE_CONSUMER_COUNT);
if (tmp != null) {
if (!(tmp instanceof String)) {
JMSException jmse;
jmse = new JMSException(ar.getString(ar.E_SPI_DEST_CREATION_FAILED, DestType.toString(typeMask), destinationName) + "\n"
+ ar.getString(ar.E_SPI_ATTR_TYPE_NOT_STRING, BrokerCmdOptions.PROP_NAME_MAX_ACTIVE_CONSUMER_COUNT));
throw jmse;
}
val = (String) tmp;
try {
di.setMaxActiveConsumers(Integer.parseInt(val));
} catch (Exception e) {
JMSException jmse;
jmse = new JMSException(ar.getString(ar.E_SPI_DEST_CREATION_FAILED, DestType.toString(typeMask), destinationName) + "\n"
+ ar.getString(ar.E_INVALID_INTEGER_VALUE, val, BrokerCmdOptions.PROP_NAME_MAX_ACTIVE_CONSUMER_COUNT));
throw (jmse);
}
}
}
}
di.setType(typeMask);
requestMesg = session.createObjectMessage();
requestMesg.setJMSReplyTo(replyQueue);
requestMesg.setIntProperty(MessageType.JMQ_MESSAGE_TYPE, MessageType.CREATE_DESTINATION);
requestMesg.setObject(di);
sender.send(requestMesg);
replyMesg = receiver.receive(timeout);
replyMesg.acknowledge();
checkReplyTypeStatus(replyMesg, MessageType.CREATE_DESTINATION_REPLY);
}
/**
* Delete a physical destination within the JMS Provider.
*
* @param type Either QUEUE or TOPIC.
* @exception JMSException thrown if Queue could not be deleted.
*/
@Override
public void deleteProviderDestination(String destinationName, int type) throws JMSException {
ObjectMessage requestMesg = null;
Message replyMesg = null;
requestMesg = session.createObjectMessage();
requestMesg.setJMSReplyTo(replyQueue);
requestMesg.setIntProperty(MessageType.JMQ_MESSAGE_TYPE, MessageType.DESTROY_DESTINATION);
requestMesg.setStringProperty(MessageType.JMQ_DESTINATION, destinationName);
requestMesg.setIntProperty(MessageType.JMQ_DEST_TYPE, this.getDestTypeMask(type, null));
sender.send(requestMesg);
replyMesg = receiver.receive(timeout);
replyMesg.acknowledge();
checkReplyTypeStatus(replyMesg, MessageType.DESTROY_DESTINATION_REPLY);
}
/**
* Get all provider destinations.
*
* @return A multi dimensional array containing information about the JMS destinations. array[0] is a String[] listing
* the destination names. array[1] is a String[] listing the destination types.
* @exception JMSException thrown if array could not be obtained.
*/
@Override
public String[][] getProviderDestinations() throws JMSException {
ObjectMessage mesg = null;
mesg = session.createObjectMessage();
mesg.setJMSReplyTo(replyQueue);
mesg.setIntProperty(MessageType.JMQ_MESSAGE_TYPE, MessageType.GET_DESTINATIONS);
sender.send(mesg);
mesg = (ObjectMessage) receiver.receive(timeout);
mesg.acknowledge();
checkReplyTypeStatus(mesg, MessageType.GET_DESTINATIONS_REPLY);
Object obj;
if ((obj = mesg.getObject()) != null) {
if (obj instanceof Vector) {
Vector dests = (Vector) obj;
/*
* Remove temporary, internal and admin destinations by creating a new Vector and adding all the valid destinations into
* this new Vector.
*/
Vector validDests = new Vector();
for (int i = 0; i < dests.size(); i++) {
DestinationInfo di = (DestinationInfo) dests.elementAt(i);
if ((!MessageType.JMQ_ADMIN_DEST.equals(di.name)) && (!MessageType.JMQ_BRIDGE_ADMIN_DEST.equals(di.name))
&& (!DestType.isInternal(di.fulltype)) && (!DestType.isTemporary(di.type))) {
validDests.add(di);
}
}
int numElements = validDests.size();
String[][] destinations = new String[2][numElements];
for (int i = 0; i < numElements; i++) {
DestinationInfo di = (DestinationInfo) validDests.get(i);
destinations[0][i] = di.name;
destinations[1][i] = this.getDestinationType(di.type);
}
return destinations;
}
}
return null;
}
/**
* Start the provider.
*
* @param iMQHome Location of the broker executable.
* @param optArgs Array of optional broker command line arguments.
* @param serverName Instance name of the server.
* @exception IOException thrown if the server startup fails.
*/
@Override
public void startProvider(String iMQHome, String optArgs[], String serverName) throws IOException, JMSException {
String[] cmdLine = makeStartProviderCmdLine(iMQHome, optArgs, serverName, false);
// Log the command line we are about to execute
if (logger.isLoggable(Level.FINE)) {
String commandLineToLog = "";
for (int i = 0; i < cmdLine.length; i++) {
commandLineToLog = commandLineToLog + cmdLine[i] + " ";
}
logger.fine("MQJMSRA: Starting LOCAL broker with command line: " + commandLineToLog);
}
launchAndWatch(cmdLine);
}
/**
* @param iMQHome Location of the broker executable, ignored if argsOnly true
*/
@Override
public String[] makeStartProviderCmdLine(String iMQHome, String optArgs[], String serverName, boolean argsOnly) throws IOException, JMSException {
Vector v = new Vector();
String append = null;
if (!argsOnly) {
String iMQBrokerPath;
if (java.io.File.separator.equals("\\")) {
// Windows path
// <iMQHome>\\imqbrokersvc.exe -console
iMQBrokerPath = iMQHome + java.io.File.separator + "imqbrokersvc.exe";
append = "-console";
} else {
// Unix path.
// <iMQHome>/bin/imqbrokerd
iMQBrokerPath = iMQHome + java.io.File.separator + "imqbrokerd";
}
v.add(iMQBrokerPath);
}
String portStr = qcf.getProperty(ConnectionConfiguration.imqBrokerHostPort);
// Important : Do not change the command line parameter order
// unless you know what you are doing. Here are the
// constraints -
//
// 1. The "-javahome" argument, if present, must be first.
// Otherwise it does not work on Windows. The caller (of
// this method) is responsible for making sure that the
// "-javahome" argument is first in the 'optArgs' string.
//
// 2. The -name, -port and -silent arguments must be at
// placed at the end, so that they override anything
// specified in the optArgs...
//
// 3. The -bgnd argument is required for proper signal
// handling on solaris.
//
if (optArgs != null) {
for (int i = 0; i < optArgs.length; i++) {
v.add(optArgs[i]);
}
}
if (serverName != null) {
v.add("-name");
v.add(serverName);
}
if (append != null) {
v.add(append);
}
v.add("-port");
v.add(portStr);
// CR 6944162 Disable use of -bgnd (used on Solaris)
// because it prevents passwords being passed to the broker via standard input
// v.add("-bgnd");
// disable use of -errorwarn if FINE logging is enabled
if (!logger.isLoggable(Level.FINE)) {
// normally we only want to see errors in stdout
v.add("-ttyerrors");
}
if (!argsOnly) {
v.add("-managed");
v.add("-read-stdin");
}
return (String[]) v.toArray(new String[0]);
}
private void launchAndWatch(String[] cmdLine) throws IOException {
Process p = Runtime.getRuntime().exec(cmdLine);
BrokerWatcher brokerWatcher = new BrokerWatcher(p, cmdLine);
brokerWatcher.setDaemon(true);
brokerWatcher.start();
// start a thread to log any error messages from the new broker as a WARN message
boolean isError = true;
StreamGobbler errorGobbler = new StreamGobbler(p.getErrorStream(), isError, "Local broker: ");
errorGobbler.setDaemon(true);
errorGobbler.start();
// start a thread to log any output messages from the new broker as an INFO message
isError = false;
StreamGobbler outputGobbler = new StreamGobbler(p.getInputStream(), isError, "Local broker: ");
outputGobbler.setDaemon(true);
outputGobbler.start();
// generate the broker properties afresh
Properties brokerProps = brokerPropertiesHolder.getProperties();
// write properties to the input stream of the new process
try {
OutputStreamWriter osw = new OutputStreamWriter(p.getOutputStream());
BufferedWriter bw = new BufferedWriter(osw);
for (Enumeration e = brokerProps.propertyNames(); e.hasMoreElements();) {
String thisPropertyName = (String) e.nextElement();
String thisPropertyValue = brokerProps.getProperty(thisPropertyName);
bw.write(thisPropertyName + "=" + thisPropertyValue);
bw.newLine();
}
if (this.adminPassword != null) {
// if set, override any admin password set via brokerProps
bw.write("imq.imqcmd.password=" + this.adminPassword);
bw.newLine();
}
bw.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
/**
* Ping the provider.
*
* @exception JMSException thrown if ping fails
*/
@Override
public void pingProvider() throws JMSException {
// temporarily turn off logging because we do not want to log a message if the provider is not running
// as this might not be an error.
Logger rootLogger = Logger.getLogger(ConnectionImpl.ROOT_LOGGER_NAME);
Level savedLevel = rootLogger.getLevel();
rootLogger.setLevel(Level.SEVERE);
Connection pingConn = null;
try {
pingConn = qcf.createQueueConnection(adminuserName, adminPassword);
} finally {
// re-enable logging logging
rootLogger.setLevel(savedLevel);
}
try {
pingConn.setExceptionListener(this);
pingConn.start();
} finally {
try {
pingConn.close();
} catch (JMSException jmse) {
if (!secureTransportUsed) {
throw (jmse);
}
}
}
}
/**
* Get the property value from a provider
*
* @exception JMSException thrown if the get fails.
*/
private String getProviderPropertyValue(String propName) throws JMSException {
ObjectMessage requestMesg = null;
ObjectMessage replyMesg = null;
String propVal = null;
requestMesg = session.createObjectMessage();
requestMesg.setJMSReplyTo(replyQueue);
requestMesg.setIntProperty(MessageType.JMQ_MESSAGE_TYPE, MessageType.GET_BROKER_PROPS);
sender.send(requestMesg);
replyMesg = (ObjectMessage) receiver.receive(timeout);
replyMesg.acknowledge();
checkReplyTypeStatus(replyMesg, MessageType.GET_BROKER_PROPS_REPLY);
Object obj;
if ((obj = replyMesg.getObject()) != null) {
if (obj instanceof Properties) {
Properties props = (Properties) obj;
propVal = props.getProperty(propName);
}
}
return (propVal);
}
/**
* Get the instance name of the provider
*
* @exception JMSException thrown if the get fails.
*/
@Override
public String getProviderInstanceName() throws JMSException {
return (getProviderPropertyValue(BrokerConstants.PROP_NAME_BKR_INSTANCE_NAME));
}
/**
* Get the VARHOME directory of the provider
*
* @exception JMSException thrown if the get fails.
*/
@Override
public String getProviderVarHome() throws JMSException {
return (getProviderPropertyValue(BrokerConstants.PROP_NAME_BKR_VARHOME));
}
/**
* Shutdown the provider. @exception JMSException thrown if the shutdown fails @throws
*/
@Override
public void shutdownProvider() throws JMSException {
try {
tryToShutdownProvider();
} catch (JMSException jmse) {
if ((com.sun.messaging.jmq.jmsclient.resources.ClientResources.X_CONSUMER_CLOSED.equals(jmse.getErrorCode()))
|| (com.sun.messaging.jmq.jmsclient.resources.ClientResources.X_SESSION_CLOSED.equals(jmse.getErrorCode()))) {
// we seem to have lost the connection - try once to reconnect before giving up
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
connectToProvider();
tryToShutdownProvider();
} else {
// re-throw the exception if not X_CONSUMER_CLOSED or X_SESSION_CLOSED
throw jmse;
}
}
}
private void tryToShutdownProvider() throws JMSException {
ObjectMessage requestMesg;
Message replyMesg;
requestMesg = session.createObjectMessage();
requestMesg.setJMSReplyTo(replyQueue);
requestMesg.setIntProperty(MessageType.JMQ_MESSAGE_TYPE, MessageType.SHUTDOWN);
sender.send(requestMesg);
// disable reconnect since we don't want the client to try to reconnect
// ConnectionImpl ci = (ConnectionImpl)connection;
// ci.setImqReconnect(false);
replyMesg = receiver.receive(timeout);
checkReplyTypeStatus(replyMesg, MessageType.SHUTDOWN_REPLY);
}
/**
* Restart the provider.
*
* @exception JMSException thrown if the restart fails
*/
@Override
public void restartProvider() throws JMSException {
ObjectMessage requestMesg = null;
Message replyMesg = null;
requestMesg = session.createObjectMessage();
requestMesg.setJMSReplyTo(replyQueue);
requestMesg.setIntProperty(MessageType.JMQ_MESSAGE_TYPE, MessageType.SHUTDOWN);
requestMesg.setBooleanProperty(MessageType.JMQ_RESTART, true);
sender.send(requestMesg);
replyMesg = receiver.receive(timeout);
checkReplyTypeStatus(replyMesg, MessageType.SHUTDOWN_REPLY);
}
/**
* Return the provider host name
*/
@Override
public String getProviderHostName() throws JMSException {
return qcf.getProperty(ConnectionConfiguration.imqBrokerHostName);
}
/**
* Return the provider host port number
*/
@Override
public String getProviderHostPort() throws JMSException {
return qcf.getProperty(ConnectionConfiguration.imqBrokerHostPort);
}
/**
* Delete provider instance.
*
* @param mqBinDir Location of MQ's bin directory, which contains the broker executable.
* @param optArgs Optional broker command line arguments.
* @param serverName instance name of MQ broker to delete
* @exception JMSException thrown if the delete fails.
*/
@Override
public void deleteProviderInstance(String mqBinDir, String optArgs, String serverName) throws IOException, JMSException {
String iMQBrokerPath;
int exitCode = 0;
boolean interrupted = false;
if (java.io.File.separator.equals("\\")) {
// Windows path
// <mqBinDir>\\bin\\imqbrokerd.exe
iMQBrokerPath = mqBinDir + java.io.File.separator + "imqbrokerd.exe";
} else {
// Unix path.
// <mqBinDir>/bin/imqbrokerd
iMQBrokerPath = mqBinDir + java.io.File.separator + "imqbrokerd";
}
// String portStr =
// qcf.getProperty(ConnectionConfiguration.imqBrokerHostPort);
// Important : Do not change the command line parameter order
// unless you know what you are doing. Here are the
// constraints -
//
// 1. The "-javahome" argument, if present, must be first.
// Otherwise it does not work on Windoze. The caller (of
// this method) is responsible for making sure that the
// "-javahome" argument is first in the 'optArgs' string.
//
// 2. The -name, -port and -silent arguments must be at
// placed at the end, so that they override anything
// specified in the optArgs...
//
// 3. The -bgnd argument is required for proper signal
// handling on solaris.
//
String cmdLine = iMQBrokerPath;
if (optArgs != null) {
cmdLine = cmdLine + " " + optArgs;
}
if (serverName != null) {
cmdLine = cmdLine + " -name " + serverName;
}
cmdLine = cmdLine + " -remove instance -silent -force";
Process p = Runtime.getRuntime().exec(cmdLine);
// Close the receiver end of stdout and stderr streams.
// Otherwise the child process blocks while trying to
// write...
p.getInputStream().close();
p.getErrorStream().close();
try {
p.waitFor();
exitCode = p.exitValue();
} catch (InterruptedException iex) {
interrupted = true;
}
if (interrupted) {
throw new jakarta.jms.JMSException(ar.getKString(ar.X_JMSSPI_DELETE_INST_INT_PREM, serverName));
}
/*
* Proper handling of exit codes will be done once the following bug is fixed: 4713518 - imqbrokerd -remove:
* Enhancements needed for app server integration
*/
switch (exitCode) {
case BrokerExitCode.NORMAL:
break;
case BrokerExitCode.INSTANCE_NOT_EXISTS:
throw new jakarta.jms.JMSException(ar.getKString(ar.X_JMSSPI_DELETE_INST_NOT_EXIST, serverName));
case BrokerExitCode.INSTANCE_BEING_USED:
throw new jakarta.jms.JMSException(ar.getKString(ar.X_JMSSPI_DELETE_INST_BEING_USED, serverName));
case BrokerExitCode.NO_PERMISSION_ON_INSTANCE:
throw new jakarta.jms.JMSException(ar.getKString(ar.X_JMSSPI_DELETE_INST_NO_PERM, serverName));
case BrokerExitCode.PROBLEM_REMOVING_PERSISTENT_STORE:
throw new jakarta.jms.JMSException(ar.getKString(ar.X_JMSSPI_DELETE_INST_PROB_RM_STORE, serverName));