-
Notifications
You must be signed in to change notification settings - Fork 33
/
ConnectionImpl.java
3163 lines (2617 loc) · 108 KB
/
ConnectionImpl.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.jmsclient;
import jakarta.jms.*;
import java.util.Vector;
import java.util.Properties;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Objects;
import java.util.logging.*;
import java.io.PrintStream;
import java.net.InetAddress;
import com.sun.messaging.jmq.Version;
import com.sun.messaging.AdministeredObject;
import com.sun.messaging.ConnectionConfiguration;
import com.sun.messaging.jmq.ClientConstants;
import com.sun.messaging.jmq.auth.api.client.*;
import com.sun.messaging.jmq.io.PacketType;
import com.sun.messaging.jmq.io.ReadWritePacket;
import com.sun.messaging.jmq.util.DebugPrinter;
import com.sun.messaging.jms.MQRuntimeException;
import com.sun.messaging.jms.notification.*;
import com.sun.messaging.jmq.jmsclient.notification.*;
import com.sun.messaging.jmq.jmsclient.resources.*;
import com.sun.messaging.jms.MQIllegalStateRuntimeException;
import com.sun.messaging.jms.MQInvalidClientIDRuntimeException;
/**
* A JMS Connection is a client's active connection to its JMS provider. It will typically allocate provider resources
* outside the Java virtual machine.
*
* <P>
* Connections support concurrent use.
*
* <P>
* A Connection serves several purposes:
*
* <UL>
* <LI>It encapsulates an open connection with a JMS provider. It typically represents an open TCP/IP socket between a
* client and a provider service daemon.
* <LI>Its creation is where client authenticating takes place.
* <LI>It can specify a unique client identifier.
* <LI>It provides ConnectionMetaData.
* <LI>It supports an optional ExceptionListener.
* </UL>
*
* <P>
* Due to the authentication and communication setup done when a Connection is created, a Connection is a relatively
* heavy-weight JMS object. Most clients will do all their messaging with a single Connection. Other more advanced
* applications may use several Connections. JMS does not architect a reason for using multiple connections; however,
* there may be operational reasons for doing so.
*
* <P>
* A JMS client typically creates a Connection; one or more Sessions; and a number of message producers and consumers.
* When a Connection is created it is in stopped mode. That means that no messages are being delivered.
*
* <P>
* It is typical to leave the Connection in stopped mode until setup is complete. At that point the Connection's start()
* method is called and messages begin arriving at the Connection's consumers. This setup convention minimizes any
* client confusion that may result from asynchronous message delivery while the client is still in the process of
* setting itself up.
*
* <P>
* A Connection can immediately be started and the setup can be done afterwards. Clients that do this must be prepared
* to handle asynchronous message delivery while they are still in the process of setting up.
*
* <P>
* A message producer can send messages while a Connection is stopped.
*
* @see jakarta.jms.ConnectionFactory
* @see jakarta.jms.QueueConnection
* @see jakarta.jms.TopicConnection
*/
public class ConnectionImpl implements com.sun.messaging.jms.Connection, Traceable, ContextableConnection {
protected static final Version version = new Version();
private boolean daemonThreads = false;
private boolean hasNamespace = false;
private String raNamespaceUID = null;
private Object nsSyncObj = new Object();
ExceptionListener exceptionListener = null;
protected String clientID = null;
protected String clientIPAddress = null;
protected ReadChannel readChannel = null;
protected WriteChannel writeChannel = null;
protected ProtocolHandler protocolHandler = null;
private AuthenticationProtocolHandler authenticationHandler = null;
// XXX PROTOCOL3.5 --
protected FlowControl flowControl = null;
// XXX PROTOCOL3.5 --
// Improved reconnect and connection failover.
protected ConnectionInitiator initiator = null;
protected boolean reconnecting = false;
private Object reconnectSyncObj = new Object();
// XXX PROTOCOL3.5 --
// All the producers for this connection. We need to quickly find
// the producer object when we get RESUME_FLOW packets...
protected Hashtable producers = new Hashtable();
// table to hold Consumer objects
protected InterestTable interestTable = null;
// table to hold SessionQueue objects. pkts are put in SessionQueue based
// on sessionID
protected ReadQTable readQTable = null;
// table to hold queues for acknowledgements. - XXX PROTOCOL2.1 change.
protected ReadQTable ackQTable = null;
// XXX PROTOCOL2.1 change.
// table to hold RequestMetaData. Such as interestID/consumer pair.
protected Hashtable requestMetaData = null;
// bug 6172663
// protected boolean isTopicConnection = true;
protected boolean isTopicConnection = false;
// bug 6172663
protected boolean isQueueConnection = false;
protected boolean isStopped = true;
// XXX:GT TBF **** this is closed until opened !!!
protected boolean isClosed = true;
// bug 6189645 -- general blocking issues.
// this flag is set to true when close() is called.
protected boolean isCloseCalled = false;
// protected boolean isClosing = false;
protected boolean isSuspended = false;
// table to hold Sessions. When a session is created, it is put in here.
protected Vector sessionTable = null;
protected Vector connectionConsumerTable = null;
protected Vector tempDestTable = null;
// next available session ID
protected long nextSessionId = 0;
// if nextSessionId reached MAX_INTEREST_ID, this flag is set to true
protected boolean sessionIdReset = false;
// next available transactionID
protected int nextTransactionID = 0;
protected boolean openedFromXA = false;
// max queue size in the session queue.
// protected int maxQueueSize = 1000;
// protected int minQueueSize = 10;
// setting this to true if wanted to have session reader to check queue
// sizes and protect the system from memory over flow.
protected boolean protectMode = false;
// default value for flow control message size
protected int flowControlMsgSize = 100;
// water mark - used in flow control
// not used if protectMode == false
protected int flowControlWaterMark = 1000;
// XXX PROTOCOL3.5 New consumer flow control attributes.
protected int prefetchMaxMsgCount = 100;
protected int prefetchThresholdPercent = 50;
// 4.5
protected boolean consumerFlowLimitPrefetch = true;
// 5.0
protected int onMessageExRedeliveryAttempts = 1;
protected long onMessageExRedeliveryIntervals = 500L; // millisecs
// XXX PROTOCOL3.5 Connection reconnect & failover attributes.
protected volatile boolean imqReconnect = false;
// Enable Shared ClientID for this connection
protected boolean imqEnableSharedClientID = false;
// Enable Shared Subscriptions for this connection (non-durable)
protected boolean imqEnableSharedSubscriptions = false;
// dups ok limit. default is 10
protected int dupsOkLimit = 10;
// if set, we check if unack msgs has exceeded the limit.
protected boolean isAckLimited = false;
// client ack limit. default 100.
protected int ackLimit = 100;
// for temporary destination name generation.
private int tempDestSequence = 0;
// for connection recovery to check if this connection has associated
// with temp destination. We do not recover connection if there is
// active temp destination for the connection.
private int tempDestCounter = 0;
// flag for session reader to check if the connection is broken
// This flag is set by ReadChannel when connection is broken.
protected volatile boolean connectionIsBroken = false;
// flag to indicate connection recover is in process
protected volatile boolean recoverInProcess = false;
// connection ID - for thread naming purpose
// XXX PROTOCOL2.1 from int to long.
private static long nextConnectionID = 0;
// current connection ID
protected Long connectionID = null;
// local connection ID. This is used for local ID. The connectionID
// will be reassigned by broker.
protected long localID = 0;
// brokerSessionID (sent by broker in HELLO_REPLY)
protected long brokerSessionID = 0;
// Override flags and values for Administered JMS Msg Headers
protected boolean jmqOverrideJMSMsgHeaders = false;
protected boolean jmqOverrideJMSDeliveryMode = false;
protected boolean jmqOverrideJMSExpiration = false;
protected boolean jmqOverrideJMSPriority = false;
protected boolean jmqOverrideMsgsToTempDests = false;
protected int jmqJMSDeliveryMode = DeliveryMode.PERSISTENT;
protected long jmqJMSExpiration = 0L;
protected int jmqJMSPriority = 4;
// dups ok ack time out properties - dupsOkPerf
// if set, dups ok acks when reached unacked limit or session Q is empty.
protected boolean dupsOkAckOnEmptyQueue = false;
// The magic number from Dipol.
protected long dupsOkAckTimeout = 7000L; // seven seconds.
protected long asyncSendCompletionWaitTimeout = 180000L; // 3min
/**
*
* Value of ConnectionFactory property imqSocketConnectTimeout This property defines the socket timeout, in
* milliseconds, used when a TCP connection is made to the broker. A timeout of zero is interpreted as an infinite
* timeout. The connection will then block until established or an error occurs. This property is used when connecting
* to the port mapper as well as when connecting to the required service.
*/
protected int imqSocketConnectTimeout = 0;
/**
* Port Mapper client socket read timeout
*/
protected Integer imqPortMapperSoTimeout = null;
/**
* flag used for setting client ID. If set to false, API user can not set clientID.
*/
protected boolean allowToSetClientID = true;
protected boolean adminSetClientID = false;
// sync object for synchronizing sequences
private Object syncObj = new Object();
// save this for reconnect
private String userName = null;
private String password = null;
private String ackOnProduce = null;
private String ackOnAcknowledge = null;
private String connectionType = ClientConstants.CONNECTIONTYPE_NORMAL;
private boolean adminKeyUsed = false;
protected ConnectionMetaDataImpl connectionMetaData = null;
private boolean debug = Debug.debug;
// package protect field, so that protocol handler can access it.
Properties configuration = null;
// ConnectionConsumer workaround for 4715054
private boolean isDedicatedToConnectionConsumer = true;
private volatile boolean negotiateProtocolLevel = false;
private int brokerProtocolLevel = 0;
private String brokerVersion = "Unknown";
// ping interval -- default to 30 seconds.
private long imqPingInterval = 30 * 1000;
// blocking wait timeout -- 30 secs.
private static long WAIT_TIME_OUT = 30000;
// event listener
protected EventListener eventListener = null;
protected EventHandler eventHandler = null;
// HA variables.
protected volatile boolean isConnectedToHABroker = false;
protected String JMQClusterID = null;
protected Long JMQStoreSession = null;
protected String JMQBrokerList = null;
protected String savedJMQBrokerList = null;
protected String JMQStoreOwner = null;
protected String lastContactedBrokerAddress = null;
// if set to true, client runtime will notify the connection event listener
// with all the MQ event available. Such as broker address list changed.
private boolean extendedEventNotification = false;
private boolean _appTransactedAck = false;
// root logging domain name
public static final String ROOT_LOGGER_NAME = "jakarta.jms";
// connection logging domain name.
public static final String CONNECTION_LOGGER_NAME = ROOT_LOGGER_NAME + ".connection";
protected static final Logger connectionLogger = Logger.getLogger(CONNECTION_LOGGER_NAME, ClientResources.CLIENT_RESOURCE_BUNDLE_NAME);
/**
* This flag is to over-ride imqReconnectEnabled flag.
*
* For HA, client runtime will always fail-over to HA broker if connection is broken. Th imqReconnectEnabled flag is
* ignored.
*
* This flag (private) is used to over-ride this behavior. This flag is NOT static as it is chaged in individual
* instances
*/
private boolean isHADisabled = Boolean.getBoolean("imq.ha.disabled");
/**
* called by protocol handler to check if JMQHAReconnect property should be set to true/false.
*
* Default is set to true.
*
* @return true if HA enabled, otherwise return false.
*/
public boolean isHAEnabled() {
return (isHADisabled == false);
}
/**
* @return true if connected to broker with pkt direct mode.
*/
public boolean isDirectMode() {
return this.protocolHandler.isDirectMode();
}
// Bug6664278 -- JMQ connections won?t close after broker is bounced.
// flag to turn off RA (from XAResorceImpl) re-open connection.
private volatile boolean disableReopenFromRA = false;
// This is the only constructor to be survived ...
public ConnectionImpl(Properties configuration, String userName, String password, String type) throws JMSException {
this.configuration = configuration;
this.userName = userName;
this.password = password;
if (ClientConstants.CONNECTIONTYPE_ADMINKEY.equals(type)) {
this.connectionType = ClientConstants.CONNECTIONTYPE_ADMIN;
adminKeyUsed = true;
} else {
// Only set if non-null; else default to initialized NORMAL
if (type != null) {
this.connectionType = type;
}
}
if (Objects.equals(this.connectionType, ClientConstants.CONNECTIONTYPE_ADMIN)) {
isHADisabled = true;
}
// obtain unique connectionID in this VM
// this is for debugging purpose only
connectionID = Long.valueOf(getNextConnectionID());
localID = connectionID.longValue();
// this over-ride auto detection feature for ra
// the information is logged in init method -- after "imqReconnect" flag is set.
// if (isHADisabled) {
// this.configuration.setProperty(ConnectionConfiguration.imqReconnectEnabled, Boolean.toString(false));
// } else if (isHAEnabled) {
// this.configuration.setProperty(ConnectionConfiguration.imqReconnectEnabled, Boolean.toString(true));
// }
init();
// if ( isConnectedToHABroker && (imqReconnect == false) ) {
// if ( ClientConstants.CONNECTIONTYPE_ADMIN.equals(connectionType)==false) {
// String reconnectInfo = AdministeredObject.cr.getKString(ClientResources.I_MQ_AUTO_RECONNECT_IS_DISABLED,
// this.getLastContactedBrokerAddress());
// connectionLogger.log (Level.WARNING, reconnectInfo);
// }
// }
logLifeCycle(ClientResources.I_CONNECTION_CREATED);
}
public long getLocalID() {
return localID;
}
public String getBrokerVersion() {
return brokerVersion;
}
protected void setBrokerSessionID(long id) {
brokerSessionID = id;
}
protected long getBrokerSessionID() {
return brokerSessionID;
}
/**
* Invoked from ReadChannel on HELLO_REPLY
*/
public void setBrokerVersion(String brokerVersion) {
if (debug) {
Debug.println("setBrokerVersion : " + brokerVersion);
}
this.brokerVersion = brokerVersion;
}
public long generateUID() throws JMSException {
return protocolHandler.generateUID();
}
protected int getBrokerProtocolLevel() {
return brokerProtocolLevel;
}
/**
* Invoked from ReadChannel on HELLO_REPLY
*/
protected void setBrokerProtocolLevel(int brokerProtocolLevel) {
if (debug) {
Debug.println("setBrokerProtocolLevel : " + brokerProtocolLevel);
}
this.brokerProtocolLevel = brokerProtocolLevel;
}
protected boolean checkBrokerProtocolLevel() throws JMSException {
return (brokerProtocolLevel >= PacketType.VERSION2);
}
/**
* check if the specified port number is valid.
*
* @param host the host to connect to.
* @param port the port number to connect to.
* @throws JMSException if port number is 0.
*/
public static void checkHostPort(String host, int port) throws JMSException {
// check if broker is paused.
if (port <= 0) {
String errorString0 = "[" + host + "," + port + "]";
String errorString = AdministeredObject.cr.getKString(AdministeredObject.cr.X_BROKER_PAUSED, errorString0);
JMSException jmse = new JMSException(errorString, AdministeredObject.cr.X_BROKER_PAUSED);
ExceptionHandler.throwJMSException(jmse);
}
}
public boolean getNegotiateProtocolLevel() {
return negotiateProtocolLevel;
}
public void setNegotiateProtocolLevel(boolean negotiateProtocolLevel) {
if (debug) {
Debug.println("setNegotiateProtocolLevel : " + negotiateProtocolLevel);
}
this.negotiateProtocolLevel = negotiateProtocolLevel;
}
protected void hello() throws JMSException {
protocolHandler.hello(userName, password);
}
protected void hello(boolean reconnect) throws JMSException {
protocolHandler.hello(userName, password, connectionID);
}
/**
* This method blocks (if root cause is IOException) until reconnected to a take over broker.
*
*/
protected boolean waitForReconnecting(Exception e) {
boolean isReconnected = false;
/**
* proceed only if auto reconnect is enabled.
*/
if (imqReconnect == false) {
return false;
}
if ((e instanceof JMSException) == false) {
return false;
}
JMSException jmse = (JMSException) e;
/**
* wait for reconnecting only if IO errors.
*/
String ecode = jmse.getErrorCode();
if (ClientResources.X_NET_WRITE_PACKET.equals(ecode) || ClientResources.X_NET_ACK.equals(ecode)) {
SessionImpl.yield();
try {
checkReconnecting(null);
if (isCloseCalled || connectionIsBroken) {
isReconnected = false;
} else {
isReconnected = true;
}
} catch (Exception e2) {
isReconnected = false;
}
}
return isReconnected;
}
// bug 6189645 -- general blocking issues.
protected void checkReconnecting(ReadWritePacket pkt) throws JMSException {
checkReconnecting(pkt, true);
}
protected void checkReconnecting(ReadWritePacket pkt, boolean block) throws JMSException {
synchronized (reconnectSyncObj) {
while (reconnecting) {
if (!block) {
throw new JMSException("XXXWOULD-BLOCK");
}
try {
reconnectSyncObj.wait(WAIT_TIME_OUT); // wake up 30 secs
} catch (Exception e) {
}
// we want to exit if any of the following is true.
if (connectionIsBroken || isCloseCalled) {
return;
}
}
}
// XXX HAWK: throw JMSException if the pkt contains session ID.
// the session ID is invalidated because of fail over.
if (pkt != null) {
checkPacketType(pkt);
}
}
private void checkPacketType(ReadWritePacket pkt) throws JMSException {
boolean isAllowed = this.isAllowedToFailover(pkt);
if (isAllowed == false) {
String msg = AdministeredObject.cr.getKString(AdministeredObject.cr.X_NET_WRITE_PACKET) + ", packet type = "
+ PacketType.getString(pkt.getPacketType());
JMSException jmse = new com.sun.messaging.jms.JMSException(msg, AdministeredObject.cr.X_NET_WRITE_PACKET);
ExceptionHandler.throwJMSException(jmse);
}
}
/**
* Do not send pkt to fail-over broker if 1. pkt header contains JMQSessionID. 2. pkt is one of the pkt types as below.
*/
private boolean isAllowedToFailover(ReadWritePacket pkt) {
Hashtable ht = null;
try {
ht = pkt.getProperties();
} catch (Exception e) {
connectionLogger.log(Level.WARNING, ClientResources.X_PACKET_GET_PROPERTIES, e);
// unexpected error. should never happen. do not continue.
return false;
}
if (ht != null) {
Object sid = ht.get("JMQSessionID");
if (sid != null) {
// not allowed if contains JMQSessionID.
return false;
}
}
int packetType = pkt.getPacketType();
// do not send pkt to take-over broker for any of the pkt below.
if (packetType == PacketType.ACKNOWLEDGE || packetType == PacketType.ADD_CONSUMER || packetType == PacketType.ADD_PRODUCER
|| packetType == PacketType.AUTHENTICATE || packetType == PacketType.CREATE_DESTINATION || packetType == PacketType.CREATE_SESSION
|| packetType == PacketType.DELETE_CONSUMER || packetType == PacketType.DELETE_PRODUCER || packetType == PacketType.DESTROY_DESTINATION
|| packetType == PacketType.DESTROY_SESSION || packetType == PacketType.PREPARE_TRANSACTION || packetType == PacketType.SET_CLIENTID
|| packetType == PacketType.START_TRANSACTION || packetType == PacketType.ROLLBACK_TRANSACTION) {
return false;
}
// do not send pkt for transacted messages. The tid is no longer valid.
if (packetType == PacketType.MESSAGE || packetType == PacketType.BYTES_MESSAGE || packetType == PacketType.MAP_MESSAGE
|| packetType == PacketType.TEXT_MESSAGE || packetType == PacketType.OBJECT_MESSAGE || packetType == PacketType.STREAM_MESSAGE) {
long tid = pkt.getTransactionID();
if (tid > 0) {
return false;
}
}
// default to true
return true;
}
public boolean getReconnecting() {
synchronized (reconnectSyncObj) {
return reconnecting;
}
}
public void setReconnecting(boolean reconnecting) {
synchronized (reconnectSyncObj) {
this.reconnecting = reconnecting;
reconnectSyncObj.notifyAll();
}
}
/**
* called by ReadChannel before peform recover.
*/
protected void checkAndSetReconnecting() throws JMSException {
/**
* If this is true, we do nothing here.
*/
synchronized (reconnectSyncObj) {
if (this.reconnecting) {
// throw new JMSException ("Cannot recover -- Recover in progress.");
} else {
// we only set this if the following conditions are met.
if (connectionIsBroken == false && isCloseCalled == false) {
this.setReconnecting(true);
}
}
}
}
public boolean useNamespace() {
synchronized (nsSyncObj) {
return hasNamespace;
}
}
public synchronized void setRANamespaceUID(String raNamespaceUID) {
synchronized (nsSyncObj) {
imqEnableSharedClientID = true;
imqEnableSharedSubscriptions = true;
this.raNamespaceUID = raNamespaceUID;
hasNamespace = true;
}
}
public String getRANamespaceUID() {
synchronized (nsSyncObj) {
return raNamespaceUID;
}
}
/**
* When connection recovery failed, this is called to ensure the system quit gracefully.
*
* Errors will be handled by ReadChannel class.
*/
// protected void abort(JMSException jmse) {
// readChannel.abort();
// protocolHandler.abort();
// if ( eventListener != null ) {
// triggerConnectionExitEvent(jmse);
// }
// }
/**
* Get host and port of the broker to establish connection. Construct an instance of InterestTable. Construct an
* instance of ReadChannel. Construct an instance of WriteChannel. Construct an instance of sessionTable.
*
* @exception JMSException any internal errors caused by constructing the above tables.
*/
private void init() throws JMSException {
try {
// interest table
interestTable = new InterestTable();
// table to hold session Qs
readQTable = new ReadQTable();
// table to store ack qs. -- protocol 2.1 change.
ackQTable = new ReadQTable();
requestMetaData = new Hashtable();
// construct session table
sessionTable = new Vector();
connectionConsumerTable = new Vector();
// construct temp dest table
tempDestTable = new Vector();
String prop = null;
int propval = 0;
long lpropval = 0L;
/**
* Check if admin has set the client ID for the user.
*/
String cid = getTrimmedProperty(ConnectionConfiguration.imqConfiguredClientID);
if (cid != null) {
clientID = cid;
/**
* After init(), we send setClientID protocol to broker if this is set to true.
*/
adminSetClientID = true;
}
prop = getProperty("imq.DaemonThreads", "false");
if (Boolean.parseBoolean(prop) == true) {
daemonThreads = true;
}
// Bug6664278 -- JMQ connections won?t close after broker is
// bounced.
// flag to turn off RA (from XAResorceImpl) re-open connection.
prop = getProperty("imq.disableReopenFramRA", "false");
if (Boolean.parseBoolean(prop) == true) {
disableReopenFromRA = true;
}
/**
* Check and initialize override properties for msg headers
*/
prop = getTrimmedProperty(ConnectionConfiguration.imqOverrideJMSDeliveryMode);
if (Boolean.parseBoolean(prop) == true) {
prop = getTrimmedProperty(ConnectionConfiguration.imqJMSDeliveryMode);
if (ConnectionConfiguration.JMSDeliveryMode_PERSISTENT.equals(prop)) {
jmqJMSDeliveryMode = DeliveryMode.PERSISTENT;
jmqOverrideJMSDeliveryMode = true;
}
if (ConnectionConfiguration.JMSDeliveryMode_NON_PERSISTENT.equals(prop)) {
jmqJMSDeliveryMode = DeliveryMode.NON_PERSISTENT;
jmqOverrideJMSDeliveryMode = true;
}
}
prop = getTrimmedProperty(ConnectionConfiguration.imqOverrideJMSExpiration);
if (Boolean.parseBoolean(prop) == true) {
prop = getTrimmedProperty(ConnectionConfiguration.imqJMSExpiration);
lpropval = Long.parseLong(prop);
if (lpropval >= 0L) {
jmqJMSExpiration = lpropval;
jmqOverrideJMSExpiration = true;
}
}
prop = getTrimmedProperty(ConnectionConfiguration.imqOverrideJMSPriority);
if (Boolean.parseBoolean(prop) == true) {
prop = getTrimmedProperty(ConnectionConfiguration.imqJMSPriority);
propval = Integer.parseInt(prop);
if (propval >= 0 && propval <= 9) {
jmqJMSPriority = propval;
jmqOverrideJMSPriority = true;
}
}
if (jmqOverrideJMSDeliveryMode || jmqOverrideJMSExpiration || jmqOverrideJMSPriority) {
jmqOverrideJMSMsgHeaders = true;
}
prop = getTrimmedProperty(ConnectionConfiguration.imqOverrideJMSHeadersToTemporaryDestinations);
jmqOverrideMsgsToTempDests = Boolean.parseBoolean(prop);
/**
* Check if the the admin disallow to set client id.
*/
String disableSetID = getProperty(ConnectionConfiguration.imqDisableSetClientID);
if (Boolean.parseBoolean(disableSetID) == true) {
setClientIDFlag();
}
// protect mode
prop = getProperty(ConnectionConfiguration.imqConnectionFlowLimitEnabled);
if (Boolean.parseBoolean(prop) == true) {
protectMode = true;
}
/**
* water mark - used in flow control used only if protectMode == true
*/
prop = getTrimmedProperty(ConnectionConfiguration.imqConnectionFlowLimit);
if (prop != null) {
flowControlWaterMark = Integer.parseInt(prop);
}
// flow control message size
prop = getTrimmedProperty(ConnectionConfiguration.imqConnectionFlowCount);
if (prop != null) {
flowControlMsgSize = Integer.parseInt(prop);
}
// XXX PROTOCOL3.5
// Consumer flow control attribute
prop = getTrimmedProperty(ConnectionConfiguration.imqConsumerFlowLimit);
if (prop != null) {
prefetchMaxMsgCount = Integer.parseInt(prop);
}
// XXX PROTOCOL3.5
// Consumer flow control attribute
prop = getTrimmedProperty(ConnectionConfiguration.imqConsumerFlowThreshold);
if (prop != null) {
prefetchThresholdPercent = Integer.parseInt(prop);
}
// 4.5
prop = getProperty(ConnectionConfiguration.imqConsumerFlowLimitPrefetch, "true");
consumerFlowLimitPrefetch = Boolean.parseBoolean(prop);
if (!consumerFlowLimitPrefetch) {
prefetchMaxMsgCount = 1;
prefetchThresholdPercent = 0;
}
// 5.0
prop = getProperty(ConnectionConfiguration.imqOnMessageExceptionRedeliveryAttempts, String.valueOf(onMessageExRedeliveryAttempts));
if (prop != null) {
int val = Integer.parseInt(prop);
if (val < 1) {
val = 1;
}
onMessageExRedeliveryAttempts = val;
}
// 5.0
prop = getProperty(ConnectionConfiguration.imqOnMessageExceptionRedeliveryIntervals, String.valueOf(onMessageExRedeliveryIntervals));
if (prop != null) {
long val = Long.parseLong(prop);
if (val < 0) {
val = 0;
}
onMessageExRedeliveryIntervals = val;
}
prop = getTrimmedProperty(ConnectionConfiguration.imqReconnectEnabled);
if (prop != null) {
imqReconnect = Boolean.parseBoolean(prop);
}
prop = getTrimmedProperty(ConnectionConfiguration.imqEnableSharedClientID);
if (prop != null) {
imqEnableSharedClientID = Boolean.parseBoolean(prop);
}
ackOnProduce = getTrimmedProperty(ConnectionConfiguration.imqAckOnProduce);
ackOnAcknowledge = getTrimmedProperty(ConnectionConfiguration.imqAckOnAcknowledge);
String valstr = getTrimmedProperty(ConnectionConfiguration.imqAsyncSendCompletionWaitTimeout);
if (valstr != null) {
long val = Long.parseLong(valstr);
if (val > 0L) {
asyncSendCompletionWaitTimeout = val;
}
}
// dups ok limit
String dupsOk = System.getProperty("imqDupsOkLimit");
if (dupsOk != null) {
dupsOkLimit = Integer.parseInt(dupsOk);
}
// dups ok ack on timeout
prop = System.getProperty("imqDupsOkAckTimeout");
if (prop != null) {
dupsOkAckTimeout = Integer.parseInt(prop);
}
prop = getTrimmedProperty(ConnectionConfiguration.imqPortMapperSoTimeout);
if (prop != null) {
imqPortMapperSoTimeout = Integer.valueOf(prop);
if (imqPortMapperSoTimeout.intValue() < 0) {
imqPortMapperSoTimeout = null;
}
}
// Work out what socket timeout, in milliseconds, should be used when a TCP connection is made to the broker.
// this may be defined either using a system property imqSocketConnectTimeout
// or using a connection factory property imqSocketConnectTimeout
// Since the connection factory property was added after the system property was added
// in order to allow backwards compatibility, the system property is always used if set
String tmpVal = System.getProperty("imqSocketConnectTimeout");
if (tmpVal != null) {
// set via system property
imqSocketConnectTimeout = Integer.parseInt(tmpVal);
} else {
// not set via system property
prop = getTrimmedProperty(ConnectionConfiguration.imqSocketConnectTimeout);
if (prop != null) {
// set via connection factory property
imqSocketConnectTimeout = Integer.parseInt(prop);
}
}
// dups ok ack on empty queue
prop = System.getProperty("imqDupsOkAckOnEmptyQueue");
if (prop != null) {
dupsOkAckOnEmptyQueue = Boolean.parseBoolean(prop);
}
// client Ack Limit
String ackCount = System.getProperty("imqAckLimit");
if (ackCount != null) {
ackLimit = Integer.parseInt(ackCount);
}
// if ack is limited, we check the ack count to make sure
// unacked messages do not exceed the ack count limit
// default is false
String isLimited = System.getProperty("imqAckIsLimited");
if (isLimited != null) {
if (isLimited.equals("true")) {
isAckLimited = true;
}
}
// ConnectionConsumer workaround 4715054
String dedicateToCC = System.getProperty("imq.dedicateToConnectionConsumer");
if (dedicateToCC != null) {
if (dedicateToCC.equals("false")) {
isDedicatedToConnectionConsumer = false;
}
}
String pInterval = getTrimmedProperty(ConnectionConfiguration.imqPingInterval);
if (pInterval != null) {
int tmp = Integer.parseInt(pInterval);
if (tmp <= 0) {
imqPingInterval = 0;
} else {
imqPingInterval = tmp * 1000L;
}
}
// XXX PROTOCOL2.1 --
// Improved reconnect and connection failover.
initiator = new ConnectionInitiator(this);