private static void releaseChunk(DataChunk chunk) { if (chunk != null && !chunk.isReleased()) { LOGGER.finest(() -> "Releasing chunk: " + chunk.id()); chunk.release(); } }
@Override public void onNext(DataChunk data) { if (internallyClosed.get()) { throw new IllegalStateException("Response is already closed!"); } if (data != null) { LOGGER.finest(() -> log("Sending data chunk")); DefaultHttpContent httpContent = new DefaultHttpContent(Unpooled.wrappedBuffer(data.data())); runOnOutboundEventLoopThread(() -> { LOGGER.finest(() -> log("Sending data chunk on event loop thread.")); ChannelFuture channelFuture; if (data.flush()) { channelFuture = ctx.writeAndFlush(httpContent); } else { channelFuture = ctx.write(httpContent); } channelFuture .addListener(future -> { data.release(); LOGGER.finest(() -> log("Data chunk sent with result: " + future.isSuccess())); }) .addListener(completeOnFailureListener("Failure when sending a content!")) .addListener(ChannelFutureListener.CLOSE_ON_FAILURE); }); } }
curentChunk.release();
private static void releaseChunk(DataChunk chunk) { if (chunk != null && !chunk.isReleased()) { LOGGER.finest(() -> "Releasing chunk: " + chunk.id()); chunk.release(); } }
@Override public void onNext(DataChunk data) { if (internallyClosed.get()) { throw new IllegalStateException("Response is already closed!"); } if (data != null) { LOGGER.finest(() -> log("Sending data chunk")); DefaultHttpContent httpContent = new DefaultHttpContent(Unpooled.wrappedBuffer(data.data())); runOnOutboundEventLoopThread(() -> { LOGGER.finest(() -> log("Sending data chunk on event loop thread.")); ChannelFuture channelFuture; if (data.flush()) { channelFuture = ctx.writeAndFlush(httpContent); } else { channelFuture = ctx.write(httpContent); } channelFuture .addListener(future -> { data.release(); LOGGER.finest(() -> log("Data chunk sent with result: " + future.isSuccess())); }) .addListener(completeOnFailureListener("Failure when sending a content!")) .addListener(ChannelFutureListener.CLOSE_ON_FAILURE); }); } }
curentChunk.release();