@Override public ChannelConfig setAutoRead(boolean autoRead) { boolean oldAutoRead = AUTOREAD_UPDATER.getAndSet(this, autoRead ? 1 : 0) == 1; if (autoRead && !oldAutoRead) { channel.read(); } else if (!autoRead && oldAutoRead) { autoReadCleared(); } return this; }
private void readIfIsAutoRead() { if (channel.config().isAutoRead()) { channel.read(); } }
@Override public void operationComplete(ChannelFuture future) { if (future.isSuccess()) { ctx.channel().read(); } else { if (isNotSocketClosedException(future.cause())) { mockServerLogger.error("Exception while returning writing " + response, future.cause()); } future.channel().close(); } } });
private void readIfIsAutoRead() { if (channel.config().isAutoRead()) { channel.read(); } }
@Override public ChannelConfig setAutoRead(boolean autoRead) { boolean oldAutoRead = AUTOREAD_UPDATER.getAndSet(this, autoRead ? 1 : 0) == 1; if (autoRead && !oldAutoRead) { channel.read(); } else if (!autoRead && oldAutoRead) { autoReadCleared(); } return this; }
@Override public void operationComplete(ChannelFuture future) { if (future.isSuccess()) { ctx.channel().read(); } else { if (isNotSocketClosedException(future.cause())) { mockServerLogger.error("Exception while returning response for request \"" + request.method() + " " + request.uri() + "\"", future.cause()); } future.channel().close(); } } });
@Override public void channelReadComplete(ChannelHandlerContext ctx) { ctx.flush(); if (requestContext == null) { // there was no publisher associated with this connection // this happens in case there was no http request made on this connection return; } if (requestContext.publisher().tryAcquire() > 0) { ctx.channel().read(); } }
private void readIfIsAutoRead() { if (channel.config().isAutoRead()) { channel.read(); } }
@Override public ChannelConfig setAutoRead(boolean autoRead) { boolean oldAutoRead = AUTOREAD_UPDATER.getAndSet(this, autoRead ? 1 : 0) == 1; if (autoRead && !oldAutoRead) { channel.read(); } else if (!autoRead && oldAutoRead) { autoReadCleared(); } return this; }
@Override public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof HttpResponse) { if (edgeProxy != null) { edgeProxy.responseFromOrigin((HttpResponse) msg); } ctx.channel().read(); } else if (msg instanceof HttpContent) { final HttpContent chunk = (HttpContent) msg; if (edgeProxy != null) { edgeProxy.invokeNext(chunk); } else { chunk.release(); } ctx.channel().read(); } else { //should never happen ReferenceCountUtil.release(msg); final Exception error = new IllegalStateException("Received invalid message from origin"); if (edgeProxy != null) { edgeProxy.errorFromOrigin(error); } ctx.fireExceptionCaught(error); } }
@Override public void run() { nettyCnxn.getChannel().read(); } }, 1, TimeUnit.SECONDS);
private void closeChannel(Channel channel, FlowableEmitter<?> emitter, ChannelFuture channelFuture) { channelFuture.addListener(f -> { try { if (!f.isSuccess()) { emitter.onError(f.cause()); } else { channel.read(); } } finally { if (encoder != null) { encoder.cleanFiles(); } closeChannelAsync(channel); } }); }
protected void createConnection(ChannelFuture cf, Promise<PooledConnection> callerPromise, String httpMethod, String uri, int attemptNum, CurrentPassport passport) { final PooledConnection conn = pooledConnectionFactory.create(cf.channel()); conn.incrementUsageCount(); conn.startRequestTimer(); conn.getChannel().read(); onAcquire(conn, httpMethod, uri, attemptNum, passport); callerPromise.setSuccess(conn); }
/** * Enables auto read for a netty channel. * * @param channel the netty channel */ public static void enableAutoRead(Channel channel) { if (!channel.config().isAutoRead()) { channel.config().setAutoRead(true); channel.read(); } }
@Override public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof HttpResponse) { if (edgeProxy != null) { edgeProxy.responseFromOrigin((HttpResponse) msg); } ctx.channel().read(); } else if (msg instanceof HttpContent) { final HttpContent chunk = (HttpContent) msg; if (edgeProxy != null) { edgeProxy.invokeNext(chunk); } else { chunk.release(); } ctx.channel().read(); } else { //should never happen ReferenceCountUtil.release(msg); final Exception error = new IllegalStateException("Received invalid message from origin"); if (edgeProxy != null) { edgeProxy.errorFromOrigin(error); } ctx.fireExceptionCaught(error); } }
private void writeClientRequestToOrigin(final PooledConnection conn) { final Channel ch = conn.getChannel(); passport.setOnChannel(ch); context.set(ORIGIN_CHANNEL, ch); context.set(POOLED_ORIGIN_CONNECTION_KEY, conn); preWriteToOrigin(chosenServer.get(), zuulRequest); final ChannelPipeline pipeline = ch.pipeline(); originResponseReceiver = getOriginResponseReceiver(); pipeline.addBefore("connectionPoolHandler", OriginResponseReceiver.CHANNEL_HANDLER_NAME, originResponseReceiver); // check if body needs to be repopulated for retry repopulateRetryBody(); ch.write(zuulRequest); writeBufferedBodyContent(zuulRequest, ch); ch.flush(); //Get ready to read origin's response ch.read(); originConn = conn; channelCtx.read(); }
protected void createConnection(ChannelFuture cf, Promise<PooledConnection> callerPromise, String httpMethod, String uri, int attemptNum, CurrentPassport passport) { final PooledConnection conn = pooledConnectionFactory.create(cf.channel()); conn.incrementUsageCount(); conn.startRequestTimer(); conn.getChannel().read(); onAcquire(conn, httpMethod, uri, attemptNum, passport); callerPromise.setSuccess(conn); }
@Override public Promise<PooledConnection> acquire(EventLoop eventLoop, Object key, String httpMethod, String uri, int attemptNum, CurrentPassport passport, AtomicReference<String> selectedHostAddr) { requestConnCounter.increment(); stats.incrementActiveRequestsCount(); Promise<PooledConnection> promise = eventLoop.newPromise(); // Try getting a connection from the pool. final PooledConnection conn = tryGettingFromConnectionPool(eventLoop); if (conn != null) { // There was a pooled connection available, so use this one. conn.startRequestTimer(); conn.incrementUsageCount(); conn.getChannel().read(); onAcquire(conn, httpMethod, uri, attemptNum, passport); initPooledConnection(conn, promise); selectedHostAddr.set(getHostFromServer(conn.getServer())); } else { // connection pool empty, create new connection using client connection factory. tryMakingNewConnection(eventLoop, promise, httpMethod, uri, attemptNum, passport, selectedHostAddr); } return promise; }
private void writeClientRequestToOrigin(final PooledConnection conn) { final Channel ch = conn.getChannel(); passport.setOnChannel(ch); context.set(ORIGIN_CHANNEL, ch); context.set(POOLED_ORIGIN_CONNECTION_KEY, conn); preWriteToOrigin(chosenServer.get(), zuulRequest); final ChannelPipeline pipeline = ch.pipeline(); originResponseReceiver = getOriginResponseReceiver(); pipeline.addBefore("connectionPoolHandler", OriginResponseReceiver.CHANNEL_HANDLER_NAME, originResponseReceiver); // check if body needs to be repopulated for retry repopulateRetryBody(); ch.write(zuulRequest); writeBufferedBodyContent(zuulRequest, ch); ch.flush(); //Get ready to read origin's response ch.read(); originConn = conn; channelCtx.read(); }
@Override public Promise<PooledConnection> acquire(EventLoop eventLoop, Object key, String httpMethod, String uri, int attemptNum, CurrentPassport passport, AtomicReference<String> selectedHostAddr) { requestConnCounter.increment(); stats.incrementActiveRequestsCount(); Promise<PooledConnection> promise = eventLoop.newPromise(); // Try getting a connection from the pool. final PooledConnection conn = tryGettingFromConnectionPool(eventLoop); if (conn != null) { // There was a pooled connection available, so use this one. conn.startRequestTimer(); conn.incrementUsageCount(); conn.getChannel().read(); onAcquire(conn, httpMethod, uri, attemptNum, passport); initPooledConnection(conn, promise); selectedHostAddr.set(getHostFromServer(conn.getServer())); } else { // connection pool empty, create new connection using client connection factory. tryMakingNewConnection(eventLoop, promise, httpMethod, uri, attemptNum, passport, selectedHostAddr); } return promise; }