@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (!(msg instanceof RequestWithCallback)) { ctx.write(msg, promise); return; } _alpnPromise.addListener(f -> { ChannelFuture future = (ChannelFuture) f; if (future.isSuccess()) { ctx.write(msg, promise); } else { // Releases the async pool handle @SuppressWarnings("unchecked") TimeoutAsyncPoolHandle<?> handle = ((RequestWithCallback<?, ?, TimeoutAsyncPoolHandle<?>>) msg).handle(); handle.dispose(); // Invokes user specified callback with error TransportCallback<?> callback = ((RequestWithCallback) msg).callback(); callback.onResponse(TransportResponseImpl.error(future.cause())); } }); }
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (!(msg instanceof RequestWithCallback)) { ctx.write(msg, promise); return; } _upgradePromise.addListener(f -> { ChannelFuture future = (ChannelFuture)f; if (future.isSuccess()) { ctx.write(msg, promise); } else { // Releases the async pool handle @SuppressWarnings("unchecked") TimeoutAsyncPoolHandle<?> handle = ((RequestWithCallback<?, ?, TimeoutAsyncPoolHandle<?>>) msg).handle(); handle.dispose(); // Invokes user specified callback with error TransportCallback<?> callback = ((RequestWithCallback) msg).callback(); callback.onResponse(TransportResponseImpl.error(future.cause())); } }); }