From dev-return-67749-archive-asf-public=cust-asf.ponee.io@activemq.apache.org Wed Oct 24 02:26:46 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 1571D18066B for ; Wed, 24 Oct 2018 02:26:45 +0200 (CEST) Received: (qmail 38480 invoked by uid 500); 24 Oct 2018 00:26:45 -0000 Mailing-List: contact dev-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list dev@activemq.apache.org Received: (qmail 38468 invoked by uid 99); 24 Oct 2018 00:26:44 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 24 Oct 2018 00:26:44 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id F3372DFC65; Wed, 24 Oct 2018 00:26:43 +0000 (UTC) From: jbertram To: dev@activemq.apache.org Reply-To: dev@activemq.apache.org References: In-Reply-To: Subject: [GitHub] activemq-artemis pull request #2388: ARTEMIS-1856 support delays before dele... Content-Type: text/plain Message-Id: <20181024002643.F3372DFC65@git1-us-west.apache.org> Date: Wed, 24 Oct 2018 00:26:43 +0000 (UTC) Github user jbertram commented on a diff in the pull request: https://github.com/apache/activemq-artemis/pull/2388#discussion_r227609075 --- 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 nameMap = addressManager.getBindings(); + + List 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 -- @michaelandrepearce is right, but I think it's worth mitigating the risk within the bounds of the current locking scheme. What I don't want to do is introduce additional locking or synchronization. ---