@Override
public void messageReceived(final ChannelHandlerContext ctx, MessageEvent e) throws Exception {
super.messageReceived(ctx, e);
Channel channel = ctx.getChannel();
Object attribute = Channels.getAttribute(channel);
if (attribute instanceof Callback) {
Object message = e.getMessage();
Callback ac = (Callback) attribute;
if (message instanceof HttpChunk) {
if (HttpChunk.class.cast(message).isLast())
ac.call();
} else {
LOGGER.info("Received unexpected message while expecting a chunk: " + message);
ac.call();
Channels.setDiscard(channel);
}
} else if (attribute instanceof NettyResponseFuture<?>) {
NettyResponseFuture<?> future = (NettyResponseFuture<?>) attribute;
protocol.handle(channel, future, e.getMessage());
} else if (attribute != DiscardEvent.INSTANCE) {
LOGGER.debug("Orphan channel {} with attribute {} received message {}, closing", channel, attribute, e.getMessage());
Channels.silentlyCloseChannel(channel);
}
}