{
name = UUID.randomUUID().toString();
}
AMQQueue queue = _vhost.getQueue(name);
ExchangeImpl exchange = exchangeDestination.getExchange();
if(queue == null)
{
Map<String,Object> attributes = new HashMap<String,Object>();
attributes.put(Queue.ID, UUID.randomUUID());
attributes.put(Queue.NAME, name);
attributes.put(Queue.DURABLE, isDurable);
attributes.put(Queue.LIFETIME_POLICY, LifetimePolicy.DELETE_ON_NO_OUTBOUND_LINKS);
attributes.put(Queue.EXCLUSIVE, ExclusivityPolicy.LINK);
queue = _vhost.createQueue(attributes);
}
else
{
Collection<BindingImpl> bindings = queue.getBindings();
List<BindingImpl> bindingsToRemove = new ArrayList<BindingImpl>();
for(BindingImpl existingBinding : bindings)
{
if(existingBinding.getExchange() != exchange)
{
bindingsToRemove.add(existingBinding);
}
}
for(BindingImpl existingBinding : bindingsToRemove)
{
existingBinding.delete();
}
}
String binding = null;
Map<Symbol,Filter> filters = source.getFilter();
Map<Symbol,Filter> actualFilters = new HashMap<Symbol,Filter>();
boolean hasBindingFilter = false;
if(filters != null && !filters.isEmpty())
{
for(Map.Entry<Symbol,Filter> entry : filters.entrySet())
{
if(!hasBindingFilter
&& entry.getValue() instanceof ExactSubjectFilter
&& exchange.getType().equals(ExchangeDefaults.DIRECT_EXCHANGE_CLASS))
{
ExactSubjectFilter filter = (ExactSubjectFilter) filters.values().iterator().next();
source.setFilter(filters);
binding = filter.getValue();
actualFilters.put(entry.getKey(), entry.getValue());
hasBindingFilter = true;
}
else if(!hasBindingFilter
&& entry.getValue() instanceof MatchingSubjectFilter
&& exchange.getType().equals(ExchangeDefaults.TOPIC_EXCHANGE_CLASS))
{
MatchingSubjectFilter filter = (MatchingSubjectFilter) filters.values().iterator().next();
source.setFilter(filters);
binding = filter.getValue();
actualFilters.put(entry.getKey(), entry.getValue());
hasBindingFilter = true;
}
else if(entry.getValue() instanceof NoLocalFilter)
{
actualFilters.put(entry.getKey(), entry.getValue());
noLocal = true;
}
else if(messageFilter == null && entry.getValue() instanceof org.apache.qpid.amqp_1_0.type.messaging.JMSSelectorFilter)
{
org.apache.qpid.amqp_1_0.type.messaging.JMSSelectorFilter selectorFilter = (org.apache.qpid.amqp_1_0.type.messaging.JMSSelectorFilter) entry.getValue();
try
{
messageFilter = new JMSSelectorFilter(selectorFilter.getValue());
actualFilters.put(entry.getKey(), entry.getValue());
}
catch (ParseException e)
{
Error error = new Error();
error.setCondition(AmqpError.INVALID_FIELD);
error.setDescription("Invalid JMS Selector: " + selectorFilter.getValue());
error.setInfo(Collections.singletonMap(Symbol.valueOf("field"), Symbol.valueOf("filter")));
throw new AmqpErrorException(error);
}
catch (SelectorParsingException e)
{
Error error = new Error();
error.setCondition(AmqpError.INVALID_FIELD);
error.setDescription("Invalid JMS Selector: " + selectorFilter.getValue());
error.setInfo(Collections.singletonMap(Symbol.valueOf("field"), Symbol.valueOf("filter")));
throw new AmqpErrorException(error);
}
}
}
}
_queue = queue;
source.setFilter(actualFilters.isEmpty() ? null : actualFilters);
if(binding != null)
{
exchange.addBinding(binding, queue,null);
}
if(exchangeDestination.getInitialRoutingAddress() != null)
{
exchange.addBinding(exchangeDestination.getInitialRoutingAddress(),queue,null);
}
if(binding == null
&& exchangeDestination.getInitialRoutingAddress() == null
&& exchange.getType().equals(ExchangeDefaults.FANOUT_EXCHANGE_CLASS))
{
exchange.addBinding(queue.getName(), queue, null);
}
else if(binding == null
&& exchangeDestination.getInitialRoutingAddress() == null
&& exchange.getType().equals(ExchangeDefaults.TOPIC_EXCHANGE_CLASS))
{
exchange.addBinding("#", queue, null);
}
source.setDistributionMode(StdDistMode.COPY);
qd = new QueueDestination(queue);