From 5c7aaa760a9c959ad8d512509d7d63455e7efe56 Mon Sep 17 00:00:00 2001 From: jbertram Date: Thu, 5 May 2016 10:37:28 -0500 Subject: [PATCH] Auto-delete JMS, not just core --- .../jms/server/impl/JMSServerManagerImpl.java | 17 +++++++---- .../artemis/core/server/ActiveMQServer.java | 14 +++++++++- .../artemis/core/server/QueueDeleter.java | 28 +++++++++++++++++++ .../core/server/impl/ActiveMQServerImpl.java | 16 +++++++++++ .../impl/AutoCreatedQueueManagerImpl.java | 2 +- 5 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 artemis-server/src/main/java/org/apache/activemq/artemis/core/server/QueueDeleter.java diff --git a/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/server/impl/JMSServerManagerImpl.java b/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/server/impl/JMSServerManagerImpl.java index c9a16179ff..51817315c1 100644 --- a/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/server/impl/JMSServerManagerImpl.java +++ b/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/server/impl/JMSServerManagerImpl.java @@ -50,6 +50,7 @@ import org.apache.activemq.artemis.core.server.ActivateCallback; import org.apache.activemq.artemis.core.server.ActiveMQServer; import org.apache.activemq.artemis.core.server.Queue; import org.apache.activemq.artemis.core.server.QueueCreator; +import org.apache.activemq.artemis.core.server.QueueDeleter; import org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl; import org.apache.activemq.artemis.core.server.management.Notification; import org.apache.activemq.artemis.core.settings.impl.AddressSettings; @@ -372,6 +373,8 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback server.setJMSQueueCreator(new JMSQueueCreator()); + server.setJMSQueueDeleter(new JMSQueueDeleter()); + server.registerActivateCallback(this); /** * See this method's javadoc. @@ -1617,15 +1620,11 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback } class JMSQueueCreator implements QueueCreator { - - private final SimpleString PREFIX = SimpleString.toSimpleString("jms.queue"); - @Override public boolean create(SimpleString address) throws Exception { AddressSettings settings = server.getAddressSettingsRepository().getMatch(address.toString()); - if (address.startsWith(PREFIX) && settings.isAutoCreateJmsQueues()) { - // stopped here... finish here - JMSServerManagerImpl.this.internalCreateJMSQueue(false, address.toString().substring(PREFIX.toString().length() + 1), null, true, true); + if (address.toString().startsWith(ActiveMQDestination.JMS_QUEUE_ADDRESS_PREFIX) && settings.isAutoCreateJmsQueues()) { + JMSServerManagerImpl.this.internalCreateJMSQueue(false, address.toString().substring(ActiveMQDestination.JMS_QUEUE_ADDRESS_PREFIX.length()), null, true, true); return true; } else { @@ -1634,4 +1633,10 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback } } + class JMSQueueDeleter implements QueueDeleter { + @Override + public boolean delete(SimpleString address) throws Exception { + return JMSServerManagerImpl.this.destroyQueue(address.toString().substring(ActiveMQDestination.JMS_QUEUE_ADDRESS_PREFIX.length()), false); + } + } } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java index 3719453553..0c6fe11ac6 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java @@ -187,7 +187,7 @@ public interface ActiveMQServer extends ActiveMQComponent { long getUptimeMillis(); /** - * This is the queue creator responsible for JMS Queue creations* + * This is the queue creator responsible for automatic JMS Queue creations. * * @param queueCreator */ @@ -198,6 +198,18 @@ public interface ActiveMQServer extends ActiveMQComponent { */ QueueCreator getJMSQueueCreator(); + /** + * This is the queue deleter responsible for automatic JMS Queue deletions. + * + * @param queueDeleter + */ + void setJMSQueueDeleter(QueueDeleter queueDeleter); + + /** + * @see org.apache.activemq.artemis.core.server.ActiveMQServer#setJMSQueueDeleter(QueueDeleter) + */ + QueueDeleter getJMSQueueDeleter(); + /** * Wait for server initialization. * diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/QueueDeleter.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/QueueDeleter.java new file mode 100644 index 0000000000..4bdb8a41f0 --- /dev/null +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/QueueDeleter.java @@ -0,0 +1,28 @@ +/* + * 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; + +import org.apache.activemq.artemis.api.core.SimpleString; + +public interface QueueDeleter { + + /** + * @return True if a queue was deleted. + */ + boolean delete(SimpleString address) throws Exception; +} diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java index 40a7b6c2fb..641ceddb09 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java @@ -108,6 +108,7 @@ import org.apache.activemq.artemis.core.server.MemoryManager; import org.apache.activemq.artemis.core.server.NodeManager; import org.apache.activemq.artemis.core.server.Queue; import org.apache.activemq.artemis.core.server.QueueCreator; +import org.apache.activemq.artemis.core.server.QueueDeleter; import org.apache.activemq.artemis.core.server.QueueFactory; import org.apache.activemq.artemis.core.server.QueueQueryResult; import org.apache.activemq.artemis.core.server.SecuritySettingPlugin; @@ -243,6 +244,11 @@ public class ActiveMQServerImpl implements ActiveMQServer { */ private QueueCreator jmsQueueCreator; + /** + * This will be set by the JMS Queue Manager. + */ + private QueueDeleter jmsQueueDeleter; + private final Map sessions = new ConcurrentHashMap<>(); /** @@ -658,6 +664,16 @@ public class ActiveMQServerImpl implements ActiveMQServer { this.jmsQueueCreator = jmsQueueCreator; } + @Override + public QueueDeleter getJMSQueueDeleter() { + return jmsQueueDeleter; + } + + @Override + public void setJMSQueueDeleter(QueueDeleter jmsQueueDeleter) { + this.jmsQueueDeleter = jmsQueueDeleter; + } + /** * Stops the server * diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AutoCreatedQueueManagerImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AutoCreatedQueueManagerImpl.java index 9895a30bad..25fc60a015 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AutoCreatedQueueManagerImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AutoCreatedQueueManagerImpl.java @@ -46,7 +46,7 @@ public class AutoCreatedQueueManagerImpl implements AutoCreatedQueueManager { logger.debug("deleting auto-created queue \"" + queueName + ".\" consumerCount = " + consumerCount + "; messageCount = " + messageCount + "; isAutoDeleteJmsQueues = " + isAutoDeleteJmsQueues); } - server.destroyQueue(queueName, null, false); + server.getJMSQueueDeleter().delete(queueName); } else if (logger.isDebugEnabled()) { logger.debug("NOT deleting auto-created queue \"" + queueName + ".\" consumerCount = " + consumerCount + "; messageCount = " + messageCount + "; isAutoDeleteJmsQueues = " + isAutoDeleteJmsQueues);