AMQProtocolSession session = stateManager.getProtocolSession();
VirtualHost virtualHost = session.getVirtualHost();
ExchangeRegistry exchangeRegistry = virtualHost.getExchangeRegistry();
ExchangeFactory exchangeFactory = virtualHost.getExchangeFactory();
final ExchangeDeclareBody body = evt.getMethod();
if (_logger.isDebugEnabled())
{
_logger.debug("Request to declare exchange of type " + body.type + " with name " + body.exchange);
}
synchronized(exchangeRegistry)
{
Exchange exchange = exchangeRegistry.getExchange(body.exchange);
if (exchange == null)
{
if(body.passive && ((body.type == null) || body.type.length() ==0))
{
throw body.getChannelException(AMQConstant.NOT_FOUND, "Unknown exchange: " + body.exchange);
}
else
{
try
{
exchange = exchangeFactory.createExchange(body.exchange == null ? null : body.exchange.intern(),
body.type == null ? null : body.type.intern(),
body.durable,
body.passive, body.ticket);
exchangeRegistry.registerExchange(exchange);
}
catch(AMQUnknownExchangeType e)
{
throw body.getConnectionException(AMQConstant.COMMAND_INVALID, "Unknown exchange: " + body.exchange,e);
}
}
}
else if (!exchange.getType().equals(body.type))
{
throw new AMQConnectionException(AMQConstant.NOT_ALLOWED, "Attempt to redeclare exchange: " + body.exchange + " of type " + exchange.getType() + " to " + body.type +".",body.getClazz(), body.getMethod(),body.getMajor(),body.getMinor());
}
}
if(!body.nowait)
{