Source:
void maybeReadPayload(ChannelHandlerContext ctx) { if (pending.readableBytes() < nextFrameSize) return; ByteBuf payload = ctx.alloc().buffer(nextFrameSize); pending.readBytes(payload, nextFrameSize); pending.discardSomeReadBytes(); state = ReadState.HEADER; HttpRequest request = HttpRequest.of(THRIFT_HEADERS, new ByteBufHttpData(payload, true)); ServiceRequestContextBuilder requestContextBuilder = ServiceRequestContextBuilder.of(request) .service(scribeService) .alloc(ctx.alloc()); if (ctx.executor() instanceof EventLoop) { requestContextBuilder.eventLoop((EventLoop) ctx.executor()); } ServiceRequestContext requestContext = requestContextBuilder.build(); final HttpResponse response; try (SafeCloseable unused = requestContext.push()) { response = scribeService.serve(requestContext, request); } catch (Throwable t) { propagateIfFatal(t); exceptionCaught(ctx, t); return; } int responseIndex = nextResponseIndex++; response.aggregateWithPooledObjects(ctx.executor(), ctx.alloc()).handle((msg, t) -> { if (t != null) { exceptionCaught(ctx, t); return null; } HttpData content = msg.content(); ByteBuf returned = ctx.alloc().buffer(content.length() + 4); returned.writeInt(content.length()); if (content instanceof ByteBufHolder) { ByteBuf buf = ((ByteBufHolder) content).content(); try { returned.writeBytes(buf); } finally { buf.release(); } } else { returned.writeBytes(content.array(), 0, content.length()); } if (responseIndex == previouslySentResponseIndex + 1) { ctx.writeAndFlush(returned); previouslySentResponseIndex++; flushResponses(ctx); } else { pendingResponses.put(responseIndex, returned); } return null; }); }

Target:
void maybeReadPayload(ChannelHandlerContext ctx) { if (pending.readableBytes() < nextFrameSize) return; ByteBuf payload = ctx.alloc().buffer(nextFrameSize); pending.readBytes(payload, nextFrameSize); pending.discardSomeReadBytes(); state = ReadState.HEADER; HttpRequest request = HttpRequest.of(THRIFT_HEADERS, new ByteBufHttpData(payload, true)); ServiceRequestContextBuilder requestContextBuilder = ServiceRequestContextBuilder.of(request) .service(scribeService) .alloc(ctx.alloc()); if (ctx.executor() instanceof EventLoop) { requestContextBuilder.eventLoop((EventLoop) ctx.executor()); } ServiceRequestContext requestContext = requestContextBuilder.build(); final HttpResponse response; try (SafeCloseable unused = requestContext.push()) { response = scribeService.serve(requestContext, request); } catch (Throwable t) { propagateIfFatal(t); exceptionCaught(ctx, t); return; } int responseIndex = nextResponseIndex++; response.aggregateWithPooledObjects(ctx.executor(), ctx.alloc()).handle((msg, t) -> { if (t != null) { exceptionCaught(ctx, t); return null; } HttpData content = msg.content(); ByteBuf returned = ctx.alloc().buffer(content.length() + 4); returned.writeInt(content.length()); if (content instanceof ByteBufHolder) { ByteBuf buf = ((ByteBufHolder) content).content(); try { returned.writeBytes(buf); } finally { buf.release(); } } else { returned.writeBytes(content.array()); } if (responseIndex == previouslySentResponseIndex + 1) { ctx.writeAndFlush(returned); previouslySentResponseIndex++; flushResponses(ctx); } else { pendingResponses.put(responseIndex, returned); } return null; }); }