Configurator.configure(this);
}
public void methodReceived(AMQStateManager stateManager, QueueDeclareBody body, int channelId) throws AMQException
{
AMQProtocolSession session = stateManager.getProtocolSession();
VirtualHost virtualHost = session.getVirtualHost();
ExchangeRegistry exchangeRegistry = virtualHost.getExchangeRegistry();
QueueRegistry queueRegistry = virtualHost.getQueueRegistry();
MessageStore store = virtualHost.getMessageStore();
if (!body.getPassive())
{
//Perform ACL if request is not passive
virtualHost.getAccessManager().authorise(session, Permission.CREATE, body);
}
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"?
synchronized (queueRegistry)
{
if (((queue = queueRegistry.getQueue(queueName)) == 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, session);
if (queue.isDurable() && !queue.isAutoDelete())
{
store.createQueue(queue, body.getArguments());
}
queueRegistry.registerQueue(queue);
if (autoRegister)
{
Exchange defaultExchange = exchangeRegistry.getDefaultExchange();
queue.bind(defaultExchange, queueName, null);
_logger.info("Queue " + queueName + " bound to default exchange(" + defaultExchange.getName() + ")");
}
}
}
else if (queue.getOwner() != null && !session.getContextKey().equals(queue.getOwner()))
{
throw body.getChannelException(AMQConstant.ALREADY_EXISTS, "Cannot declare queue('" + queueName + "'),"
+ " as exclusive queue with same name "
+ "declared on another client ID('"
+ queue.getOwner() + "')");
}
AMQChannel channel = session.getChannel(channelId);
if (channel == null)
{
throw body.getChannelNotFoundException(channelId);
}
//set this as the default queue on the channel:
channel.setDefaultQueue(queue);
}
if (!body.getNowait())
{
MethodRegistry methodRegistry = session.getMethodRegistry();
QueueDeclareOkBody responseBody =
methodRegistry.createQueueDeclareOkBody(queueName,
queue.getMessageCount(),
queue.getConsumerCount());
session.writeFrame(responseBody.generateFrame(channelId));
_logger.info("Queue " + queueName + " declared successfully");
}
}