Github user sebthom commented on a diff in the pull request:

    https://github.com/apache/activemq-artemis/pull/2388#discussion_r227494586
  
    --- Diff: 
artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/PostOfficeImpl.java
 ---
    @@ -1540,6 +1561,75 @@ public void run() {
           }
        }
     
    +   private final class AddressQueueReaper extends 
ActiveMQScheduledComponent {
    +
    +      AddressQueueReaper(ScheduledExecutorService scheduledExecutorService,
    +                         Executor executor,
    +                         long checkPeriod,
    +                         TimeUnit timeUnit,
    +                         boolean onDemand) {
    +         super(scheduledExecutorService, executor, checkPeriod, timeUnit, 
onDemand);
    +      }
    +
    +      @Override
    +      public void run() {
    +         Map<SimpleString, Binding> nameMap = addressManager.getBindings();
    +
    +         List<Queue> queues = new ArrayList<>();
    +
    +         for (Binding binding : nameMap.values()) {
    +            if (binding.getType() == BindingType.LOCAL_QUEUE) {
    +               Queue queue = (Queue) binding.getBindable();
    +
    +               queues.add(queue);
    +            }
    +         }
    +
    +         for (Queue queue : queues) {
    +            int consumerCount = queue.getConsumerCount();
    +            long messageCount = queue.getMessageCount();
    +            boolean autoCreated = queue.isAutoCreated();
    +            long consumerRemovedTimestamp =  
queue.getConsumerRemovedTimestamp();
    +
    +            if (!queue.isInternalQueue() && autoCreated && messageCount == 
0 && consumerCount == 0 && consumerRemovedTimestamp != -1) {
    +               SimpleString queueName = queue.getName();
    +               AddressSettings settings = 
addressSettingsRepository.getMatch(queue.getAddress().toString());
    +               if (settings.isAutoDeleteQueues() && 
(System.currentTimeMillis() - consumerRemovedTimestamp >= 
settings.getAutoDeleteQueuesDelay())) {
    +                  if (ActiveMQServerLogger.LOGGER.isDebugEnabled()) {
    +                     ActiveMQServerLogger.LOGGER.info("deleting 
auto-created queue \"" + queueName + ".\" consumerCount = " + consumerCount + 
"; messageCount = " + messageCount + "; isAutoDeleteQueues = " + 
settings.isAutoDeleteQueues());
    +                  }
    +
    +                  try {
    +                     server.destroyQueue(queueName, null, true, false);
    --- End diff --
    
    What happens if a message was added to the queue in the time between 
queue.getMessageCount() was invoked and server.destroyQueue() is executed. 
Maybe ActiveMQServer.destroyQueue() needs to be extended by a 
"checkMessageCount" parameter?


---

Reply via email to