@Override
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
if (requestSender.isClosed())
return;
Channel channel = ctx.getChannel();
channelManager.removeAll(channel);
try {
super.channelClosed(ctx, e);
} catch (Exception ex) {
LOGGER.trace("super.channelClosed", ex);
}
Object attribute = Channels.getAttribute(channel);
LOGGER.debug("Channel Closed: {} with attribute {}", channel, attribute);
if (attribute instanceof Callback) {
Callback callback = (Callback) attribute;
Channels.setAttribute(channel, callback.future());
callback.call();
} else if (attribute instanceof NettyResponseFuture<?>) {
NettyResponseFuture<?> future = (NettyResponseFuture<?>) attribute;
future.touch();
if (!config.getIOExceptionFilters().isEmpty()
&& requestSender.applyIoExceptionFiltersAndReplayRequest(future, CHANNEL_CLOSED_EXCEPTION, channel))
return;
protocol.onClose(channel);
if (future == null || future.isDone())
channelManager.closeChannel(channel);
else if (!requestSender.retry(future, ctx.getChannel()))
requestSender.abort(future, REMOTELY_CLOSED_EXCEPTION);
}
}