use of org.apache.qpid.server.filter.AMQInvalidArgumentException in project qpid-broker-j by apache.
the class AbstractExchange method onOpen.
@Override
protected void onOpen() {
super.onOpen();
final ConfiguredDerivedMethodAttribute<Exchange<?>, Collection<Binding>> durableBindingsAttribute = (ConfiguredDerivedMethodAttribute<Exchange<?>, Collection<Binding>>) getModel().getTypeRegistry().getAttributeTypes(getTypeClass()).get(DURABLE_BINDINGS);
final Collection<Binding> bindings = durableBindingsAttribute.convertValue(getActualAttributes().get(DURABLE_BINDINGS), this);
if (bindings != null) {
_bindings.addAll(bindings);
for (Binding b : _bindings) {
final MessageDestination messageDestination = getOpenedMessageDestination(b.getDestination());
if (messageDestination != null) {
Map<String, Object> arguments = b.getArguments() == null ? Collections.emptyMap() : b.getArguments();
try {
onBind(new BindingIdentifier(b.getBindingKey(), messageDestination), arguments);
} catch (AMQInvalidArgumentException e) {
throw new IllegalConfigurationException("Unexpected bind argument : " + e.getMessage(), e);
}
messageDestination.linkAdded(this, b);
}
}
}
if (getLifetimePolicy() == LifetimePolicy.DELETE_ON_CREATING_LINK_CLOSE) {
if (_creatingLinkInfo != null) {
final LinkModel link;
if (_creatingLinkInfo.isSendingLink()) {
link = _virtualHost.getSendingLink(_creatingLinkInfo.getRemoteContainerId(), _creatingLinkInfo.getLinkName());
} else {
link = _virtualHost.getReceivingLink(_creatingLinkInfo.getRemoteContainerId(), _creatingLinkInfo.getLinkName());
}
addLifetimeConstraint(link);
} else {
throw new IllegalArgumentException("Exchanges created with a lifetime policy of " + getLifetimePolicy() + " must be created from a AMQP 1.0 link.");
}
}
if (getAlternateBinding() != null) {
String alternateDestination = getAlternateBinding().getDestination();
_alternateBindingDestination = getOpenedMessageDestination(alternateDestination);
if (_alternateBindingDestination != null) {
_alternateBindingDestination.addReference(this);
} else {
LOGGER.warn("Cannot find alternate binding destination '{}' for exchange '{}'", alternateDestination, toString());
}
}
}
use of org.apache.qpid.server.filter.AMQInvalidArgumentException in project qpid-broker-j by apache.
the class AbstractVirtualHost method getSubscriptionQueue.
@Override
@DoOnConfigThread
public Queue<?> getSubscriptionQueue(@Param(name = "exchangeName", mandatory = true) final String exchangeName, @Param(name = "attributes", mandatory = true) final Map<String, Object> attributes, @Param(name = "bindings", mandatory = true) final Map<String, Map<String, Object>> bindings) {
Queue queue;
Object exclusivityPolicy = attributes.get(Queue.EXCLUSIVE);
if (exclusivityPolicy == null) {
exclusivityPolicy = getContextValue(ExclusivityPolicy.class, Queue.QUEUE_DEFAULT_EXCLUSIVITY_POLICY);
}
if (!(exclusivityPolicy instanceof ExclusivityPolicy)) {
throw new IllegalArgumentException("Exclusivity policy is required");
}
Exchange<?> exchange = findConfiguredObject(Exchange.class, exchangeName);
if (exchange == null) {
throw new NotFoundException(String.format("Exchange '%s' was not found", exchangeName));
}
try {
queue = createMessageDestination(Queue.class, attributes);
for (String binding : bindings.keySet()) {
exchange.addBinding(binding, queue, bindings.get(binding));
}
} catch (AbstractConfiguredObject.DuplicateNameException e) {
Queue<?> existingQueue = (Queue) e.getExisting();
if (existingQueue.getExclusive() == exclusivityPolicy) {
if (hasDifferentBindings(exchange, existingQueue, bindings)) {
if (existingQueue.getConsumers().isEmpty()) {
existingQueue.delete();
queue = createMessageDestination(Queue.class, attributes);
for (String binding : bindings.keySet()) {
try {
exchange.addBinding(binding, queue, bindings.get(binding));
} catch (AMQInvalidArgumentException ia) {
throw new IllegalArgumentException("Unexpected bind argument : " + ia.getMessage(), ia);
}
}
} else {
throw new IllegalStateException("subscription already in use");
}
} else {
queue = existingQueue;
}
} else {
throw new IllegalStateException("subscription already in use");
}
} catch (AMQInvalidArgumentException e) {
throw new IllegalArgumentException("Unexpected bind argument : " + e.getMessage(), e);
}
return queue;
}
use of org.apache.qpid.server.filter.AMQInvalidArgumentException in project qpid-broker-j by apache.
the class AMQChannel method consumeFromSource.
/**
* Subscribe to a queue. We register all subscriptions in the channel so that if the channel is closed we can clean
* up all subscriptions, even if the client does not explicitly unsubscribe from all queues.
*
* @param tag the tag chosen by the client (if null, server will generate one)
* @param sources the queues to subscribe to
* @param acks Are acks enabled for this subscriber
* @param arguments Filters to apply to this subscriber
*
* @param exclusive Flag requesting exclusive access to the queue
* @return the consumer tag. This is returned to the subscriber and used in subsequent unsubscribe requests
*/
private AMQShortString consumeFromSource(AMQShortString tag, Collection<MessageSource> sources, boolean acks, FieldTable arguments, boolean exclusive, boolean noLocal) throws MessageSource.ExistingConsumerPreventsExclusive, MessageSource.ExistingExclusiveConsumer, AMQInvalidArgumentException, MessageSource.ConsumerAccessRefused, ConsumerTagInUseException, MessageSource.QueueDeleted {
if (tag == null) {
tag = AMQShortString.createAMQShortString("sgen_" + getNextConsumerTag());
}
if (_tag2SubscriptionTargetMap.containsKey(tag)) {
throw new ConsumerTagInUseException("Consumer already exists with same tag: " + tag);
}
ConsumerTarget_0_8 target;
EnumSet<ConsumerOption> options = EnumSet.noneOf(ConsumerOption.class);
final boolean multiQueue = sources.size() > 1;
if (arguments != null && Boolean.TRUE.equals(arguments.get(AMQPFilterTypes.NO_CONSUME.getValue()))) {
target = ConsumerTarget_0_8.createBrowserTarget(this, tag, arguments, INFINITE_CREDIT_CREDIT_MANAGER, multiQueue);
} else if (acks) {
target = ConsumerTarget_0_8.createAckTarget(this, tag, arguments, _creditManager, multiQueue);
options.add(ConsumerOption.ACQUIRES);
options.add(ConsumerOption.SEES_REQUEUES);
} else {
target = ConsumerTarget_0_8.createNoAckTarget(this, tag, arguments, INFINITE_CREDIT_CREDIT_MANAGER, multiQueue);
options.add(ConsumerOption.ACQUIRES);
options.add(ConsumerOption.SEES_REQUEUES);
}
if (exclusive) {
options.add(ConsumerOption.EXCLUSIVE);
}
// So to keep things straight we put before the call and catch all exceptions from the register and tidy up.
// We add before we register as the Async Delivery process may AutoClose the subscriber
// so calling _cT2QM.remove before we have done put which was after the register succeeded.
// So to keep things straight we put before the call and catch all exceptions from the register and tidy up.
_tag2SubscriptionTargetMap.put(tag, target);
try {
FilterManager filterManager = FilterManagerFactory.createManager(FieldTable.convertToMap(arguments));
if (noLocal) {
if (filterManager == null) {
filterManager = new FilterManager();
}
MessageFilter filter = new NoLocalFilter();
filterManager.add(filter.getName(), filter);
}
if (arguments != null && arguments.containsKey(AMQPFilterTypes.REPLAY_PERIOD.toString())) {
Object value = arguments.get(AMQPFilterTypes.REPLAY_PERIOD.toString());
final long period;
if (value instanceof Number) {
period = ((Number) value).longValue();
} else if (value instanceof String) {
try {
period = Long.parseLong(value.toString());
} catch (NumberFormatException e) {
throw new AMQInvalidArgumentException("Cannot parse value " + value + " as a number for filter " + AMQPFilterTypes.REPLAY_PERIOD.toString());
}
} else {
throw new AMQInvalidArgumentException("Cannot parse value " + value + " as a number for filter " + AMQPFilterTypes.REPLAY_PERIOD.toString());
}
final long startingFrom = System.currentTimeMillis() - (1000l * period);
if (filterManager == null) {
filterManager = new FilterManager();
}
MessageFilter filter = new ArrivalTimeFilter(startingFrom, period == 0);
filterManager.add(filter.getName(), filter);
}
Integer priority = null;
if (arguments != null && arguments.containsKey("x-priority")) {
Object value = arguments.get("x-priority");
if (value instanceof Number) {
priority = ((Number) value).intValue();
} else if (value instanceof String || value instanceof AMQShortString) {
try {
priority = Integer.parseInt(value.toString());
} catch (NumberFormatException e) {
// use default vlaue
}
}
}
for (MessageSource source : sources) {
source.addConsumer(target, filterManager, AMQMessage.class, AMQShortString.toString(tag), options, priority);
}
target.updateNotifyWorkDesired();
} catch (AccessControlException | MessageSource.ExistingExclusiveConsumer | MessageSource.ExistingConsumerPreventsExclusive | MessageSource.QueueDeleted | AMQInvalidArgumentException | MessageSource.ConsumerAccessRefused e) {
_tag2SubscriptionTargetMap.remove(tag);
throw e;
}
return tag;
}
Aggregations