@Override
public void queueDeclare(Session session, final QueueDeclare method)
{
VirtualHost virtualHost = getVirtualHost(session);
DurableConfigurationStore store = virtualHost.getMessageStore();
String queueName = method.getQueue();
AMQQueue queue;
QueueRegistry queueRegistry = getQueueRegistry(session);
//TODO: do we need to check that the queue already exists with exactly the same "configuration"?
synchronized (queueRegistry)
{
if (((queue = queueRegistry.getQueue(queueName)) == null))
{
if (method.getPassive())
{
String description = "Queue: " + queueName + " not found on VirtualHost(" + virtualHost + ").";
ExecutionErrorCode errorCode = ExecutionErrorCode.NOT_FOUND;
exception(session, method, errorCode, description);
return;
}
else
{
try
{
queue = createQueue(queueName, method, virtualHost, (ServerSession)session);
if(!method.getExclusive() && method.getAutoDelete())
{
queue.setDeleteOnNoConsumers(true);
}
final String alternateExchangeName = method.getAlternateExchange();
if(alternateExchangeName != null && alternateExchangeName.length() != 0)
{
Exchange alternate = getExchange(session, alternateExchangeName);
queue.setAlternateExchange(alternate);
}
if(method.hasArguments() && method.getArguments() != null)
{
if(method.getArguments().containsKey(QUEUE_ARGUMENT_NO_LOCAL))
{
Object noLocal = method.getArguments().get(QUEUE_ARGUMENT_NO_LOCAL);
queue.setNoLocal(convertBooleanValue(noLocal));
}
}
if (queue.isDurable() && !queue.isAutoDelete())
{
if(method.hasArguments() && method.getArguments() != null)
{
Map<String,Object> args = method.getArguments();
FieldTable ftArgs = new FieldTable();
for(Map.Entry<String, Object> entry : args.entrySet())
{
ftArgs.put(new AMQShortString(entry.getKey()), entry.getValue());
}
store.createQueue(queue, ftArgs);
}
else
{
store.createQueue(queue);
}
}
queueRegistry.registerQueue(queue);
boolean autoRegister = ApplicationRegistry.getInstance().getConfiguration().getQueueAutoRegister();