use of org.apache.qpid.server.virtualhost.RequiredExchangeException in project qpid-broker-j by apache.
the class AMQChannel method receiveExchangeDelete.
@Override
public void receiveExchangeDelete(final AMQShortString exchangeStr, final boolean ifUnused, final boolean nowait) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("RECV[" + _channelId + "] ExchangeDelete[" + " exchange: " + exchangeStr + " ifUnused: " + ifUnused + " nowait: " + nowait + " ]");
}
NamedAddressSpace virtualHost = _connection.getAddressSpace();
sync();
if (isDefaultExchange(exchangeStr)) {
_connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Default Exchange cannot be deleted", getChannelId());
} else {
final String exchangeName = exchangeStr.toString();
final Exchange<?> exchange = getExchange(exchangeName);
if (exchange == null) {
closeChannel(ErrorCodes.NOT_FOUND, "No such exchange: '" + exchangeStr + "'");
} else {
if (ifUnused && exchange.hasBindings()) {
closeChannel(ErrorCodes.IN_USE, "Exchange has bindings");
} else {
try {
exchange.delete();
if (!nowait) {
ExchangeDeleteOkBody responseBody = _connection.getMethodRegistry().createExchangeDeleteOkBody();
_connection.writeFrame(responseBody.generateFrame(getChannelId()));
}
} catch (MessageDestinationIsAlternateException e) {
closeChannel(ErrorCodes.NOT_ALLOWED, "Exchange in use as an alternate binding destination");
} catch (RequiredExchangeException e) {
closeChannel(ErrorCodes.NOT_ALLOWED, "Exchange '" + exchangeStr + "' cannot be deleted");
} catch (AccessControlException e) {
_connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, e.getMessage(), getChannelId());
}
}
}
}
}
Aggregations