{
String queueName = method.getQueue();
VirtualHostImpl<?,?,?> vhost = getVirtualHost(session);
final Collection<MessageSource> sources = new HashSet<>();
final MessageSource queue = vhost.getMessageSource(queueName);
if(queue != null)
{
sources.add(queue);
}
else if(vhost.getContextValue(Boolean.class, "qpid.enableMultiQueueConsumers")
&& method.getArguments() != null
&& method.getArguments().get("x-multiqueue") instanceof Collection)
{
for(Object object : (Collection<Object>)method.getArguments().get("x-multiqueue"))
{
String sourceName = String.valueOf(object);
sourceName = sourceName.trim();
if(sourceName.length() != 0)
{
MessageSource source = vhost.getMessageSource(sourceName);
if(source == null)
{
sources.clear();
break;
}
else
{
sources.add(source);
}
}
}
queueName = method.getArguments().get("x-multiqueue").toString();
}
if(sources.isEmpty())
{
exception(session, method, ExecutionErrorCode.NOT_FOUND, "Queue: " + queueName + " not found");
}
else if(!verifySessionAccess((ServerSession) session, sources))
{
exception(session,method,ExecutionErrorCode.RESOURCE_LOCKED, "Exclusive Queue: " + queueName + " owned exclusively by another session");
}
else
{
FlowCreditManager_0_10 creditManager = new WindowCreditManager(0L,0L);
FilterManager filterManager = null;
try
{
filterManager = FilterManagerFactory.createManager(method.getArguments());
}
catch (AMQInvalidArgumentException amqe)
{
exception(session, method, ExecutionErrorCode.ILLEGAL_ARGUMENT, "Exception Creating FilterManager");
return;
}
ConsumerTarget_0_10 target = new ConsumerTarget_0_10((ServerSession)session, destination,
method.getAcceptMode(),
method.getAcquireMode(),
MessageFlowMode.WINDOW,
creditManager,
method.getArguments()
);
((ServerSession)session).register(destination, target);
try
{
EnumSet<ConsumerImpl.Option> options = EnumSet.noneOf(ConsumerImpl.Option.class);
if(method.getAcquireMode() == MessageAcquireMode.PRE_ACQUIRED)
{
options.add(ConsumerImpl.Option.ACQUIRES);
}
if(method.getAcquireMode() != MessageAcquireMode.NOT_ACQUIRED || method.getAcceptMode() == MessageAcceptMode.EXPLICIT)
{
options.add(ConsumerImpl.Option.SEES_REQUEUES);
}
if(method.getExclusive())
{
options.add(ConsumerImpl.Option.EXCLUSIVE);
}
for(MessageSource source : sources)
{
((ServerSession) session).register(
source.addConsumer(target,
filterManager,
MessageTransferMessage.class,
destination,
options));
}