-
Notifications
You must be signed in to change notification settings - Fork 910
/
QueueImpl.java
4582 lines (3757 loc) · 158 KB
/
QueueImpl.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.server.impl;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import java.util.concurrent.locks.ReentrantLock;
import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration;
import org.apache.activemq.artemis.api.core.ActiveMQException;
import org.apache.activemq.artemis.api.core.ActiveMQNullRefException;
import org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException;
import org.apache.activemq.artemis.api.core.Message;
import org.apache.activemq.artemis.api.core.Pair;
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.management.CoreNotificationType;
import org.apache.activemq.artemis.api.core.management.ManagementHelper;
import org.apache.activemq.artemis.core.PriorityAware;
import org.apache.activemq.artemis.core.filter.Filter;
import org.apache.activemq.artemis.core.filter.impl.FilterImpl;
import org.apache.activemq.artemis.core.io.IOCallback;
import org.apache.activemq.artemis.core.paging.PagingStore;
import org.apache.activemq.artemis.core.paging.cursor.PageIterator;
import org.apache.activemq.artemis.core.paging.cursor.PagePosition;
import org.apache.activemq.artemis.core.paging.cursor.PageSubscription;
import org.apache.activemq.artemis.core.paging.cursor.PagedReference;
import org.apache.activemq.artemis.core.persistence.AddressQueueStatus;
import org.apache.activemq.artemis.core.persistence.OperationContext;
import org.apache.activemq.artemis.core.persistence.StorageManager;
import org.apache.activemq.artemis.core.persistence.impl.journal.LargeServerMessageImpl;
import org.apache.activemq.artemis.core.postoffice.Binding;
import org.apache.activemq.artemis.core.postoffice.Bindings;
import org.apache.activemq.artemis.core.postoffice.DuplicateIDCache;
import org.apache.activemq.artemis.core.postoffice.PostOffice;
import org.apache.activemq.artemis.core.postoffice.RoutingStatus;
import org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding;
import org.apache.activemq.artemis.core.postoffice.impl.PostOfficeImpl;
import org.apache.activemq.artemis.core.remoting.server.RemotingService;
import org.apache.activemq.artemis.core.server.ActiveMQMessageBundle;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.core.server.ActiveMQServerLogger;
import org.apache.activemq.artemis.core.server.Consumer;
import org.apache.activemq.artemis.core.server.HandleStatus;
import org.apache.activemq.artemis.core.server.MessageReference;
import org.apache.activemq.artemis.core.server.Queue;
import org.apache.activemq.artemis.core.server.QueueFactory;
import org.apache.activemq.artemis.core.server.RoutingContext;
import org.apache.activemq.artemis.core.server.ScheduledDeliveryHandler;
import org.apache.activemq.artemis.core.server.ServerConsumer;
import org.apache.activemq.artemis.core.server.ServerSession;
import org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding;
import org.apache.activemq.artemis.core.server.cluster.impl.Redistributor;
import org.apache.activemq.artemis.core.server.management.ManagementService;
import org.apache.activemq.artemis.core.server.management.Notification;
import org.apache.activemq.artemis.core.settings.HierarchicalRepository;
import org.apache.activemq.artemis.core.settings.HierarchicalRepositoryChangeListener;
import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
import org.apache.activemq.artemis.core.settings.impl.SlowConsumerPolicy;
import org.apache.activemq.artemis.core.settings.impl.SlowConsumerThresholdMeasurementUnit;
import org.apache.activemq.artemis.core.transaction.Transaction;
import org.apache.activemq.artemis.core.transaction.TransactionOperationAbstract;
import org.apache.activemq.artemis.core.transaction.TransactionPropertyIndexes;
import org.apache.activemq.artemis.core.transaction.impl.BindingsTransactionImpl;
import org.apache.activemq.artemis.core.transaction.impl.TransactionImpl;
import org.apache.activemq.artemis.logs.AuditLogger;
import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
import org.apache.activemq.artemis.utils.ArtemisCloseable;
import org.apache.activemq.artemis.utils.BooleanUtil;
import org.apache.activemq.artemis.utils.Env;
import org.apache.activemq.artemis.utils.ReferenceCounter;
import org.apache.activemq.artemis.utils.ReusableLatch;
import org.apache.activemq.artemis.utils.actors.ArtemisExecutor;
import org.apache.activemq.artemis.utils.collections.ConcurrentHashSet;
import org.apache.activemq.artemis.utils.collections.NodeStore;
import org.apache.activemq.artemis.utils.collections.LinkedListIterator;
import org.apache.activemq.artemis.utils.collections.PriorityLinkedList;
import org.apache.activemq.artemis.utils.collections.PriorityLinkedListImpl;
import org.apache.activemq.artemis.utils.collections.TypedProperties;
import org.apache.activemq.artemis.utils.critical.CriticalComponentImpl;
import org.apache.activemq.artemis.utils.critical.EmptyCriticalAnalyzer;
import org.jboss.logging.Logger;
import org.jctools.queues.MpscUnboundedArrayQueue;
import static org.apache.activemq.artemis.utils.collections.IterableStream.iterableOf;
/**
* Implementation of a Queue
* <p>
* Completely non blocking between adding to queue and delivering to consumers.
*/
public class QueueImpl extends CriticalComponentImpl implements Queue {
protected static final int CRITICAL_PATHS = 5;
protected static final int CRITICAL_PATH_ADD_TAIL = 0;
protected static final int CRITICAL_PATH_ADD_HEAD = 1;
protected static final int CRITICAL_DELIVER = 2;
protected static final int CRITICAL_CONSUMER = 3;
protected static final int CRITICAL_CHECK_DEPAGE = 4;
private static final Logger logger = Logger.getLogger(QueueImpl.class);
private static final AtomicIntegerFieldUpdater<QueueImpl> dispatchingUpdater = AtomicIntegerFieldUpdater.newUpdater(QueueImpl.class, "dispatching");
private static final AtomicLongFieldUpdater<QueueImpl> dispatchStartTimeUpdater = AtomicLongFieldUpdater.newUpdater(QueueImpl.class, "dispatchStartTime");
private static final AtomicLongFieldUpdater<QueueImpl> consumerRemovedTimestampUpdater = AtomicLongFieldUpdater.newUpdater(QueueImpl.class, "consumerRemovedTimestamp");
private static final AtomicReferenceFieldUpdater<QueueImpl, Filter> filterUpdater = AtomicReferenceFieldUpdater.newUpdater(QueueImpl.class, Filter.class, "filter");
public static final int REDISTRIBUTOR_BATCH_SIZE = 100;
public static final int NUM_PRIORITIES = 10;
public static final int MAX_DELIVERIES_IN_LOOP = 1000;
public static final int CHECK_QUEUE_SIZE_PERIOD = 1000;
/**
* If The system gets slow for any reason, this is the maximum time a Delivery or
* or depage executor should be hanging on
*/
public static final int DELIVERY_TIMEOUT = 1000;
public static final int DEFAULT_FLUSH_LIMIT = 500;
private final Long id;
private final SimpleString name;
private SimpleString user;
private volatile Filter filter;
private final boolean propertyDurable;
private final boolean temporary;
private final boolean autoCreated;
private final PostOffice postOffice;
private volatile boolean queueDestroyed = false;
private final PagingStore pagingStore;
protected final PageSubscription pageSubscription;
private final ReferenceCounter refCountForConsumers;
private final PageIterator pageIterator;
private volatile boolean printErrorExpiring = false;
private boolean mirrorController;
private volatile boolean hasUnMatchedPending = false;
// Messages will first enter intermediateMessageReferences
// Before they are added to messageReferences
// This is to avoid locking the queue on the producer
private final MpscUnboundedArrayQueue<MessageReference> intermediateMessageReferences = new MpscUnboundedArrayQueue<>(8192);
// This is where messages are stored
private final PriorityLinkedList<MessageReference> messageReferences = new PriorityLinkedListImpl<>(QueueImpl.NUM_PRIORITIES, MessageReferenceImpl.getIDComparator());
private NodeStore<MessageReference> nodeStore;
private void checkIDSupplier(NodeStore<MessageReference> nodeStore) {
if (this.nodeStore != nodeStore) {
this.nodeStore = nodeStore;
messageReferences.setNodeStore(nodeStore);
}
}
// The quantity of pagedReferences on messageReferences priority list
private final AtomicInteger pagedReferences = new AtomicInteger(0);
// The estimate of memory being consumed by this queue. Used to calculate instances of messages to depage
private final AtomicInteger queueMemorySize = new AtomicInteger(0);
protected final QueueMessageMetrics pendingMetrics = new QueueMessageMetrics(this, "pending");
private final QueueMessageMetrics deliveringMetrics = new QueueMessageMetrics(this, "delivering");
protected final ScheduledDeliveryHandler scheduledDeliveryHandler;
private final AtomicLong messagesAdded = new AtomicLong(0);
private final AtomicLong messagesAcknowledged = new AtomicLong(0);
private final AtomicLong ackAttempts = new AtomicLong(0);
private final AtomicLong messagesExpired = new AtomicLong(0);
private final AtomicLong messagesKilled = new AtomicLong(0);
private final AtomicLong messagesReplaced = new AtomicLong(0);
private boolean paused;
private long pauseStatusRecord = -1;
private static final int MAX_SCHEDULED_RUNNERS = 1;
private static final int MAX_DEPAGE_NUM = MAX_DELIVERIES_IN_LOOP * MAX_SCHEDULED_RUNNERS;
// We don't ever need more than two DeliverRunner on the executor's list
// that is getting the worse scenario possible when one runner is almost finishing before the second started
// for that we keep a counter of scheduled instances
private final AtomicInteger scheduledRunners = new AtomicInteger(0);
private final Runnable deliverRunner = new DeliverRunner();
//This lock is used to prevent deadlocks between direct and async deliveries
private final ReentrantLock deliverLock = new ReentrantLock();
private final ReentrantLock depageLock = new ReentrantLock();
private volatile boolean depagePending = false;
private final StorageManager storageManager;
private final HierarchicalRepository<AddressSettings> addressSettingsRepository;
private final ActiveMQServer server;
private final ScheduledExecutorService scheduledExecutor;
private final SimpleString address;
// redistributor singleton goes in the consumers list
private ConsumerHolder<Redistributor> redistributor;
private ScheduledFuture<?> redistributorFuture;
// This is used by an AtomicFieldUpdater
private volatile long consumerRemovedTimestamp = -1;
private final QueueConsumers<ConsumerHolder<? extends Consumer>> consumers = new QueueConsumersImpl<>();
private volatile boolean groupRebalance;
private volatile boolean groupRebalancePauseDispatch;
private volatile int groupBuckets;
private volatile SimpleString groupFirstKey;
private MessageGroups<Consumer> groups;
private volatile Consumer exclusiveConsumer;
private volatile SimpleString expiryAddress;
private final ArtemisExecutor executor;
private boolean internalQueue;
private volatile long lastDirectDeliveryCheck = 0;
private volatile boolean directDeliver = true;
private volatile boolean supportsDirectDeliver = false;
private AddressSettingsRepositoryListener addressSettingsRepositoryListener;
private final ExpiryScanner expiryScanner = new ExpiryScanner();
private final ReusableLatch deliveriesInTransit = new ReusableLatch(0);
private final AtomicLong queueRateCheckTime = new AtomicLong(System.currentTimeMillis());
private final AtomicLong messagesAddedSnapshot = new AtomicLong(0);
private ScheduledFuture slowConsumerReaperFuture;
private SlowConsumerReaperRunnable slowConsumerReaperRunnable;
private volatile int maxConsumers;
private volatile boolean exclusive;
private volatile boolean purgeOnNoConsumers;
private volatile boolean enabled;
private final AddressInfo addressInfo;
private volatile RoutingType routingType;
private final QueueFactory factory;
public volatile int dispatching = 0;
public volatile long dispatchStartTime = -1;
private volatile int consumersBeforeDispatch = 0;
private volatile long delayBeforeDispatch = 0;
private final boolean autoDelete;
private final long autoDeleteDelay;
private final long autoDeleteMessageCount;
private volatile boolean configurationManaged;
private volatile boolean nonDestructive;
private volatile long ringSize;
/* in certain cases we need to redeliver a message directly.
* it's useful for usecases last LastValueQueue */
protected MessageReference nextDelivery() {
return null;
}
protected void repeatNextDelivery(MessageReference reference) {
}
/**
* This is to avoid multi-thread races on calculating direct delivery,
* to guarantee ordering will be always be correct
*/
private final Object directDeliveryGuard = new Object();
private final ConcurrentHashSet<String> lingerSessionIds = new ConcurrentHashSet<>();
public String debug() {
StringWriter str = new StringWriter();
PrintWriter out = new PrintWriter(str);
out.println("queueMemorySize=" + queueMemorySize);
for (ConsumerHolder holder : consumers) {
out.println("consumer: " + holder.consumer.debug());
}
out.println("Intermediate reference size is " + intermediateMessageReferences.size());
boolean foundRef = false;
synchronized (this) {
Iterator<MessageReference> iter = messageReferences.iterator();
while (iter.hasNext()) {
foundRef = true;
out.println("reference = " + iter.next());
}
}
if (!foundRef) {
out.println("No permanent references on queue");
}
System.out.println(str.toString());
return str.toString();
}
@Deprecated
public QueueImpl(final long id,
final SimpleString address,
final SimpleString name,
final Filter filter,
final SimpleString user,
final boolean durable,
final boolean temporary,
final boolean autoCreated,
final ScheduledExecutorService scheduledExecutor,
final PostOffice postOffice,
final StorageManager storageManager,
final HierarchicalRepository<AddressSettings> addressSettingsRepository,
final ArtemisExecutor executor,
final ActiveMQServer server,
final QueueFactory factory) {
this(id, address, name, filter, null, null, user, durable, temporary, autoCreated, scheduledExecutor, postOffice, storageManager, addressSettingsRepository, executor, server, factory);
}
@Deprecated
public QueueImpl(final long id,
final SimpleString address,
final SimpleString name,
final Filter filter,
final PagingStore pagingStore,
final PageSubscription pageSubscription,
final SimpleString user,
final boolean durable,
final boolean temporary,
final boolean autoCreated,
final ScheduledExecutorService scheduledExecutor,
final PostOffice postOffice,
final StorageManager storageManager,
final HierarchicalRepository<AddressSettings> addressSettingsRepository,
final ArtemisExecutor executor,
final ActiveMQServer server,
final QueueFactory factory) {
this(id, address, name, filter, pagingStore, pageSubscription, user, durable, temporary, autoCreated, RoutingType.MULTICAST, null, null, scheduledExecutor, postOffice, storageManager, addressSettingsRepository, executor, server, factory);
}
@Deprecated
public QueueImpl(final long id,
final SimpleString address,
final SimpleString name,
final Filter filter,
final PagingStore pagingStore,
final PageSubscription pageSubscription,
final SimpleString user,
final boolean durable,
final boolean temporary,
final boolean autoCreated,
final RoutingType routingType,
final Integer maxConsumers,
final Boolean purgeOnNoConsumers,
final ScheduledExecutorService scheduledExecutor,
final PostOffice postOffice,
final StorageManager storageManager,
final HierarchicalRepository<AddressSettings> addressSettingsRepository,
final ArtemisExecutor executor,
final ActiveMQServer server,
final QueueFactory factory) {
this(id, address, name, filter, pagingStore, pageSubscription, user, durable, temporary, autoCreated, routingType, maxConsumers, null, purgeOnNoConsumers, scheduledExecutor, postOffice, storageManager, addressSettingsRepository, executor, server, factory);
}
@Deprecated
public QueueImpl(final long id,
final SimpleString address,
final SimpleString name,
final Filter filter,
final PagingStore pagingStore,
final PageSubscription pageSubscription,
final SimpleString user,
final boolean durable,
final boolean temporary,
final boolean autoCreated,
final RoutingType routingType,
final Integer maxConsumers,
final Boolean exclusive,
final Boolean purgeOnNoConsumers,
final ScheduledExecutorService scheduledExecutor,
final PostOffice postOffice,
final StorageManager storageManager,
final HierarchicalRepository<AddressSettings> addressSettingsRepository,
final ArtemisExecutor executor,
final ActiveMQServer server,
final QueueFactory factory) {
this(id, address, name, filter, pagingStore, pageSubscription, user, durable, temporary, autoCreated, routingType, maxConsumers, exclusive, null, null, false, null, null, purgeOnNoConsumers, null, null, null, false, scheduledExecutor, postOffice, storageManager, addressSettingsRepository, executor, server, factory);
}
@Deprecated
public QueueImpl(final long id,
final SimpleString address,
final SimpleString name,
final Filter filter,
final PagingStore pagingStore,
final PageSubscription pageSubscription,
final SimpleString user,
final boolean durable,
final boolean temporary,
final boolean autoCreated,
final RoutingType routingType,
final Integer maxConsumers,
final Boolean exclusive,
final Boolean groupRebalance,
final Integer groupBuckets,
final Boolean nonDestructive,
final Integer consumersBeforeDispatch,
final Long delayBeforeDispatch,
final Boolean purgeOnNoConsumers,
final Boolean autoDelete,
final Long autoDeleteDelay,
final Long autoDeleteMessageCount,
final boolean configurationManaged,
final ScheduledExecutorService scheduledExecutor,
final PostOffice postOffice,
final StorageManager storageManager,
final HierarchicalRepository<AddressSettings> addressSettingsRepository,
final ArtemisExecutor executor,
final ActiveMQServer server,
final QueueFactory factory) {
this(id, address, name, filter, pagingStore, pageSubscription, user, durable, temporary, autoCreated, routingType, maxConsumers, exclusive, groupRebalance, groupBuckets, null, nonDestructive, consumersBeforeDispatch, delayBeforeDispatch, purgeOnNoConsumers, autoDelete, autoDeleteDelay, autoDeleteMessageCount, configurationManaged, scheduledExecutor, postOffice, storageManager, addressSettingsRepository, executor, server, factory);
}
@Deprecated
public QueueImpl(final long id,
final SimpleString address,
final SimpleString name,
final Filter filter,
final PagingStore pagingStore,
final PageSubscription pageSubscription,
final SimpleString user,
final boolean durable,
final boolean temporary,
final boolean autoCreated,
final RoutingType routingType,
final Integer maxConsumers,
final Boolean exclusive,
final Boolean groupRebalance,
final Integer groupBuckets,
final SimpleString groupFirstKey,
final Boolean nonDestructive,
final Integer consumersBeforeDispatch,
final Long delayBeforeDispatch,
final Boolean purgeOnNoConsumers,
final Boolean autoDelete,
final Long autoDeleteDelay,
final Long autoDeleteMessageCount,
final boolean configurationManaged,
final ScheduledExecutorService scheduledExecutor,
final PostOffice postOffice,
final StorageManager storageManager,
final HierarchicalRepository<AddressSettings> addressSettingsRepository,
final ArtemisExecutor executor,
final ActiveMQServer server,
final QueueFactory factory) {
this(id, address, name, filter, pagingStore, pageSubscription, user, durable, temporary, autoCreated, routingType, maxConsumers, exclusive, groupRebalance, groupBuckets, groupFirstKey, nonDestructive, consumersBeforeDispatch, delayBeforeDispatch, purgeOnNoConsumers, autoDelete, autoDeleteDelay, autoDeleteMessageCount, configurationManaged, null, scheduledExecutor, postOffice, storageManager, addressSettingsRepository, executor, server, factory);
}
@Deprecated
public QueueImpl(final long id,
final SimpleString address,
final SimpleString name,
final Filter filter,
final PagingStore pagingStore,
final PageSubscription pageSubscription,
final SimpleString user,
final boolean durable,
final boolean temporary,
final boolean autoCreated,
final RoutingType routingType,
final Integer maxConsumers,
final Boolean exclusive,
final Boolean groupRebalance,
final Integer groupBuckets,
final SimpleString groupFirstKey,
final Boolean nonDestructive,
final Integer consumersBeforeDispatch,
final Long delayBeforeDispatch,
final Boolean purgeOnNoConsumers,
final Boolean autoDelete,
final Long autoDeleteDelay,
final Long autoDeleteMessageCount,
final boolean configurationManaged,
final Long ringSize,
final ScheduledExecutorService scheduledExecutor,
final PostOffice postOffice,
final StorageManager storageManager,
final HierarchicalRepository<AddressSettings> addressSettingsRepository,
final ArtemisExecutor executor,
final ActiveMQServer server,
final QueueFactory factory) {
this(new QueueConfiguration(name)
.setId(id)
.setAddress(address)
.setFilterString(filter == null ? null : filter.getFilterString())
.setUser(user)
.setDurable(durable)
.setTemporary(temporary)
.setAutoCreated(autoCreated)
.setRoutingType(routingType)
.setMaxConsumers(maxConsumers)
.setExclusive(exclusive)
.setGroupRebalance(groupRebalance)
.setGroupBuckets(groupBuckets)
.setGroupFirstKey(groupFirstKey)
.setNonDestructive(nonDestructive)
.setConsumersBeforeDispatch(consumersBeforeDispatch)
.setDelayBeforeDispatch(delayBeforeDispatch)
.setPurgeOnNoConsumers(purgeOnNoConsumers)
.setAutoDelete(autoDelete)
.setAutoDeleteDelay(autoDeleteDelay)
.setAutoDeleteMessageCount(autoDeleteMessageCount)
.setConfigurationManaged(configurationManaged)
.setRingSize(ringSize),
pagingStore,
pageSubscription,
scheduledExecutor,
postOffice,
storageManager,
addressSettingsRepository,
executor,
server,
factory);
this.filter = filter;
}
public QueueImpl(final QueueConfiguration queueConfiguration,
final PagingStore pagingStore,
final PageSubscription pageSubscription,
final ScheduledExecutorService scheduledExecutor,
final PostOffice postOffice,
final StorageManager storageManager,
final HierarchicalRepository<AddressSettings> addressSettingsRepository,
final ArtemisExecutor executor,
final ActiveMQServer server,
final QueueFactory factory) {
super(server == null ? EmptyCriticalAnalyzer.getInstance() : server.getCriticalAnalyzer(), CRITICAL_PATHS);
this.id = queueConfiguration.getId();
this.address = queueConfiguration.getAddress();
this.refCountForConsumers = queueConfiguration.isTransient() ? new TransientQueueManagerImpl(server, queueConfiguration.getName()) : new QueueManagerImpl(server, queueConfiguration.getName());
this.addressInfo = postOffice == null ? null : postOffice.getAddressInfo(address);
this.routingType = queueConfiguration.getRoutingType();
this.name = queueConfiguration.getName();
try {
this.filter = filter == null ? FilterImpl.createFilter(queueConfiguration.getFilterString()) : filter;
} catch (ActiveMQException e) {
throw new RuntimeException(e);
}
this.pagingStore = pagingStore;
this.pageSubscription = pageSubscription;
this.propertyDurable = queueConfiguration.isDurable();
this.temporary = queueConfiguration.isTemporary();
this.autoCreated = queueConfiguration.isAutoCreated();
this.maxConsumers = queueConfiguration.getMaxConsumers() == null ? ActiveMQDefaultConfiguration.getDefaultMaxQueueConsumers() : queueConfiguration.getMaxConsumers();
this.exclusive = queueConfiguration.isExclusive() == null ? ActiveMQDefaultConfiguration.getDefaultExclusive() : queueConfiguration.isExclusive();
this.nonDestructive = queueConfiguration.isNonDestructive() == null ? ActiveMQDefaultConfiguration.getDefaultNonDestructive() : queueConfiguration.isNonDestructive();
this.purgeOnNoConsumers = queueConfiguration.isPurgeOnNoConsumers() == null ? ActiveMQDefaultConfiguration.getDefaultPurgeOnNoConsumers() : queueConfiguration.isPurgeOnNoConsumers();
this.enabled = queueConfiguration.isEnabled() == null ? ActiveMQDefaultConfiguration.getDefaultEnabled() : queueConfiguration.isEnabled();
this.consumersBeforeDispatch = queueConfiguration.getConsumersBeforeDispatch() == null ? ActiveMQDefaultConfiguration.getDefaultConsumersBeforeDispatch() : queueConfiguration.getConsumersBeforeDispatch();
this.delayBeforeDispatch = queueConfiguration.getDelayBeforeDispatch() == null ? ActiveMQDefaultConfiguration.getDefaultDelayBeforeDispatch() : queueConfiguration.getDelayBeforeDispatch();
this.groupRebalance = queueConfiguration.isGroupRebalance() == null ? ActiveMQDefaultConfiguration.getDefaultGroupRebalance() : queueConfiguration.isGroupRebalance();
this.groupRebalancePauseDispatch = queueConfiguration.isGroupRebalancePauseDispatch() == null ? ActiveMQDefaultConfiguration.getDefaultGroupRebalancePauseDispatch() : queueConfiguration.isGroupRebalancePauseDispatch();
this.groupBuckets = queueConfiguration.getGroupBuckets() == null ? ActiveMQDefaultConfiguration.getDefaultGroupBuckets() : queueConfiguration.getGroupBuckets();
this.groups = groupMap(this.groupBuckets);
this.groupFirstKey = queueConfiguration.getGroupFirstKey() == null ? ActiveMQDefaultConfiguration.getDefaultGroupFirstKey() : queueConfiguration.getGroupFirstKey();
this.autoDelete = queueConfiguration.isAutoDelete() == null ? ActiveMQDefaultConfiguration.getDefaultQueueAutoDelete(autoCreated) : queueConfiguration.isAutoDelete();
this.autoDeleteDelay = queueConfiguration.getAutoDeleteDelay() == null ? ActiveMQDefaultConfiguration.getDefaultQueueAutoDeleteDelay() : queueConfiguration.getAutoDeleteDelay();
this.autoDeleteMessageCount = queueConfiguration.getAutoDeleteMessageCount() == null ? ActiveMQDefaultConfiguration.getDefaultQueueAutoDeleteMessageCount() : queueConfiguration.getAutoDeleteMessageCount();
this.configurationManaged = queueConfiguration.isConfigurationManaged();
this.postOffice = postOffice;
this.storageManager = storageManager;
this.addressSettingsRepository = addressSettingsRepository;
this.scheduledExecutor = scheduledExecutor;
this.server = server;
scheduledDeliveryHandler = new ScheduledDeliveryHandlerImpl(scheduledExecutor, this);
if (addressSettingsRepository != null) {
addressSettingsRepositoryListener = new AddressSettingsRepositoryListener();
addressSettingsRepository.registerListener(addressSettingsRepositoryListener);
} else {
expiryAddress = null;
}
if (pageSubscription != null) {
pageSubscription.setQueue(this);
this.pageIterator = pageSubscription.iterator();
} else {
this.pageIterator = null;
}
this.executor = executor;
this.user = queueConfiguration.getUser();
this.factory = factory;
if (this.addressInfo != null && this.addressInfo.isPaused()) {
this.pause(false);
}
this.ringSize = queueConfiguration.getRingSize() == null ? ActiveMQDefaultConfiguration.getDefaultRingSize() : queueConfiguration.getRingSize();
}
// Bindable implementation -------------------------------------------------------------------------------------
@Override
public boolean allowsReferenceCallback() {
// non destructive queues will reuse the same reference between multiple consumers
// so you cannot really use the callback from the MessageReference
return !nonDestructive;
}
@Override
public boolean isMirrorController() {
return mirrorController;
}
@Override
public void setMirrorController(boolean mirrorController) {
this.mirrorController = mirrorController;
}
public SimpleString getRoutingName() {
return name;
}
public SimpleString getUniqueName() {
return name;
}
@Override
public SimpleString getUser() {
return user;
}
@Override
public void setUser(SimpleString user) {
this.user = user;
}
@Override
public boolean isExclusive() {
return exclusive;
}
@Override
public synchronized void setExclusive(boolean exclusive) {
this.exclusive = exclusive;
if (!exclusive) {
exclusiveConsumer = null;
}
}
@Override
public int getConsumersBeforeDispatch() {
return consumersBeforeDispatch;
}
@Override
public synchronized void setConsumersBeforeDispatch(int consumersBeforeDispatch) {
this.consumersBeforeDispatch = consumersBeforeDispatch;
}
@Override
public long getDelayBeforeDispatch() {
return delayBeforeDispatch;
}
@Override
public synchronized void setDelayBeforeDispatch(long delayBeforeDispatch) {
this.delayBeforeDispatch = delayBeforeDispatch;
}
@Override
public long getDispatchStartTime() {
return dispatchStartTimeUpdater.get(this);
}
@Override
public boolean isDispatching() {
return BooleanUtil.toBoolean(dispatchingUpdater.get(this));
}
@Override
public synchronized void setDispatching(boolean dispatching) {
if (dispatchingUpdater.compareAndSet(this, BooleanUtil.toInt(!dispatching), BooleanUtil.toInt(dispatching))) {
if (dispatching) {
dispatchStartTimeUpdater.set(this, System.currentTimeMillis());
} else {
dispatchStartTimeUpdater.set(this, -1);
}
}
}
@Override
public boolean isLastValue() {
return false;
}
@Override
public SimpleString getLastValueKey() {
return null;
}
@Override
public boolean isNonDestructive() {
return nonDestructive;
}
@Override
public synchronized void setNonDestructive(boolean nonDestructive) {
this.nonDestructive = nonDestructive;
}
@Override
public void route(final Message message, final RoutingContext context) throws Exception {
if (!enabled) {
context.setReusable(false);
return;
}
if (purgeOnNoConsumers) {
context.setReusable(false);
if (getConsumerCount() == 0) {
return;
}
}
context.addQueue(address, this);
}
@Override
public void routeWithAck(Message message, RoutingContext context) {
context.addQueueWithAck(address, this);
}
// Queue implementation ----------------------------------------------------------------------------------------
@Override
public ReferenceCounter getConsumersRefCount() {
return refCountForConsumers;
}
@Override
public boolean isDurable() {
return propertyDurable;
}
@Override
public boolean isDurableMessage() {
return propertyDurable && !purgeOnNoConsumers;
}
@Override
public boolean isAutoDelete() {
return autoDelete;
}
@Override
public long getAutoDeleteDelay() {
return autoDeleteDelay;
}
@Override
public long getAutoDeleteMessageCount() {
return autoDeleteMessageCount;
}
@Override
public boolean isTemporary() {
return temporary;
}
@Override
public boolean isAutoCreated() {
return autoCreated;
}
@Override
public boolean isPurgeOnNoConsumers() {
return purgeOnNoConsumers;
}
@Override
public synchronized void setPurgeOnNoConsumers(boolean value) {
this.purgeOnNoConsumers = value;
}
@Override
public boolean isEnabled() {
return enabled;
}
@Override
public synchronized void setEnabled(boolean value) {
this.enabled = value;
}
@Override
public int getMaxConsumers() {
return maxConsumers;
}
@Override
public synchronized void setMaxConsumer(int maxConsumers) {
this.maxConsumers = maxConsumers;
}
@Override
public int getGroupBuckets() {
return groupBuckets;
}
@Override
public synchronized void setGroupBuckets(int groupBuckets) {
if (this.groupBuckets != groupBuckets) {
this.groups = groupMap(groupBuckets);
this.groupBuckets = groupBuckets;
}
}
@Override
public boolean isGroupRebalance() {
return groupRebalance;
}
@Override
public synchronized void setGroupRebalance(boolean groupRebalance) {
this.groupRebalance = groupRebalance;
}
@Override
public boolean isGroupRebalancePauseDispatch() {
return groupRebalancePauseDispatch;
}
@Override
public synchronized void setGroupRebalancePauseDispatch(boolean groupRebalancePauseDispatch) {
this.groupRebalancePauseDispatch = groupRebalancePauseDispatch;
}
@Override
public SimpleString getGroupFirstKey() {
return groupFirstKey;
}
@Override
public synchronized void setGroupFirstKey(SimpleString groupFirstKey) {
this.groupFirstKey = groupFirstKey;
}
@Override
public boolean isConfigurationManaged() {
return configurationManaged;
}
@Override
public synchronized void setConfigurationManaged(boolean configurationManaged) {
this.configurationManaged = configurationManaged;
}
@Override
public SimpleString getName() {
return name;
}
@Override
public SimpleString getAddress() {
return address;
}
@Override
public Long getID() {