-
Notifications
You must be signed in to change notification settings - Fork 33
/
DirectSession.java
1899 lines (1765 loc) · 79.5 KB
/
DirectSession.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.jms.ra;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Vector;
import java.util.logging.Logger;
import jakarta.jms.BytesMessage;
import jakarta.jms.Destination;
import jakarta.jms.InvalidDestinationException;
import jakarta.jms.InvalidSelectorException;
import jakarta.jms.JMSSecurityException;
import jakarta.jms.JMSException;
import jakarta.jms.MapMessage;
import jakarta.jms.Message;
import jakarta.jms.MessageConsumer;
import jakarta.jms.MessageFormatException;
import jakarta.jms.MessageProducer;
import jakarta.jms.ObjectMessage;
import jakarta.jms.Queue;
import jakarta.jms.QueueBrowser;
import jakarta.jms.QueueReceiver;
import jakarta.jms.QueueSender;
import jakarta.jms.Session;
import jakarta.jms.StreamMessage;
import jakarta.jms.TextMessage;
import jakarta.jms.Topic;
import jakarta.jms.TopicPublisher;
import jakarta.jms.TopicSubscriber;
import com.sun.messaging.AdministeredObject;
import com.sun.messaging.jmq.io.JMSPacket;
import com.sun.messaging.jmq.io.SysMessageID;
import com.sun.messaging.jmq.jmsclient.ExceptionHandler;
import com.sun.messaging.jmq.jmsclient.resources.ClientResources;
import com.sun.messaging.jmq.jmsserver.util.BrokerException;
import com.sun.messaging.jmq.jmsservice.ConsumerClosedNoDeliveryException;
import com.sun.messaging.jmq.jmsservice.JMSAck;
import com.sun.messaging.jmq.jmsservice.JMSService;
import com.sun.messaging.jmq.jmsservice.JMSService.MessageAckType;
import com.sun.messaging.jmq.jmsservice.JMSService.SessionAckMode;
import com.sun.messaging.jmq.jmsservice.JMSServiceException;
import com.sun.messaging.jmq.jmsservice.JMSServiceReply;
import com.sun.messaging.jms.IllegalStateException;
/**
* DirectSession encapsulates JMS Session behavior for MQ DIRECT mode operation
*/
public class DirectSession implements jakarta.jms.Session, jakarta.jms.QueueSession, jakarta.jms.TopicSession {
/**
* The JMSService for this DirectSession
*/
protected JMSService jmsservice;
/**
* The parent DirectConnection that created this DirectSession
*/
protected DirectConnection dc;
/**
* The connectionId of the parent DirectConnectio
*/
protected long connectionId;
/**
* The sessionId for this DirectSession
*/
protected long sessionId;
/**
*
*/
protected SessionAckMode ackMode;
/**
* Holds the closed state of this DirectSession
*/
protected boolean isClosed;
protected boolean isClosing;
/**
* Holds the stopped state of this DirectSession
*/
protected boolean isStopped;
/**
* Indicates whether the DirectSession is servicing an Async Consumer. When a session has an async consumer on it, it
* can no longer be used by any thread other than the thread that delivers messages to that asynch consumer.
*/
protected boolean isAsync;
/** inDeliver is true as long as the session is delivering a message */
protected boolean inDeliver;
/** Holds the ThreadId of the server Thread used to deliver messages */
protected long deliverThreadId = 0L;
protected boolean enableThreadCheck = false;
/** Indicates whether this DirectSesion is being used for an MDB */
protected boolean isMDBSession = false;
/**
* Holds the xaTransacted state of this DirectSession
*/
private boolean isXATransacted;
/** Holds the transactionId of this DirectSession if it is transcated */
protected long transactionId = 0L;
protected boolean ackOnFetch = false;
/**
* DirectConsumers made by this DirectSession
*/
private Vector<DirectConsumer> consumers = null;
/**
* DirectProducers made by this DirectSession
*/
private Vector<DirectProducer> producers = null;
/**
* DirectBrowsers made by this DirectSession
*/
private Vector<DirectQueueBrowser> browsers = null;
/**
* Unacknowledged messages' SysMessageID objects kept in order for recover
*/
private ArrayList<SysMessageID> unackedMessageIDs = null;
/**
* Unacknowledged messages'consumerId longs kept in order for recover
*/
private ArrayList<Long> unackedConsumerIDs = null;
/**
* Logging
*/
private static final String _className = "com.sun.messaging.jms.ra.DirectSession";
private static final String _lgrNameOutboundConnection = "javax.resourceadapter.mqjmsra.outbound.connection";
private static final String _lgrNameJMSSession = "jakarta.jms.Session.mqjmsra";
protected static final Logger _loggerOC = Logger.getLogger(_lgrNameOutboundConnection);
protected static final Logger _loggerJS = Logger.getLogger(_lgrNameJMSSession);
private static final String _lgrMIDPrefix = "MQJMSRA_DS";
protected static final String _lgrMID_EET = _lgrMIDPrefix + "1001: ";
protected static final String _lgrMID_INF = _lgrMIDPrefix + "1101: ";
protected static final String _lgrMID_WRN = _lgrMIDPrefix + "2001: ";
protected static final String _lgrMID_ERR = _lgrMIDPrefix + "3001: ";
protected static final String _lgrMID_EXC = _lgrMIDPrefix + "4001: ";
/** For optimized logging */
protected static final int _logLevel;
protected static final boolean _logFINE;
static {
// _loggerOC = Logger.getLogger(_lgrNameOutboundConnection);
// _loggerJS = Logger.getLogger(_lgrNameJMSSession);
int tmplevel = java.util.logging.Level.INFO.intValue();
boolean tmplogfine = false;
java.util.logging.Level _level = _loggerJS.getLevel();
if (_level != null) {
tmplevel = _level.intValue();
if (tmplevel <= java.util.logging.Level.FINE.intValue()) {
tmplogfine = true;
}
}
_logLevel = tmplevel;
_logFINE = tmplogfine;
}
/** Creates a new instance of DirectSession */
public DirectSession(DirectConnection dc, JMSService jmsservice, long sessionId, SessionAckMode ackMode) throws JMSException {
Object params[] = new Object[4];
params[0] = dc;
params[1] = jmsservice;
params[2] = sessionId;
params[3] = ackMode;
_loggerOC.entering(_className, "constructor()", params);
this.dc = dc;
this.jmsservice = jmsservice;
this.connectionId = dc.getConnectionId();
this.sessionId = sessionId;
this.ackMode = ackMode;
producers = new Vector<>();
consumers = new Vector<>();
browsers = new Vector<>();
unackedMessageIDs = new ArrayList<>();
unackedConsumerIDs = new ArrayList<>();
_initSession();
}
/////////////////////////////////////////////////////////////////////////
// methods that implement jakarta.jms.Session
/////////////////////////////////////////////////////////////////////////
/**
* Close the JMS Session
*/
@Override
public synchronized void close() throws JMSException {
_loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId + ":" + "close()");
// harmless if already closed
if (isClosed) {
return;
} else {
dc.removeSession(this);
this._close();
}
}
/**
* Commit all messages acknowledged in this JMS Sesssion
*/
@Override
public void commit() throws JMSException {
String methodName = "commit()";
_loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId + ":" + methodName);
// XXX:handle commit inside deliver() includes the current message
this._checkIfClosed(methodName);
this._checkTransactedState(methodName, true); // allow only if transacted
// JMSServiceReply reply = null;
try {
// reply = jmsservice.commitTransaction(
jmsservice.commitTransaction(this.connectionId, this.transactionId, null, 0);
} catch (JMSServiceException jmsse) {
_loggerJS.warning(_lgrMID_WRN + "sessionId=" + sessionId + ":" + methodName + ":JMSServiceException=" + jmsse.getMessage());
}
this._startTransaction(methodName);
}
/**
* Create a QueueBrowser to peek at the messages on the specified queue
*/
@Override
public QueueBrowser createBrowser(Queue queue) throws JMSException {
return this._createAndAddBrowser("createBrowser(Queue)", queue, null);
}
/**
* Create a QueueBrowser to peek at the messages on the specified queue using a message selector
*/
@Override
public QueueBrowser createBrowser(Queue queue, String selector) throws JMSException {
return this._createAndAddBrowser("createBrowser(Queue, Selector)", queue, selector);
}
/**
* Create a BytesMessage
*/
@Override
public BytesMessage createBytesMessage() throws JMSException {
String methodName = "createBytesMessage()";
if (_logFINE) {
_loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId + ":" + methodName);
}
this._checkIfClosed(methodName);
return new DirectBytesPacket(this);
}
/**
* Create a MessageConsumer for the specified Destination
*/
@Override
public MessageConsumer createConsumer(Destination destination) throws JMSException {
return this._createAndAddConsumer("createConsumer(Destination)", destination, null, false);
}
/**
* Create a MessageConsumer for the specified Destination using a selector
*/
@Override
public MessageConsumer createConsumer(Destination destination, String selector) throws JMSException {
return this._createAndAddConsumer("createConsumer(Destination, selector)", destination, selector, false);
}
/**
* Create a MessageConsumer for the specified Destination using a selector and specifying whether messages published by
* its own connection should be delivered to it.
*/
@Override
public MessageConsumer createConsumer(Destination destination, String selector, boolean noLocal) throws JMSException {
return this._createAndAddConsumer("createConsumer(Destination, selector, noLocal)", destination, selector, noLocal);
}
/**
* Create a TopicSubscriber for the specified Topic with the specified subscription name
*/
@Override
public TopicSubscriber createDurableSubscriber(Topic topic, String name) throws JMSException {
return this._createAndAddConsumer("createDurableSubscriber(Topic, name)", topic, null, name, true, false, false, false);
}
/**
* Create a TopicSubscriber for the specified Topic with the specified subscription name and selector and specifying
* whether messages published by its own connection should be delivered to it.
*/
@Override
public TopicSubscriber createDurableSubscriber(Topic topic, String name, String selector, boolean noLocal) throws JMSException {
return this._createAndAddConsumer("createDurableSubscriber(Topic, name, selector, noLocal)", topic, selector, name, true, false,
false, noLocal);
}
/**
* Create a TopicSubscriber for the specified Topic with the specified subscription name
*/
@Override
public MessageConsumer createDurableConsumer(Topic topic, String name) throws JMSException {
return createDurableSubscriber(topic, name);
}
/**
* Create a TopicSubscriber for the specified Topic with the specified subscription name and selector and specifying
* whether messages published by its own connection should be delivered to it.
*/
@Override
public MessageConsumer createDurableConsumer(Topic topic, String name, String messageSelector, boolean noLocal) throws JMSException {
return createDurableSubscriber(topic, name, messageSelector, noLocal);
}
@Override
public MessageConsumer createSharedConsumer(Topic topic, String sharedSubscriptionName) throws JMSException {
return createSharedConsumer(topic, sharedSubscriptionName, null);
}
@Override
public MessageConsumer createSharedConsumer(Topic topic, String sharedSubscriptionName, String messageSelector) throws JMSException {
boolean noLocal = false;
return this._createAndAddConsumer("createSharedConsumer(Topic, sharedSubscriptionName, messageSelector)", topic, messageSelector,
sharedSubscriptionName, false, true, true, noLocal);
}
@Override
public MessageConsumer createSharedDurableConsumer(Topic topic, String name) throws JMSException {
return createSharedDurableConsumer(topic, name, null);
}
@Override
public MessageConsumer createSharedDurableConsumer(Topic topic, String name, String messageSelector) throws JMSException {
boolean noLocal = false;
return this._createAndAddConsumer("createSharedDurableConsumer(Topic, name, messageSelector)", topic, messageSelector, name, true,
true, true, noLocal);
}
/**
* Create a MapMessage
*/
@Override
public MapMessage createMapMessage() throws JMSException {
String methodName = "createMapMessage()";
if (_logFINE) {
_loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId + ":" + methodName);
}
this._checkIfClosed(methodName);
return new DirectMapPacket(this);
}
/**
* Create a Message
*/
@Override
public Message createMessage() throws JMSException {
String methodName = "createMessage()";
if (_logFINE) {
_loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId + ":" + methodName);
}
this._checkIfClosed(methodName);
return new DirectPacket(this);
}
/**
* Create a ObjectMessage
*/
@Override
public ObjectMessage createObjectMessage() throws JMSException {
String methodName = "createObjectMessage()";
if (_logFINE) {
_loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId + ":" + methodName);
}
this._checkIfClosed(methodName);
return new DirectObjectPacket(this, null);
}
/**
* Create a ObjectMessage
*/
@Override
public ObjectMessage createObjectMessage(Serializable object) throws JMSException {
String methodName = "createObjectMessage(object)";
if (_logFINE) {
_loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId + ":" + methodName);
}
this._checkIfClosed(methodName);
return new DirectObjectPacket(this, object);
}
/**
* Create a MessageProducer for the specified Destination
*/
@Override
public MessageProducer createProducer(Destination destination) throws JMSException {
return this._createAndAddProducer("createProducer()", destination);
/*
* String methodName = "createProducer()"; if (_logFINE){ _loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId +
* ":"+methodName+"destination="+destination); } this._checkIfClosed(methodName); if (destination !=null) { //Spcified
* destination case String _name = null; com.sun.messaging.jmq.jmsservice.Destination.Type _type =
* com.sun.messaging.jmq.jmsservice.Destination.Type.QUEUE; com.sun.messaging.jmq.jmsservice.Destination.Life _life =
* com.sun.messaging.jmq.jmsservice.Destination.Life.STANDARD;
*
* if (destination instanceof jakarta.jms.Queue){ _name = ((Queue)destination).getQueueName(); _type =
* com.sun.messaging.jmq.jmsservice.Destination.Type.QUEUE; if (destination instanceof jakarta.jms.TemporaryQueue){ _life
* = com.sun.messaging.jmq.jmsservice.Destination.Life.TEMPORARY; } } if (destination instanceof jakarta.jms.Topic){ _name
* = ((Topic)destination).getTopicName(); _type = com.sun.messaging.jmq.jmsservice.Destination.Type.TOPIC; if
* (destination instanceof jakarta.jms.TemporaryTopic){ _life =
* com.sun.messaging.jmq.jmsservice.Destination.Life.TEMPORARY; } } com.sun.messaging.jmq.jmsservice.Destination
* _destination = new com.sun.messaging.jmq.jmsservice.Destination(_name, _type, _life); //XXX:tharakan:Need to Verify
* Destination first. //dc._verifyDestination(_destination); dc._createDestination(_destination); long producerId =
* _createProducerId(_destination); DirectProducer dp = new DirectProducer(this, jmsservice, producerId, destination,
* _destination); this.addProducer(dp); return (MessageProducer)dp; } else { DirectProducer dp = new
* DirectProducer(this, jmsservice); this.addProducer(dp); return (MessageProducer)dp; }
*/
}
/**
* Create a Queue identity object with the specified queue name
*
* @param queueName The name of the Queue Destination
*
* @throws InvalidDestinationException If the queueName contains illegal syntax.
*/
@Override
public Queue createQueue(String queueName) throws JMSException {
String methodName = "createQueue(queueName)";
_loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId + ":" + methodName + "=" + queueName);
this._checkIfClosed(methodName);
return new com.sun.messaging.BasicQueue(queueName);
}
/**
* Create a StreamMessage
*/
@Override
public StreamMessage createStreamMessage() throws JMSException {
String methodName = "createStreamMessage()";
if (_logFINE) {
_loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId + ":" + methodName);
}
this._checkIfClosed(methodName);
return new DirectStreamPacket(this);
}
/**
* Create a TemporaryQueue identity object
*/
@Override
public jakarta.jms.TemporaryQueue createTemporaryQueue() throws JMSException {
String methodName = "createTemporaryQueue()";
if (_logFINE) {
_loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId + ":" + methodName);
}
this._checkIfClosed(methodName);
TemporaryQueue tq = new TemporaryQueue(this.dc);
this.dc._createDestination(tq._getDestination());
this.dc.addTemporaryDestination(tq);
return tq;
}
/**
* Create a TemporaryTopic identity object
*/
@Override
public jakarta.jms.TemporaryTopic createTemporaryTopic() throws JMSException {
String methodName = "createTemporaryTopic()";
if (_logFINE) {
_loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId + ":" + methodName);
}
this._checkIfClosed(methodName);
TemporaryTopic tt = new TemporaryTopic(this.dc);
this.dc._createDestination(tt._getDestination());
this.dc.addTemporaryDestination(tt);
return tt;
}
/**
* Create a TextMessage
*/
@Override
public TextMessage createTextMessage() throws JMSException {
String methodName = "createTextMessage()";
if (_logFINE) {
_loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId + ":" + methodName);
}
this._checkIfClosed(methodName);
return new DirectTextPacket(this, null);
}
/**
* Create a TextMessage initialized with the specified String
*/
@Override
public TextMessage createTextMessage(String text) throws JMSException {
String methodName = "createTextMessage(text)";
if (_logFINE) {
_loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId + ":" + methodName);
}
this._checkIfClosed(methodName);
return new DirectTextPacket(this, text);
}
/**
* Create a Topic identity object with the specified topic name
*
* @param topicName The name of the Topic Destination
*
* @throws InvalidDestinationException If the topicName contains illegal syntax.
*/
@Override
public Topic createTopic(String topicName) throws JMSException {
String methodName = "createTopic(topicName)";
if (_logFINE) {
_loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId + ":" + methodName + "=" + topicName);
}
this._checkIfClosed(methodName);
return new com.sun.messaging.BasicTopic(topicName);
}
/**
* Return the acknowledgement mode of the Session
*/
@Override
public int getAcknowledgeMode() throws JMSException {
String methodName = "getAcknowledgeMode()";
if (_logFINE) {
_loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId + ":" + methodName);
}
this._checkIfClosed(methodName);
switch (this.ackMode) {
case AUTO_ACKNOWLEDGE:
return Session.AUTO_ACKNOWLEDGE;
case CLIENT_ACKNOWLEDGE:
return Session.CLIENT_ACKNOWLEDGE;
case DUPS_OK_ACKNOWLEDGE:
return Session.DUPS_OK_ACKNOWLEDGE;
case TRANSACTED:
return Session.SESSION_TRANSACTED;
case NO_ACKNOWLEDGE:
return com.sun.messaging.jms.Session.NO_ACKNOWLEDGE;
default:
throw new JMSException(methodName + ":Unknown aknowledge mode");
}
}
/**
* Return the Session's distinguished MessageListener
*/
@Override
public MessageListener getMessageListener() throws JMSException {
String methodName = "getMessageListener()";
if (_logFINE) {
_loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId + ":" + methodName);
}
this._checkIfClosed(methodName);
return null;
}
/**
* Return whether the Session is transacted or not
*/
@Override
public boolean getTransacted() throws JMSException {
String methodName = "getTransacted()";
if (_logFINE) {
_loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId + ":" + methodName);
}
this._checkIfClosed(methodName);
return getTransactedNoCheck();
}
protected boolean getTransactedNoCheck() {
return (this.ackMode == SessionAckMode.TRANSACTED);
}
/**
* Restart this Session's message delivery starting with the oldest unacknowledged message
*/
@Override
public void recover() throws JMSException {
String methodName = "recover()";
// JMSServiceReply reply;
// JMSServiceReply.Status status;
if (_logFINE) {
_loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId + ":" + methodName);
}
this._checkIfClosed(methodName);
this._checkTransactedState(methodName, false); // DONOT allowIfTransacted
// Session.recover() is a NOP for an MDB Session
// and
// all for all Session Acknowledge modes except CLIENT_ACKNOWLEDGE
if ((this._isMDBSession()) || (this.ackMode != SessionAckMode.CLIENT_ACKNOWLEDGE)) {
return;
}
// XXX:tharakan
// Stop the sesssion before recover
// this._stop();
try {
// reply = jmsservice.redeliverMessages(this.connectionId, this.sessionId,
jmsservice.redeliverMessages(this.connectionId, this.sessionId, unackedMessageIDs.toArray(new SysMessageID[0]),
unackedConsumerIDs.toArray(new Long[0]), this.transactionId, true);
} catch (JMSServiceException jmsse) {
// status = jmsse.getJMSServiceReply().getStatus();
jmsse.getJMSServiceReply().getStatus();
String failure_cause = "unknown JMSService error";
/*
* switch (status) { case NOT_FOUND: failure_cause = "message not found and cannot be acknowledged"; break; default:
* failure_cause = "unkown JMSService server error."; }
*/
String exerrmsg = "redeliverMessage on JMSService:" + jmsservice.getJMSServiceID() + " failed for connectionId:" + this.connectionId
+ " and sessionId:" + this.sessionId + " due to " + failure_cause;
_loggerJS.severe(exerrmsg);
JMSException jmse = new JMSException(exerrmsg);
jmse.initCause(jmsse);
throw jmse;
} finally {
this.unackedMessageIDs.clear();
this.unackedConsumerIDs.clear();
// XXX:tharakan
// Start the session
// this._start();
}
}
/**
* Rollback all messages acknowledged in this transacted session unacknowledged message
*/
@Override
public void rollback() throws JMSException {
String methodName = "rollback()";
if (_logFINE) {
_loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId + ":" + methodName);
}
this._checkIfClosed(methodName);
this._checkTransactedState(methodName, true); // allow only if transacted
// XXX:handle rollback inside deliver() includes the current message
this._rollback(methodName);
this._startTransaction(methodName);
}
/**
* Run message delivery of the messages that have been loaded in this sesssion.
*/
@Override
public void run() {
String methodName = "run()";
if (_logFINE) {
_loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId + ":" + methodName);
}
try {
this._checkIfClosed(methodName);
this._checkTransactedState(methodName, false); // allow only if non-tx
this._unsupported("Session.recover()");
} catch (JMSException ex) {
_loggerJS.severe(this._lgrMID_EXC + "sessionId=" + sessionId + ":" + methodName + ex.getMessage());
throw new RuntimeException(ex);
}
}
/**
* Set the Session's distinguished MessageListener
*/
@Override
public void setMessageListener(jakarta.jms.MessageListener listener) throws JMSException {
String methodName = "setMessageListener()";
if (_logFINE) {
_loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId + ":" + methodName);
}
this._unsupported("Session.setMessageListener()");
this._checkIfClosed(methodName);
}
/**
* Unsubscribe the durable subscription specified by name
*/
@Override
public void unsubscribe(String name) throws JMSException {
String methodName = "unsubscribe()";
if (_logFINE) {
_loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId + ":" + methodName);
}
this._checkIfClosed(methodName);
if (name == null || "".equals(name)) {
throw new InvalidDestinationException("NULL or empty name for unsubscribe");
}
// cycle through consumers and check if one of them is lose them one by one
DirectConsumer dc = null;
Iterator<DirectConsumer> k = this.dc._getDurableConsumers().iterator();
while (k.hasNext()) {
dc = k.next();
if (name.equals(dc.getDurableName())) {
String exErrMsg = _lgrMID_WRN + "sessionId=" + sessionId + ":" + methodName + ":name:" + name + ":Is in use";
_loggerJS.warning(exErrMsg);
JMSException jmse = new JMSException(exErrMsg);
throw jmse;
}
}
try {
// this method returns a JMSServiceReply but we don't need to check it since
// an exception will be thrown if it is not OK
jmsservice.deleteConsumer(this.connectionId, this.sessionId, 0L, null, false, name, this.dc._getClientID());
} catch (JMSServiceException jmsse) {
String exErrMsg = _lgrMID_EXC + "sessionId=" + sessionId + ":" + methodName + ":name:" + name + ":error=" + jmsse.getMessage();
_loggerJS.warning(exErrMsg);
JMSException jmse = new InvalidDestinationException(exErrMsg);
jmse.initCause(jmsse);
throw jmse;
}
}
/////////////////////////////////////////////////////////////////////////
// end jakarta.jms.Session
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
// methods that implement jakarta.jms.QueueSession
/////////////////////////////////////////////////////////////////////////
/**
* Create a QueueReceiver for the specified Queue
*/
@Override
public QueueReceiver createReceiver(Queue queue) throws JMSException {
return this._createAndAddConsumer("createReceiver(Queue)", queue, null, false);
}
/**
* Create a QueueReceiver for the specified Queue with the specified selector
*/
@Override
public QueueReceiver createReceiver(Queue queue, String selector) throws JMSException {
return this._createAndAddConsumer("createReceiver(Queue, selector)", queue, selector, false);
}
/**
* Create a QueueSender for the specified Queue
*
* @param queue The Queue to be used when creating the QueueSender
*/
@Override
public QueueSender createSender(Queue queue) throws JMSException {
return this._createAndAddProducer("createSender(Queue)", queue);
/*
* String methodName = "createSender(Queue)"; String _name = null; if (queue != null){ _name = queue.getQueueName(); }
* if (_logFINE){ _loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId+":"+ methodName + ":Queue="+_name); }
* this._checkIfClosed(methodName); com.sun.messaging.jmq.jmsservice.Destination.Life _life =
* com.sun.messaging.jmq.jmsservice.Destination.Life.STANDARD; if (queue !=null) { //Spcified destination case if (queue
* instanceof jakarta.jms.TemporaryQueue){ _life = com.sun.messaging.jmq.jmsservice.Destination.Life.TEMPORARY; }
* com.sun.messaging.jmq.jmsservice.Destination _destination = new com.sun.messaging.jmq.jmsservice.Destination(_name,
* com.sun.messaging.jmq.jmsservice.Destination.Type.QUEUE, _life); dc._createDestination(_destination); long producerId
* = _createProducerId(_destination); DirectProducer dp = new DirectProducer(this, this.jmsservice, producerId, queue,
* _destination); this.addProducer(dp); return (QueueSender)dp; } else { DirectProducer dp = new DirectProducer(this,
* this.jmsservice); this.addProducer(dp); return (QueueSender)dp; }
*/
}
/////////////////////////////////////////////////////////////////////////
// end jakarta.jms.QueueSession
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
// methods that implement jakarta.jms.TopicSession
/////////////////////////////////////////////////////////////////////////
/**
* Create a TopicPublisher for the specified Topic
*
* @param topic The Topic to be used when creating the TopicPublisher
*/
@Override
public TopicPublisher createPublisher(Topic topic) throws JMSException {
return this._createAndAddProducer("createPublisher()", topic);
/*
* String methodName = "createPublisher(Topic)"; String _name = null; if (topic != null) { _name = topic.getTopicName();
* } com.sun.messaging.jmq.jmsservice.Destination.Life _life =
* com.sun.messaging.jmq.jmsservice.Destination.Life.STANDARD; if (_logFINE){ _loggerJS.fine(_lgrMID_INF + "sessionId="
* + sessionId+":"+ methodName + "=" + _name); } this._checkIfClosed(methodName); if (topic !=null) { //Spcified
* destination case if (topic instanceof jakarta.jms.TemporaryTopic){ _life =
* com.sun.messaging.jmq.jmsservice.Destination.Life.TEMPORARY; } com.sun.messaging.jmq.jmsservice.Destination
* _destination = new com.sun.messaging.jmq.jmsservice.Destination(_name,
* com.sun.messaging.jmq.jmsservice.Destination.Type.TOPIC, _life); //XXX:tharakan:Need to Verify Destination first ???
* //dc._verifyDestination(_destination); dc._createDestination(_destination); long producerId =
* _createProducerId(_destination); DirectProducer dp = new DirectProducer(this, this.jmsservice, producerId, topic,
* _destination); this.addProducer(dp); return (TopicPublisher)dp; } else { DirectProducer dp = new DirectProducer(this,
* this.jmsservice); this.addProducer(dp); return (TopicPublisher)dp; }
*/
}
/**
* Create a TopicSubscriber for the specified Topic.
*/
@Override
public TopicSubscriber createSubscriber(Topic topic) throws JMSException {
return this._createAndAddConsumer("createSubscriber(Topic)", topic, null, false);
}
/**
* Create a TopicSubscriber for the specified Topic using a selector and specifying whether messages published by its
* own connection should be delivered to it.
*/
@Override
public TopicSubscriber createSubscriber(Topic topic, String selector, boolean noLocal) throws JMSException {
return this._createAndAddConsumer("createSubscriber(Topic, selector, noLocal)", topic, selector, noLocal);
}
/////////////////////////////////////////////////////////////////////////
// methods that implement jakarta.jms.TopicSession
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
// MQ methods
/////////////////////////////////////////////////////////////////////////
/**
* Initialize this DirectSession - this is overridden by sub classes
*/
protected void _initSession() throws JMSException {
String methodName = "_initSession()";
_loggerOC.entering(_className, methodName);
this.isAsync = false;
this.inDeliver = false;
this.isClosed = false;
this.isClosing = false;
this.isStopped = true;
this.ackOnFetch = ((this.ackMode == JMSService.SessionAckMode.AUTO_ACKNOWLEDGE) || (this.ackMode == JMSService.SessionAckMode.TRANSACTED)
|| (this.ackMode == JMSService.SessionAckMode.DUPS_OK_ACKNOWLEDGE));
if (this.isTransacted() && !this.dc.isManaged()) {
this._startTransaction(methodName);
}
if (!this.dc.isStopped()) {
this._start();
}
}
/**
* Start the JMS Session
*/
protected void _start() {
this.isStopped = false;
try {
jmsservice.startSession(this.connectionId, this.sessionId);
} catch (JMSServiceException jmsse) {
_loggerJS.warning(
_lgrMID_WRN + "sessionId=" + sessionId + ":" + "_start():" + "JMSService.startSession():" + "JMSServiceException=" + jmsse.getMessage());
}
}
/**
* Start a transaction for this transacted session
*/
protected void _startTransaction(String fromMethod) throws JMSException {
JMSServiceReply reply = null;
try {
reply = jmsservice.startTransaction(this.connectionId, this.sessionId, null, 0, JMSService.TransactionAutoRollback.UNSPECIFIED, 0L);
try {
this.transactionId = reply.getJMQTransactionID();
} catch (NoSuchFieldException nsfe) {
String exerrmsg = _lgrMID_EXC + "sessionId=" + this.sessionId + ":_startTransaction from " + fromMethod
+ ":JMSServiceException:Missing JMQTransactionID";
JMSException jmse = new JMSException(exerrmsg);
jmse.initCause(nsfe);
_loggerJS.severe(exerrmsg);
throw jmse;
}
} catch (JMSServiceException jmsse) {
_loggerJS.severe(
_lgrMID_EXC + "sessionId=" + this.sessionId + ":_startTransaction from " + fromMethod + "JMSServiceException=" + jmsse.getMessage());
}
}
/**
* Rollback the transaction for this session
*/
protected void _rollback(String methodName) throws JMSException {
// JMSServiceReply reply = null;
try {
// XXX:Set the Redelivered Flag until CTS changes the test
// reply = jmsservice.rollbackTransaction(this.connectionId,
jmsservice.rollbackTransaction(this.connectionId, this.transactionId, null, true, true);
// XXX:Set the Redelivered Flag until CTS changes the test
} catch (JMSServiceException jmsse) {
_loggerJS.warning(_lgrMID_WRN + "sessionId=" + sessionId + ":" + methodName + ":JMSServiceException=" + jmsse.getMessage());
}
}
/**
* Stop the JMS Session
*/
protected void _stop() {
try {
jmsservice.stopSession(this.connectionId, this.sessionId, true);
} catch (JMSServiceException jmsse) {
_loggerJS.warning(
_lgrMID_WRN + "sessionId=" + sessionId + ":" + "_stop():" + "JMSService.stopSession():" + "JMSServiceException=" + jmsse.getMessage());
}
}
/**
* Return the DirectConnection for this DirectSession
*/
public final DirectConnection getConnection() {
return this.dc;
}
/**
* Return the connectionId for this DirectSession
*
* @return The connectionId
*/
public final long getConnectionId() {
return this.connectionId;
}
/**
* Return the sessionId for this DirectSession
*
* @return The sessionId
*/
public final long getSessionId() {
return this.sessionId;
}
protected long _getTransactionId() {
return this.transactionId;
}
/**
* Return the closed state of this DirectSession
*
* @return {@code true} if this session has been closed; {@code false} otherwise
*/
public synchronized boolean isClosed() {
return this.isClosed;
}
/**
* Return the Async state of this DirectSession
*
* @return {@code true} if this session is dedicated to async consumption {@code false} otherwise
*/
public synchronized boolean isAsync() {
return this.isAsync;
}
/**
* Set the Async state of this DirectSession
*
*
* @param isAsync The value to set the async state of this DirectSession
*/
protected synchronized void _setAsync(boolean isAsync) {
this.isAsync = isAsync;
// If the dc has started,then start this session
// else when the dc starts start this session
// only if this is asynch?
}
protected final synchronized boolean inDeliver() {
return this.inDeliver;
}
/**
* Return the XATransacted state of this DirectSession
*
* @return {@code true} if this session is involved in an XA Transaction {@code false} if it is not involved in an XA
* Transaction
*/
public synchronized boolean isXATransacted() {
return this.isXATransacted;
}
/**
* Return the Transacted state of this DirectSession
*
* @return {@code true} if this session is involved in a JMS Transaction {@code false} if it is not involved in a JMS
* Transaction
*/
public boolean isTransacted() {
return (this.ackMode == SessionAckMode.TRANSACTED);