@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (!(msg instanceof RequestWithCallback)) { ctx.write(msg, promise); return; } Request request = ((RequestWithCallback)msg).request(); URI uri = request.getURI(); String scheme = uri.getScheme(); if (!scheme.equalsIgnoreCase(_scheme)) { // Specified scheme does not match the existing scheme for the pipeline. Returns channel back to the pool // and throws exception to the caller. ((RequestWithCallback)msg).handle().release(); throw new IllegalStateException( String.format("Cannot switch scheme from %s to %s for %s", _scheme, scheme, ctx.channel().remoteAddress())); } ctx.write(msg, promise); } }
@Override public void onError(Throwable cause) { resetStream(_ctx, _streamId, Http2Error.CANCEL.code(), _ctx.newPromise()); // Releases the handle to put the channel back to the pool _poolHandle.release(); }
((RequestWithCallback) msg).handle().release(); throw new IllegalArgumentException("Request is neither StreamRequest or RestRequest");