@Override
public void queueDeclare(Session session, final QueueDeclare method)
{
final VirtualHostImpl 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 (!queue.verifySessionAccess((ServerSession)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
{
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 = UUID.randomUUID();
arguments.put(Queue.ID, id);
arguments.put(Queue.NAME, queueName);
LifetimePolicy lifetime;
if(autoDelete)
{
lifetime = exclusive ? LifetimePolicy.DELETE_ON_SESSION_END
: LifetimePolicy.DELETE_ON_NO_OUTBOUND_LINKS;
}
else
{
lifetime = LifetimePolicy.PERMANENT;
}
arguments.put(Queue.LIFETIME_POLICY, lifetime);
ExclusivityPolicy exclusivityPolicy = exclusive ? ExclusivityPolicy.SESSION : ExclusivityPolicy.NONE;
arguments.put(Queue.DURABLE, method.getDurable());
arguments.put(Queue.EXCLUSIVE, exclusivityPolicy);
queue = virtualHost.createQueue(arguments);
}
catch(QueueExistsException qe)
{
queue = qe.getExistingQueue();