/** * Note this blocks until all the channels have finished closing. */ public void gracefullyShutdownClientChannels() { LOG.warn("Gracefully shutting down all client channels"); try { List<ChannelFuture> futures = new ArrayList<>(); channels.forEach(channel -> { ConnectionCloseType.setForChannel(channel, ConnectionCloseType.DELAYED_GRACEFUL); ChannelFuture f = channel.pipeline().close(); futures.add(f); }); LOG.warn("Waiting for " + futures.size() + " client channels to be closed."); for (ChannelFuture f : futures) { f.await(); } LOG.warn(futures.size() + " client channels closed."); } catch (InterruptedException ie) { LOG.warn("Interrupted while shutting down client channels"); } } }
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (isResponseHeaders(msg)) { // Update the request count attribute for this channel. requestCount++; if (isConnectionExpired(ctx)) { // Flag this channel to be closed after response is written. HttpChannelFlags.CLOSE_AFTER_RESPONSE.set(ctx); // with close of configured type. ConnectionCloseType.setForChannel(ctx.channel(), connectionCloseType); } } super.write(ctx, msg, promise); }
/** * Note this blocks until all the channels have finished closing. */ public void gracefullyShutdownClientChannels() { LOG.warn("Gracefully shutting down all client channels"); try { List<ChannelFuture> futures = new ArrayList<>(); channels.forEach(channel -> { ConnectionCloseType.setForChannel(channel, ConnectionCloseType.DELAYED_GRACEFUL); ChannelFuture f = channel.pipeline().close(); futures.add(f); }); LOG.warn("Waiting for " + futures.size() + " client channels to be closed."); for (ChannelFuture f : futures) { f.await(); } LOG.warn(futures.size() + " client channels closed."); } catch (InterruptedException ie) { LOG.warn("Interrupted while shutting down client channels"); } } }
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (isResponseHeaders(msg)) { // Update the request count attribute for this channel. requestCount++; if (isConnectionExpired(ctx)) { // Flag this channel to be closed after response is written. HttpChannelFlags.CLOSE_AFTER_RESPONSE.set(ctx); // with close of configured type. ConnectionCloseType.setForChannel(ctx.channel(), connectionCloseType); } } super.write(ctx, msg, promise); }
/** * Note this blocks until all the channels have finished closing. */ public void gracefullyShutdownClientChannels() { LOG.warn("Gracefully shutting down all client channels"); try { List<ChannelFuture> futures = new ArrayList<>(); channels.forEach(channel -> { ConnectionCloseType.setForChannel(channel, ConnectionCloseType.DELAYED_GRACEFUL); ChannelFuture f = channel.pipeline().close(); futures.add(f); }); LOG.warn("Waiting for " + futures.size() + " client channels to be closed."); for (ChannelFuture f : futures) { f.await(); } LOG.warn(futures.size() + " client channels closed."); } catch (InterruptedException ie) { LOG.warn("Interrupted while shutting down client channels"); } } }
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (isResponseHeaders(msg)) { // Update the request count attribute for this channel. requestCount++; if (isConnectionExpired(ctx)) { // Flag this channel to be closed after response is written. HttpChannelFlags.CLOSE_AFTER_RESPONSE.set(ctx); // with close of configured type. ConnectionCloseType.setForChannel(ctx.channel(), connectionCloseType); } } super.write(ctx, msg, promise); }