final VirtualHost virtualHost = getVirtualHost(session);
DurableConfigurationStore store = virtualHost.getDurableConfigurationStore();
String queueName = method.getQueue();
AMQQueue queue;
//TODO: do we need to check that the queue already exists with exactly the same "configuration"?
final boolean exclusive = method.getExclusive();
final boolean autoDelete = method.getAutoDelete();
if(method.getPassive())
{
queue = virtualHost.getQueue(queueName);
if (queue == null)
{
String description = "Queue: " + queueName + " not found on VirtualHost(" + virtualHost + ").";
ExecutionErrorCode errorCode = ExecutionErrorCode.NOT_FOUND;
exception(session, method, errorCode, description);
}
else if (exclusive && (queue.getExclusiveOwningSession() != null && !queue.getExclusiveOwningSession().equals(session)))
{
String description = "Cannot declare queue('" + queueName + "'),"
+ " as exclusive queue with same name "
+ "declared on another session";
ExecutionErrorCode errorCode = ExecutionErrorCode.RESOURCE_LOCKED;
exception(session, method, errorCode, description);
}
}
else
{
try
{
String owner = method.getExclusive() ? ((ServerSession)session).getClientID() : null;
final String alternateExchangeName = method.getAlternateExchange();
final Map<String, Object> arguments = QueueArgumentsConverter.convertWireArgsToModel(method.getArguments());
if(alternateExchangeName != null && alternateExchangeName.length() != 0)
{
arguments.put(Queue.ALTERNATE_EXCHANGE, alternateExchangeName);
}
final UUID id = UUIDGenerator.generateQueueUUID(queueName, virtualHost.getName());
final boolean deleteOnNoConsumer = !exclusive && autoDelete;
queue = virtualHost.createQueue(id, queueName, method.getDurable(), owner,
autoDelete, exclusive, deleteOnNoConsumer,
arguments);
if (autoDelete && exclusive)
{
final AMQQueue q = queue;
final ServerSession.Task deleteQueueTask = new ServerSession.Task()
{
public void doTask(ServerSession session)
{
try
{
virtualHost.removeQueue(q);
}
catch (AMQException e)
{
exception(session, method, e, "Cannot delete '" + method.getQueue());
}
}
};
final ServerSession s = (ServerSession) session;
s.addSessionCloseTask(deleteQueueTask);
queue.addQueueDeleteTask(new AMQQueue.Task()
{
public void doTask(AMQQueue queue) throws AMQException
{
s.removeSessionCloseTask(deleteQueueTask);
}
});
}
if (exclusive)
{
final AMQQueue q = queue;
final ServerSession.Task removeExclusive = new ServerSession.Task()
{
public void doTask(ServerSession session)
{
q.setAuthorizationHolder(null);
q.setExclusiveOwningSession(null);
}
};
final ServerSession s = (ServerSession) session;
q.setExclusiveOwningSession(s);
s.addSessionCloseTask(removeExclusive);
queue.addQueueDeleteTask(new AMQQueue.Task()
{
public void doTask(AMQQueue queue) throws AMQException
{