{
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())
{
queue.setExclusive(true);
}
else if(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("no-local"))
{
Object no_local = method.getArguments().get("no-local");
if(no_local instanceof Boolean && ((Boolean)no_local))
{
queue.setNoLocal(true);
}
}
}
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();
if (autoRegister)
{
ExchangeRegistry exchangeRegistry = getExchangeRegistry(session);
Exchange defaultExchange = exchangeRegistry.getDefaultExchange();
virtualHost.getBindingFactory().addBinding(queueName, queue, defaultExchange, null);
}
if(method.hasAutoDelete()
&& method.getAutoDelete()
&& method.hasExclusive()
&& method.getExclusive())
{
final AMQQueue q = queue;
final ServerSession.Task deleteQueueTask = new ServerSession.Task()
{
public void doTask(ServerSession session)
{
try
{
q.delete();
}
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);
}
});
}
else if(method.getExclusive())
{
final AMQQueue q = queue;
final ServerSession.Task removeExclusive = new ServerSession.Task()
{
public void doTask(ServerSession session)
{
q.setPrincipalHolder(null);
q.setExclusiveOwningSession(null);
}
};
final ServerSession s = (ServerSession) session;
s.addSessionCloseTask(removeExclusive);
queue.addQueueDeleteTask(new AMQQueue.Task()
{
public void doTask(AMQQueue queue) throws AMQException
{
s.removeSessionCloseTask(removeExclusive);
}
});
}
}
catch (AMQException e)
{
exception(session, method, e, "Cannot declare queue '" + queueName);
}
}
}
else if (method.getExclusive() && (queue.getPrincipalHolder() != null && !queue.getPrincipalHolder().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);
return;
}