use of org.apache.qpid.server.model.NotFoundException in project qpid-broker-j by apache.
the class ExchangeSendingDestination method getQueue.
private static Queue<?> getQueue(Exchange<?> exchange, Source source, String subscriptionName, BindingInfo bindingInfo) throws AmqpErrorException {
boolean isDurable = source.getExpiryPolicy() == TerminusExpiryPolicy.NEVER;
boolean isShared = hasCapability(source.getCapabilities(), SHARED_CAPABILITY);
QueueManagingVirtualHost virtualHost;
if (exchange.getAddressSpace() instanceof QueueManagingVirtualHost) {
virtualHost = (QueueManagingVirtualHost) exchange.getAddressSpace();
} else {
throw new AmqpErrorException(new Error(AmqpError.INTERNAL_ERROR, "Address space of unexpected type"));
}
Queue<?> queue;
final Map<String, Object> attributes = new HashMap<>();
ExclusivityPolicy exclusivityPolicy;
if (isShared) {
exclusivityPolicy = ExclusivityPolicy.SHARED_SUBSCRIPTION;
} else {
exclusivityPolicy = ExclusivityPolicy.LINK;
}
org.apache.qpid.server.model.LifetimePolicy lifetimePolicy = getLifetimePolicy(source.getExpiryPolicy());
attributes.put(Queue.ID, UUID.randomUUID());
attributes.put(Queue.NAME, subscriptionName);
attributes.put(Queue.LIFETIME_POLICY, lifetimePolicy);
attributes.put(Queue.EXCLUSIVE, exclusivityPolicy);
attributes.put(Queue.DURABLE, isDurable);
Map<String, Map<String, Object>> bindings = bindingInfo.getBindings();
try {
queue = virtualHost.getSubscriptionQueue(exchange.getName(), attributes, bindings);
} catch (NotFoundException e) {
throw new AmqpErrorException(new Error(AmqpError.NOT_FOUND, e.getMessage()));
} catch (IllegalStateException e) {
throw new AmqpErrorException(new Error(AmqpError.RESOURCE_LOCKED, "Subscription is already in use"));
}
return queue;
}
use of org.apache.qpid.server.model.NotFoundException 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.model.NotFoundException in project qpid-broker-j by apache.
the class SendingLinkEndpoint method detach.
@Override
protected void detach(Error error, final boolean close) {
if (_consumerTarget != null) {
_consumerTarget.close();
}
Source source = getSource();
TerminusExpiryPolicy expiryPolicy = source.getExpiryPolicy();
NamedAddressSpace addressSpace = getSession().getConnection().getAddressSpace();
List<Symbol> sourceCapabilities = source.getCapabilities() == null ? Collections.emptyList() : Arrays.asList(source.getCapabilities());
if (close || TerminusExpiryPolicy.LINK_DETACH.equals(expiryPolicy) || ((expiryPolicy == null || TerminusExpiryPolicy.SESSION_END.equals(expiryPolicy)) && getSession().isClosing()) || (TerminusExpiryPolicy.CONNECTION_CLOSE.equals(expiryPolicy) && getSession().getConnection().isClosing())) {
cleanUpUnsettledDeliveries();
}
if (close) {
Error closingError = null;
if (getDestination() instanceof ExchangeSendingDestination && addressSpace instanceof QueueManagingVirtualHost && TerminusExpiryPolicy.NEVER.equals(expiryPolicy)) {
try {
((QueueManagingVirtualHost) addressSpace).removeSubscriptionQueue(((ExchangeSendingDestination) getDestination()).getQueue().getName());
TerminusDurability sourceDurability = source.getDurable();
if (sourceDurability != null && !TerminusDurability.NONE.equals(sourceDurability) && sourceCapabilities.contains(Session_1_0.SHARED_CAPABILITY) && sourceCapabilities.contains(ExchangeSendingDestination.TOPIC_CAPABILITY)) {
final Pattern containerIdPattern = sourceCapabilities.contains(Session_1_0.GLOBAL_CAPABILITY) ? ANY_CONTAINER_ID : Pattern.compile("^" + Pattern.quote(getSession().getConnection().getRemoteContainerId()) + "$");
final Pattern linkNamePattern = Pattern.compile("^" + Pattern.quote(getLinkName()) + "\\|?\\d*$");
addressSpace.visitSendingLinks((LinkRegistryModel.LinkVisitor<Link_1_0<Source, Target>>) link -> {
if (containerIdPattern.matcher(link.getRemoteContainerId()).matches() && linkNamePattern.matcher(link.getName()).matches()) {
link.linkClosed();
}
return false;
});
}
} catch (AccessControlException e) {
LOGGER.error("Error unregistering subscription", e);
closingError = new Error(AmqpError.NOT_ALLOWED, "Error unregistering subscription");
} catch (IllegalStateException e) {
String message;
if (sourceCapabilities.contains(Session_1_0.SHARED_CAPABILITY) && sourceCapabilities.contains(ExchangeSendingDestination.TOPIC_CAPABILITY)) {
String subscriptionName = getLinkName();
int separator = subscriptionName.indexOf("|");
if (separator > 0) {
subscriptionName = subscriptionName.substring(0, separator);
}
message = "There are active consumers on the shared subscription '" + subscriptionName + "'";
} else {
message = e.getMessage();
}
closingError = new Error(AmqpError.RESOURCE_LOCKED, message);
} catch (NotFoundException e) {
closingError = new Error(AmqpError.NOT_FOUND, e.getMessage());
}
}
if (error == null) {
error = closingError;
} else {
LOGGER.warn("Unexpected error on detaching endpoint {}: {}", getLinkName(), error);
}
} else if (addressSpace instanceof QueueManagingVirtualHost && ((QueueManagingVirtualHost) addressSpace).isDiscardGlobalSharedSubscriptionLinksOnDetach() && sourceCapabilities.contains(Session_1_0.SHARED_CAPABILITY) && sourceCapabilities.contains(Session_1_0.GLOBAL_CAPABILITY) && sourceCapabilities.contains(ExchangeSendingDestination.TOPIC_CAPABILITY) && !getLinkName().endsWith("|global")) {
// For JMS 2.0 global shared subscriptions we do not want to keep the links hanging around.
// However, we keep one link (ending with "|global") to perform a null-source lookup upon un-subscription.
getLink().linkClosed();
}
super.detach(error, close);
}
Aggregations