/
ClientSessionImpl.java
2211 lines (1826 loc) · 77.2 KB
/
ClientSessionImpl.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
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.artemis.core.client.impl;
import javax.transaction.xa.XAException;
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration;
import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
import org.apache.activemq.artemis.api.core.ActiveMQBuffers;
import org.apache.activemq.artemis.api.core.ActiveMQException;
import org.apache.activemq.artemis.api.core.ActiveMQExceptionType;
import org.apache.activemq.artemis.api.core.Message;
import org.apache.activemq.artemis.api.core.QueueAttributes;
import org.apache.activemq.artemis.api.core.QueueConfiguration;
import org.apache.activemq.artemis.api.core.RoutingType;
import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.api.core.client.ClientConsumer;
import org.apache.activemq.artemis.api.core.client.ClientMessage;
import org.apache.activemq.artemis.api.core.client.ClientProducer;
import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
import org.apache.activemq.artemis.api.core.client.FailoverEventListener;
import org.apache.activemq.artemis.api.core.client.SendAcknowledgementHandler;
import org.apache.activemq.artemis.api.core.client.SessionFailureListener;
import org.apache.activemq.artemis.core.client.ActiveMQClientLogger;
import org.apache.activemq.artemis.core.client.ActiveMQClientMessageBundle;
import org.apache.activemq.artemis.core.persistence.CoreMessageObjectPools;
import org.apache.activemq.artemis.core.remoting.FailureListener;
import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
import org.apache.activemq.artemis.spi.core.remoting.ConsumerContext;
import org.apache.activemq.artemis.spi.core.remoting.ReadyListener;
import org.apache.activemq.artemis.spi.core.remoting.SessionContext;
import org.apache.activemq.artemis.utils.ConfirmationWindowWarning;
import org.apache.activemq.artemis.utils.TokenBucketLimiterImpl;
import org.apache.activemq.artemis.utils.UUIDGenerator;
import org.apache.activemq.artemis.utils.XidCodecSupport;
import org.jboss.logging.Logger;
public final class ClientSessionImpl implements ClientSessionInternal, FailureListener {
private static final Logger logger = Logger.getLogger(ClientSessionImpl.class);
private final Map<String, String> metadata = new HashMap<>();
private final ClientSessionFactoryInternal sessionFactory;
private String name;
private final String username;
private final String password;
private final boolean xa;
private final Executor executor;
// to be sent to consumers as consumers will need a separate consumer for flow control
private final Executor flowControlExecutor;
/**
* All access to producers are guarded (i.e. synchronized) on itself.
*/
private final Set<ClientProducerInternal> producers = new HashSet<>();
// Consumers must be an ordered map so if we fail we recreate them in the same order with the same ids
private final Map<ConsumerContext, ClientConsumerInternal> consumers = new LinkedHashMap<>();
private volatile boolean closed;
private final boolean autoCommitAcks;
private final boolean preAcknowledge;
private final boolean autoCommitSends;
private final boolean blockOnAcknowledge;
private final boolean autoGroup;
private final int ackBatchSize;
private final int consumerWindowSize;
private final int consumerMaxRate;
private final int confirmationWindowSize;
private final int producerMaxRate;
private final boolean blockOnNonDurableSend;
private final boolean blockOnDurableSend;
private final int minLargeMessageSize;
private final boolean compressLargeMessages;
private volatile int initialMessagePacketSize;
private final boolean cacheLargeMessageClient;
private final SessionContext sessionContext;
// For testing only
private boolean forceNotSameRM;
private final ClientProducerCreditManager producerCreditManager;
private volatile boolean started;
private volatile boolean rollbackOnly;
private volatile boolean workDone;
private final String groupID;
private volatile boolean inClose;
private volatile boolean mayAttemptToFailover = true;
/**
* Current XID. this will be used in case of failover
*/
private Xid currentXID;
private final AtomicInteger concurrentCall = new AtomicInteger(0);
private final ConfirmationWindowWarning confirmationWindowWarning;
private final Executor closeExecutor;
private final CoreMessageObjectPools coreMessageObjectPools = new CoreMessageObjectPools();
ClientSessionImpl(final ClientSessionFactoryInternal sessionFactory,
final String name,
final String username,
final String password,
final boolean xa,
final boolean autoCommitSends,
final boolean autoCommitAcks,
final boolean preAcknowledge,
final boolean blockOnAcknowledge,
final boolean autoGroup,
final int ackBatchSize,
final int consumerWindowSize,
final int consumerMaxRate,
final int confirmationWindowSize,
final int producerWindowSize,
final int producerMaxRate,
final boolean blockOnNonDurableSend,
final boolean blockOnDurableSend,
final boolean cacheLargeMessageClient,
final int minLargeMessageSize,
final boolean compressLargeMessages,
final int initialMessagePacketSize,
final String groupID,
final SessionContext sessionContext,
final Executor executor,
final Executor flowControlExecutor,
final Executor closeExecutor) throws ActiveMQException {
this.sessionFactory = sessionFactory;
this.name = name;
this.username = username;
this.password = password;
this.executor = executor;
this.flowControlExecutor = flowControlExecutor;
this.xa = xa;
this.autoCommitAcks = autoCommitAcks;
this.preAcknowledge = preAcknowledge;
this.autoCommitSends = autoCommitSends;
this.blockOnAcknowledge = blockOnAcknowledge;
this.autoGroup = autoGroup;
this.ackBatchSize = ackBatchSize;
this.consumerWindowSize = consumerWindowSize;
this.consumerMaxRate = consumerMaxRate;
this.confirmationWindowSize = confirmationWindowSize;
this.producerMaxRate = producerMaxRate;
this.blockOnNonDurableSend = blockOnNonDurableSend;
this.blockOnDurableSend = blockOnDurableSend;
this.cacheLargeMessageClient = cacheLargeMessageClient;
this.minLargeMessageSize = minLargeMessageSize;
this.compressLargeMessages = compressLargeMessages;
this.initialMessagePacketSize = initialMessagePacketSize;
this.groupID = groupID;
producerCreditManager = new ClientProducerCreditManagerImpl(this, producerWindowSize);
this.sessionContext = sessionContext;
sessionContext.setSession(this);
confirmationWindowWarning = sessionFactory.getConfirmationWindowWarning();
this.closeExecutor = closeExecutor;
}
// ClientSession implementation
// -----------------------------------------------------------------
@Override
public void createQueue(final SimpleString address, final SimpleString queueName) throws ActiveMQException {
createQueue(address, queueName, false);
}
@Override
public void createQueue(final SimpleString address,
final SimpleString queueName,
final boolean durable) throws ActiveMQException {
createQueue(address, queueName, null, durable, false);
}
@Override
public void createQueue(final String address,
final String queueName,
final boolean durable) throws ActiveMQException {
createQueue(SimpleString.toSimpleString(address), SimpleString.toSimpleString(queueName), durable);
}
@Override
public void createSharedQueue(SimpleString address,
SimpleString queueName,
boolean durable) throws ActiveMQException {
createSharedQueue(address, queueName, null, durable);
}
@Override
public void createSharedQueue(SimpleString address,
SimpleString queueName,
SimpleString filterString,
boolean durable) throws ActiveMQException {
createSharedQueue(address, ActiveMQDefaultConfiguration.getDefaultRoutingType(), queueName, filterString, durable);
}
@Override
public void createAddress(final SimpleString address, Set<RoutingType> routingTypes, boolean autoCreated) throws ActiveMQException {
createAddress(address, EnumSet.copyOf(routingTypes), autoCreated);
}
@Override
public void createAddress(final SimpleString address, EnumSet<RoutingType> routingTypes, boolean autoCreated) throws ActiveMQException {
checkClosed();
startCall();
try {
sessionContext.createAddress(address, routingTypes, autoCreated);
} finally {
endCall();
}
}
@Override
public void createAddress(final SimpleString address, RoutingType routingType, boolean autoCreated) throws ActiveMQException {
createAddress(address, EnumSet.of(routingType), autoCreated);
}
@Override
public void createQueue(QueueConfiguration queueConfiguration) throws ActiveMQException {
internalCreateQueue(queueConfiguration);
}
@Override
public void createSharedQueue(QueueConfiguration queueConfiguration) throws ActiveMQException {
checkClosed();
startCall();
try {
sessionContext.createSharedQueue(queueConfiguration);
} finally {
endCall();
}
}
@Override
public void createQueue(final SimpleString address,
final SimpleString queueName,
final SimpleString filterString,
final boolean durable) throws ActiveMQException {
createQueue(address, queueName, filterString, durable, false);
}
@Override
public void createQueue(final String address,
final String queueName,
final String filterString,
final boolean durable) throws ActiveMQException {
createQueue(SimpleString.toSimpleString(address),
SimpleString.toSimpleString(queueName),
SimpleString.toSimpleString(filterString),
durable);
}
@Override
public void createQueue(final SimpleString address,
final SimpleString queueName,
final SimpleString filterString,
final boolean durable,
final boolean autoCreated) throws ActiveMQException {
createQueue(address, ActiveMQDefaultConfiguration.getDefaultRoutingType(), queueName, filterString, durable, autoCreated);
}
@Override
public void createQueue(final String address,
final String queueName,
final String filterString,
final boolean durable,
final boolean autoCreated) throws ActiveMQException {
createQueue(SimpleString.toSimpleString(address), SimpleString.toSimpleString(queueName), SimpleString.toSimpleString(filterString), durable, autoCreated);
}
@Override
public void createTemporaryQueue(final SimpleString address, final SimpleString queueName) throws ActiveMQException {
createTemporaryQueue(address, queueName, (SimpleString) null);
}
@Override
public void createTemporaryQueue(final String address, final String queueName) throws ActiveMQException {
createTemporaryQueue(SimpleString.toSimpleString(address), SimpleString.toSimpleString(queueName));
}
@Override
public void createTemporaryQueue(final SimpleString address,
final SimpleString queueName,
final SimpleString filter) throws ActiveMQException {
createTemporaryQueue(address, ActiveMQDefaultConfiguration.getDefaultRoutingType(), queueName, filter);
}
@Override
public void createTemporaryQueue(final String address,
final String queueName,
final String filter) throws ActiveMQException {
createTemporaryQueue(SimpleString.toSimpleString(address), SimpleString.toSimpleString(queueName), SimpleString.toSimpleString(filter));
}
/** New Queue API **/
@Deprecated
@Override
public void createQueue(final SimpleString address,
final RoutingType routingType,
final SimpleString queueName,
final SimpleString filterString,
final boolean durable,
final boolean autoCreated) throws ActiveMQException {
internalCreateQueue(address,
queueName,
false,
autoCreated,
new QueueAttributes()
.setRoutingType(routingType)
.setFilterString(filterString)
.setDurable(durable)
.setPurgeOnNoConsumers(ActiveMQDefaultConfiguration.getDefaultPurgeOnNoConsumers())
.setMaxConsumers(ActiveMQDefaultConfiguration.getDefaultMaxQueueConsumers()));
}
@Override
public void createQueue(final String address, final RoutingType routingType, final String queueName, final String filterString,
final boolean durable, final boolean autoCreated) throws ActiveMQException {
createQueue(SimpleString.toSimpleString(address),
routingType,
SimpleString.toSimpleString(queueName),
SimpleString.toSimpleString(filterString),
durable,
autoCreated);
}
@Deprecated
@Override
public void createQueue(final SimpleString address, final RoutingType routingType, final SimpleString queueName, final SimpleString filterString,
final boolean durable, final boolean autoCreated, final int maxConsumers, final boolean purgeOnNoConsumers) throws ActiveMQException {
internalCreateQueue(address,
queueName,
false,
autoCreated,
new QueueAttributes()
.setRoutingType(routingType)
.setFilterString(filterString)
.setDurable(durable)
.setMaxConsumers(maxConsumers)
.setPurgeOnNoConsumers(purgeOnNoConsumers));
}
@Deprecated
@Override
public void createQueue(final SimpleString address, final RoutingType routingType, final SimpleString queueName, final SimpleString filterString,
final boolean durable, final boolean autoCreated, final int maxConsumers, final boolean purgeOnNoConsumers, final Boolean exclusive, final Boolean lastValue) throws ActiveMQException {
internalCreateQueue(address,
queueName,
false,
autoCreated,
new QueueAttributes()
.setRoutingType(routingType)
.setFilterString(filterString)
.setDurable(durable)
.setMaxConsumers(maxConsumers)
.setPurgeOnNoConsumers(purgeOnNoConsumers)
.setExclusive(exclusive)
.setLastValue(lastValue));
}
@Deprecated
@Override
public void createQueue(final SimpleString address, final SimpleString queueName, final boolean autoCreated, final QueueAttributes queueAttributes) throws ActiveMQException {
internalCreateQueue(address,
queueName,
false,
autoCreated,
queueAttributes);
}
@Deprecated
@Override
public void createQueue(final String address, final RoutingType routingType, final String queueName, final String filterString,
final boolean durable, final boolean autoCreated, final int maxConsumers, final boolean purgeOnNoConsumers) throws ActiveMQException {
createQueue(address,
routingType,
queueName,
filterString,
durable,
autoCreated,
maxConsumers,
purgeOnNoConsumers,
null,
null);
}
@Override
public void createQueue(final String address, final RoutingType routingType, final String queueName, final String filterString,
final boolean durable, final boolean autoCreated, final int maxConsumers, final boolean purgeOnNoConsumers, Boolean exclusive, Boolean lastValue) throws ActiveMQException {
createQueue(SimpleString.toSimpleString(address),
routingType,
SimpleString.toSimpleString(queueName),
SimpleString.toSimpleString(filterString),
durable,
autoCreated,
maxConsumers,
purgeOnNoConsumers,
exclusive,
lastValue);
}
@Override
public void createTemporaryQueue(final SimpleString address,
final RoutingType routingType,
final SimpleString queueName) throws ActiveMQException {
createTemporaryQueue(address, routingType, queueName, null);
}
@Override
public void createTemporaryQueue(final String address, final RoutingType routingType, final String queueName) throws ActiveMQException {
createTemporaryQueue(SimpleString.toSimpleString(address), routingType, SimpleString.toSimpleString(queueName));
}
@Deprecated
@Override
public void createTemporaryQueue(final SimpleString address,
final RoutingType routingType,
final SimpleString queueName,
final SimpleString filter,
final int maxConsumers,
final boolean purgeOnNoConsumers,
final Boolean exclusive,
final Boolean lastValue) throws ActiveMQException {
internalCreateQueue(address,
queueName,
true,
false,
new QueueAttributes()
.setRoutingType(routingType)
.setFilterString(filter)
.setDurable(false)
.setPurgeOnNoConsumers(purgeOnNoConsumers)
.setMaxConsumers(maxConsumers)
.setExclusive(exclusive)
.setLastValue(lastValue));
}
@Deprecated
@Override
public void createTemporaryQueue(final SimpleString address,
final SimpleString queueName,
final QueueAttributes queueAttributes) throws ActiveMQException {
internalCreateQueue(address,
queueName,
true,
false,
queueAttributes);
}
@Deprecated
@Override
public void createTemporaryQueue(final SimpleString address,
final RoutingType routingType,
final SimpleString queueName,
final SimpleString filter) throws ActiveMQException {
createTemporaryQueue(address, routingType, queueName, filter, ActiveMQDefaultConfiguration.getDefaultMaxQueueConsumers(), ActiveMQDefaultConfiguration.getDefaultPurgeOnNoConsumers(), null, null);
}
@Override
public void createTemporaryQueue(final String address, final RoutingType routingType, final String queueName, final String filter) throws ActiveMQException {
createTemporaryQueue(SimpleString.toSimpleString(address), routingType, SimpleString.toSimpleString(queueName), SimpleString.toSimpleString(filter));
}
/**
* Creates a <em>non-temporary</em> queue.
*
* @param address the queue will be bound to this address
* @param routingType the delivery mode for this queue, MULTICAST or ANYCAST
* @param queueName the name of the queue
* @param durable whether the queue is durable or not
* @throws ActiveMQException in an exception occurs while creating the queue
*/
@Deprecated
@Override
public void createQueue(SimpleString address, RoutingType routingType, SimpleString queueName, boolean durable) throws ActiveMQException {
internalCreateQueue(address,
queueName,
false,
false,
new QueueAttributes()
.setRoutingType(routingType)
.setFilterString(null)
.setDurable(durable)
.setPurgeOnNoConsumers(ActiveMQDefaultConfiguration.getDefaultPurgeOnNoConsumers())
.setMaxConsumers(ActiveMQDefaultConfiguration.getDefaultMaxQueueConsumers()));
}
/**
* Creates a transient queue. A queue that will exist as long as there are consumers. When the last consumer is closed the queue will be deleted
* <p>
* Notice: you will get an exception if the address or the filter doesn't match to an already existent queue
*
* @param address the queue will be bound to this address
* @param routingType the delivery mode for this queue, MULTICAST or ANYCAST
* @param queueName the name of the queue
* @param durable if the queue is durable
* @throws ActiveMQException in an exception occurs while creating the queue
*/
@Override
public void createSharedQueue(SimpleString address, RoutingType routingType, SimpleString queueName, boolean durable) throws ActiveMQException {
createSharedQueue(address, routingType, queueName, null, durable);
}
/**
* Creates a transient queue. A queue that will exist as long as there are consumers. When the last consumer is closed the queue will be deleted
* <p>
* Notice: you will get an exception if the address or the filter doesn't match to an already existent queue
*
* @param address the queue will be bound to this address
* @param routingType the delivery mode for this queue, MULTICAST or ANYCAST
* @param queueName the name of the queue
* @param filter whether the queue is durable or not
* @param durable if the queue is durable
* @throws ActiveMQException in an exception occurs while creating the queue
*/
@Override
public void createSharedQueue(SimpleString address, RoutingType routingType, SimpleString queueName, SimpleString filter,
boolean durable) throws ActiveMQException {
createSharedQueue(address, routingType, queueName, filter, durable, null, null, null, null);
}
/**
* Creates Shared queue. A queue that will exist as long as there are consumers or is durable.
*
* @param address the queue will be bound to this address
* @param routingType the delivery mode for this queue, MULTICAST or ANYCAST
* @param queueName the name of the queue
* @param filter whether the queue is durable or not
* @param durable if the queue is durable
* @param maxConsumers how many concurrent consumers will be allowed on this queue
* @param purgeOnNoConsumers whether to delete the contents of the queue when the last consumer disconnects
* @param exclusive if the queue is exclusive queue
* @param lastValue if the queue is last value queue
* @throws ActiveMQException in an exception occurs while creating the queue
*/
@Deprecated
@Override
public void createSharedQueue(SimpleString address, RoutingType routingType, SimpleString queueName, SimpleString filter,
boolean durable, Integer maxConsumers, Boolean purgeOnNoConsumers, Boolean exclusive, Boolean lastValue) throws ActiveMQException {
QueueAttributes queueAttributes = new QueueAttributes()
.setRoutingType(routingType)
.setFilterString(filter)
.setDurable(durable)
.setPurgeOnNoConsumers(ActiveMQDefaultConfiguration.getDefaultPurgeOnNoConsumers())
.setMaxConsumers(ActiveMQDefaultConfiguration.getDefaultMaxQueueConsumers())
.setExclusive(exclusive)
.setLastValue(lastValue);
createSharedQueue(address, queueName, queueAttributes);
}
/**
* Creates Shared queue. A queue that will exist as long as there are consumers or is durable.
*
* @param address the queue will be bound to this address
* @param queueName the name of the queue
* @param queueAttributes attributes for the queue
* @throws ActiveMQException in an exception occurs while creating the queue
*/
@Deprecated
@Override
public void createSharedQueue(SimpleString address, SimpleString queueName, QueueAttributes queueAttributes) throws ActiveMQException {
createSharedQueue(queueAttributes.toQueueConfiguration().setName(queueName).setAddress(address));
}
/**
* Creates a <em>non-temporary</em> queue.
*
* @param address the queue will be bound to this address
* @param routingType the delivery mode for this queue, MULTICAST or ANYCAST
* @param queueName the name of the queue
* @param durable whether the queue is durable or not
* @throws ActiveMQException in an exception occurs while creating the queue
*/
@Override
public void createQueue(String address, RoutingType routingType, String queueName, boolean durable) throws ActiveMQException {
createQueue(SimpleString.toSimpleString(address), routingType, SimpleString.toSimpleString(queueName), durable);
}
/**
* Creates a <em>non-temporary</em> queue <em>non-durable</em> queue.
*
* @param address the queue will be bound to this address
* @param routingType the delivery mode for this queue, MULTICAST or ANYCAST
* @param queueName the name of the queue
* @throws ActiveMQException in an exception occurs while creating the queue
*/
@Deprecated
@Override
public void createQueue(String address, RoutingType routingType, String queueName) throws ActiveMQException {
internalCreateQueue(SimpleString.toSimpleString(address),
SimpleString.toSimpleString(queueName),
false,
false,
new QueueAttributes()
.setRoutingType(routingType)
.setFilterString(null)
.setDurable(false)
.setPurgeOnNoConsumers(ActiveMQDefaultConfiguration.getDefaultPurgeOnNoConsumers())
.setMaxConsumers(ActiveMQDefaultConfiguration.getDefaultMaxQueueConsumers()));
}
/**
* Creates a <em>non-temporary</em> queue <em>non-durable</em> queue.
*
* @param address the queue will be bound to this address
* @param routingType the delivery mode for this queue, MULTICAST or ANYCAST
* @param queueName the name of the queue
* @throws ActiveMQException in an exception occurs while creating the queue
*/
@Deprecated
@Override
public void createQueue(SimpleString address, RoutingType routingType, SimpleString queueName) throws ActiveMQException {
internalCreateQueue(address,
queueName,
false,
false,
new QueueAttributes()
.setRoutingType(routingType)
.setFilterString(null)
.setDurable(false)
.setPurgeOnNoConsumers(ActiveMQDefaultConfiguration.getDefaultPurgeOnNoConsumers())
.setMaxConsumers(ActiveMQDefaultConfiguration.getDefaultMaxQueueConsumers()));
}
/**
* Creates a <em>non-temporary</em> queue.
*
* @param address the queue will be bound to this address
* @param routingType the delivery mode for this queue, MULTICAST or ANYCAST
* @param queueName the name of the queue
* @param filter only messages which match this filter will be put in the queue
* @param durable whether the queue is durable or not
* @throws ActiveMQException in an exception occurs while creating the queue
*/
@Deprecated
@Override
public void createQueue(SimpleString address, RoutingType routingType, SimpleString queueName, SimpleString filter,
boolean durable) throws ActiveMQException {
internalCreateQueue(address,
queueName,
false,
false,
new QueueAttributes()
.setRoutingType(routingType)
.setFilterString(filter)
.setDurable(durable)
.setPurgeOnNoConsumers(ActiveMQDefaultConfiguration.getDefaultPurgeOnNoConsumers())
.setMaxConsumers(ActiveMQDefaultConfiguration.getDefaultMaxQueueConsumers()));
}
/**
* Creates a <em>non-temporary</em>queue.
*
* @param address the queue will be bound to this address
* @param routingType the delivery mode for this queue, MULTICAST or ANYCAST
* @param queueName the name of the queue
* @param filter only messages which match this filter will be put in the queue
* @param durable whether the queue is durable or not
* @throws ActiveMQException in an exception occurs while creating the queue
*/
@Override
public void createQueue(String address, RoutingType routingType, String queueName, String filter, boolean durable) throws ActiveMQException {
createQueue(SimpleString.toSimpleString(address), routingType, SimpleString.toSimpleString(queueName), SimpleString.toSimpleString(filter),
durable);
}
@Override
public void deleteQueue(final SimpleString queueName) throws ActiveMQException {
checkClosed();
startCall();
try {
sessionContext.deleteQueue(queueName);
} finally {
endCall();
}
}
@Override
public void deleteQueue(final String queueName) throws ActiveMQException {
deleteQueue(SimpleString.toSimpleString(queueName));
}
@Override
public QueueQuery queueQuery(final SimpleString queueName) throws ActiveMQException {
checkClosed();
startCall();
try {
return sessionContext.queueQuery(queueName);
} finally {
endCall();
}
}
@Override
public AddressQuery addressQuery(final SimpleString address) throws ActiveMQException {
checkClosed();
return sessionContext.addressQuery(address);
}
@Override
public ClientConsumer createConsumer(final SimpleString queueName) throws ActiveMQException {
return createConsumer(queueName, null, false);
}
@Override
public ClientConsumer createConsumer(final String queueName) throws ActiveMQException {
return createConsumer(SimpleString.toSimpleString(queueName));
}
@Override
public ClientConsumer createConsumer(final SimpleString queueName,
final SimpleString filterString) throws ActiveMQException {
return createConsumer(queueName, filterString, consumerWindowSize, consumerMaxRate, false);
}
@Override
public void createQueue(final String address, final String queueName) throws ActiveMQException {
createQueue(SimpleString.toSimpleString(address), SimpleString.toSimpleString(queueName));
}
@Override
public ClientConsumer createConsumer(final String queueName, final String filterString) throws ActiveMQException {
return createConsumer(SimpleString.toSimpleString(queueName), SimpleString.toSimpleString(filterString));
}
@Override
public ClientConsumer createConsumer(final SimpleString queueName,
final SimpleString filterString,
final boolean browseOnly) throws ActiveMQException {
return createConsumer(queueName, filterString, consumerWindowSize, consumerMaxRate, browseOnly);
}
@Override
public ClientConsumer createConsumer(final SimpleString queueName,
final SimpleString filterString,
final int priority,
final boolean browseOnly) throws ActiveMQException {
return createConsumer(queueName, filterString, priority, consumerWindowSize, consumerMaxRate, browseOnly);
}
@Override
public ClientConsumer createConsumer(final SimpleString queueName,
final boolean browseOnly) throws ActiveMQException {
return createConsumer(queueName, null, consumerWindowSize, consumerMaxRate, browseOnly);
}
@Override
public ClientConsumer createConsumer(final String queueName,
final String filterString,
final boolean browseOnly) throws ActiveMQException {
return createConsumer(SimpleString.toSimpleString(queueName), SimpleString.toSimpleString(filterString), browseOnly);
}
@Override
public ClientConsumer createConsumer(final String queueName, final boolean browseOnly) throws ActiveMQException {
return createConsumer(SimpleString.toSimpleString(queueName), null, browseOnly);
}
@Override
public boolean isWritable(ReadyListener callback) {
return sessionContext.isWritable(callback);
}
@Override
public ClientConsumer createConsumer(final SimpleString queueName,
final SimpleString filterString,
final int windowSize,
final int maxRate,
final boolean browseOnly) throws ActiveMQException {
return createConsumer(queueName, filterString, ActiveMQDefaultConfiguration.getDefaultConsumerPriority(), windowSize, maxRate, browseOnly);
}
/**
* Note, we DO NOT currently support direct consumers (i.e. consumers where delivery occurs on
* the remoting thread).
* <p>
* Direct consumers have issues with blocking and failover. E.g. if direct then inside
* MessageHandler call a blocking method like rollback or acknowledge (blocking) This can block
* until failover completes, which disallows the thread to be used to deliver any responses to
* the client during that period, so failover won't occur. If we want direct consumers we need to
* rethink how they work.
*/
@Override
public ClientConsumer createConsumer(final SimpleString queueName,
final SimpleString filterString,
final int priority,
final int windowSize,
final int maxRate,
final boolean browseOnly) throws ActiveMQException {
return internalCreateConsumer(queueName, filterString, priority, windowSize, maxRate, browseOnly);
}
@Override
public ClientConsumer createConsumer(final String queueName,
final String filterString,
final int windowSize,
final int maxRate,
final boolean browseOnly) throws ActiveMQException {
return createConsumer(SimpleString.toSimpleString(queueName), SimpleString.toSimpleString(filterString), windowSize, maxRate, browseOnly);
}
@Override
public ClientProducer createProducer() throws ActiveMQException {
return createProducer((SimpleString) null);
}
@Override
public ClientProducer createProducer(final SimpleString address) throws ActiveMQException {
return createProducer(address, producerMaxRate);
}
@Override
public ClientProducer createProducer(final String address) throws ActiveMQException {
return createProducer(SimpleString.toSimpleString(address));
}
@Override
public ClientProducer createProducer(final SimpleString address, final int maxRate) throws ActiveMQException {
return internalCreateProducer(address, maxRate);
}
public ClientProducer createProducer(final String address, final int rate) throws ActiveMQException {
return createProducer(SimpleString.toSimpleString(address), rate);
}
@Override
public XAResource getXAResource() {
return this;
}
private void rollbackOnFailover(boolean outcomeKnown) throws ActiveMQException {
rollback(false);
if (outcomeKnown) {
throw ActiveMQClientMessageBundle.BUNDLE.txRolledBack();
}
throw ActiveMQClientMessageBundle.BUNDLE.txOutcomeUnknown();
}
@Override
public void commit() throws ActiveMQException {
commit(true);
}
@Override
public void commit(boolean block) throws ActiveMQException {
checkClosed();
if (logger.isTraceEnabled()) {
logger.trace("Sending commit");
}
/*
* we have failed over since any work was done so we should rollback
* */
if (rollbackOnly) {
rollbackOnFailover(true);
}
flushAcks();
/*
* if we have failed over whilst flushing the acks then we should rollback and throw exception before attempting to
* commit as committing might actually commit something but we we wouldn't know and rollback after the commit
* */
if (rollbackOnly) {
rollbackOnFailover(true);
}
try {
sessionContext.simpleCommit(block);
} catch (ActiveMQException e) {
if (e.getType() == ActiveMQExceptionType.UNBLOCKED || e.getType() == ActiveMQExceptionType.CONNECTION_TIMEDOUT || rollbackOnly) {
// The call to commit was unlocked on failover, we therefore rollback the tx,
// and throw a transaction rolled back exception instead
//or
//if we have been set to rollbackonly then we have probably failed over and don't know if the tx has committed
rollbackOnFailover(false);
} else {
throw e;
}
}
//oops, we have failed over during the commit and don't know what happened
if (rollbackOnly) {
rollbackOnFailover(false);
}
workDone = false;
}
@Override
public boolean isRollbackOnly() {
return rollbackOnly;
}
@Override
public void rollback() throws ActiveMQException {
rollback(false);
}
@Override
public void rollback(final boolean isLastMessageAsDelivered) throws ActiveMQException {
rollback(isLastMessageAsDelivered, true);
}
public void rollback(final boolean isLastMessageAsDelivered, final boolean waitConsumers) throws ActiveMQException {