public void methodReceived(AMQStateManager stateManager, QueueDeclareBody body, int channelId) throws AMQException
{
final AMQProtocolSession protocolConnection = stateManager.getProtocolSession();
final AMQSessionModel session = protocolConnection.getChannel(channelId);
VirtualHost virtualHost = protocolConnection.getVirtualHost();
ExchangeRegistry exchangeRegistry = virtualHost.getExchangeRegistry();
QueueRegistry queueRegistry = virtualHost.getQueueRegistry();
DurableConfigurationStore store = virtualHost.getMessageStore();
final AMQShortString queueName;
// if we aren't given a queue name, we create one which we return to the client
if ((body.getQueue() == null) || (body.getQueue().length() == 0))
{
queueName = createName();
}
else
{
queueName = body.getQueue().intern();
}
AMQQueue queue;
//TODO: do we need to check that the queue already exists with exactly the same "configuration"?
AMQChannel channel = protocolConnection.getChannel(channelId);
if (channel == null)
{
throw body.getChannelNotFoundException(channelId);
}
synchronized (queueRegistry)
{
queue = queueRegistry.getQueue(queueName);
AMQSessionModel owningSession = null;
if (queue != null)
{
owningSession = queue.getExclusiveOwningSession();
}
if (queue == null)
{
if (body.getPassive())
{
String msg = "Queue: " + queueName + " not found on VirtualHost(" + virtualHost + ").";
throw body.getChannelException(AMQConstant.NOT_FOUND, msg);
}
else
{
queue = createQueue(queueName, body, virtualHost, protocolConnection);
queue.setAuthorizationHolder(protocolConnection);
if (queue.isDurable() && !queue.isAutoDelete())
{
store.createQueue(queue, body.getArguments());
}
if(body.getAutoDelete())
{
queue.setDeleteOnNoConsumers(true);
}
queueRegistry.registerQueue(queue);
if (body.getExclusive())
{
queue.setExclusiveOwningSession(protocolConnection.getChannel(channelId));
queue.setAuthorizationHolder(protocolConnection);
if(!body.getDurable())
{
final AMQQueue q = queue;
final AMQProtocolSession.Task sessionCloseTask = new AMQProtocolSession.Task()
{
public void doTask(AMQProtocolSession session) throws AMQException
{
q.setExclusiveOwningSession(null);
}
};
protocolConnection.addSessionCloseTask(sessionCloseTask);
queue.addQueueDeleteTask(new AMQQueue.Task() {
public void doTask(AMQQueue queue) throws AMQException
{
protocolConnection.removeSessionCloseTask(sessionCloseTask);
}
});
}
}
if (autoRegister)
{
Exchange defaultExchange = exchangeRegistry.getDefaultExchange();
virtualHost.getBindingFactory().addBinding(String.valueOf(queueName), queue, defaultExchange, Collections.EMPTY_MAP);
_logger.info("Queue " + queueName + " bound to default exchange(" + defaultExchange.getNameShortString() + ")");
}
}
}
else if (queue.isExclusive() && !queue.isDurable() && (owningSession == null || owningSession.getConnectionModel() != protocolConnection))