"' for:" + body.getConsumerTag() +
" nowait:" + body.getNowait() +
" args:" + body.getArguments());
}
AMQQueue queue = body.getQueue() == null ? channel.getDefaultQueue() : vHost.getQueue(body.getQueue().intern().toString());
if (queue == null)
{
if (_logger.isDebugEnabled())
{
_logger.debug("No queue for '" + body.getQueue() + "'");
}
if (body.getQueue() != null)
{
String msg = "No such queue, '" + body.getQueue() + "'";
throw body.getChannelException(AMQConstant.NOT_FOUND, msg);
}
else
{
String msg = "No queue name provided, no default queue defined.";
throw body.getConnectionException(AMQConstant.NOT_ALLOWED, msg);
}
}
else
{
final AMQShortString consumerTagName;
if (queue.isExclusive() && !queue.isDurable())
{
AMQSessionModel session = queue.getExclusiveOwningSession();
if (session == null || session.getConnectionModel() != protocolConnection)
{
throw body.getConnectionException(AMQConstant.NOT_ALLOWED,
"Queue " + queue.getName() + " is exclusive, but not created on this Connection.");
}
}
if (body.getConsumerTag() != null)
{
consumerTagName = body.getConsumerTag().intern(false);
}
else
{
consumerTagName = null;
}
try
{
if(consumerTagName == null || channel.getSubscription(consumerTagName) == null)
{
AMQShortString consumerTag = channel.subscribeToQueue(consumerTagName, queue, !body.getNoAck(),
body.getArguments(), body.getNoLocal(), body.getExclusive());
if (!body.getNowait())
{
MethodRegistry methodRegistry = protocolConnection.getMethodRegistry();
AMQMethodBody responseBody = methodRegistry.createBasicConsumeOkBody(consumerTag);
protocolConnection.writeFrame(responseBody.generateFrame(channelId));
}
}
else
{
AMQShortString msg = new AMQShortString("Non-unique consumer tag, '" + body.getConsumerTag() + "'");
MethodRegistry methodRegistry = protocolConnection.getMethodRegistry();
AMQMethodBody responseBody = methodRegistry.createConnectionCloseBody(AMQConstant.NOT_ALLOWED.getCode(), // replyCode
msg, // replytext
body.getClazz(),
body.getMethod());
protocolConnection.writeFrame(responseBody.generateFrame(0));
}
}
catch (org.apache.qpid.AMQInvalidArgumentException ise)
{
_logger.debug("Closing connection due to invalid selector");
MethodRegistry methodRegistry = protocolConnection.getMethodRegistry();
AMQMethodBody responseBody = methodRegistry.createChannelCloseBody(AMQConstant.ARGUMENT_INVALID.getCode(),
new AMQShortString(ise.getMessage()),
body.getClazz(),
body.getMethod());
protocolConnection.writeFrame(responseBody.generateFrame(channelId));
}
catch (AMQQueue.ExistingExclusiveSubscription e)
{
throw body.getChannelException(AMQConstant.ACCESS_REFUSED,
"Cannot subscribe to queue "
+ queue.getName()
+ " as it already has an existing exclusive consumer");
}
catch (AMQQueue.ExistingSubscriptionPreventsExclusive e)
{
throw body.getChannelException(AMQConstant.ACCESS_REFUSED,
"Cannot subscribe to queue "
+ queue.getName()
+ " exclusively as it already has a consumer");
}
}
}