Search in sources :

Example 1 with RequiredExchangeException

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());
                }
            }
        }
    }
}
Also used : NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) MessageDestinationIsAlternateException(org.apache.qpid.server.virtualhost.MessageDestinationIsAlternateException) AccessControlException(java.security.AccessControlException) RequiredExchangeException(org.apache.qpid.server.virtualhost.RequiredExchangeException)

Aggregations

AccessControlException (java.security.AccessControlException)1 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)1 MessageDestinationIsAlternateException (org.apache.qpid.server.virtualhost.MessageDestinationIsAlternateException)1 RequiredExchangeException (org.apache.qpid.server.virtualhost.RequiredExchangeException)1