This closes #509

This commit is contained in:
Clebert Suconic 2016-05-05 17:10:50 -04:00
commit 41d81d68ca
5 changed files with 69 additions and 8 deletions

View File

@ -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);
}
}
}

View File

@ -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.
*

View File

@ -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;
}

View File

@ -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<String, ServerSession> 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
*

View File

@ -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);