/** * Always prefer a direct buffer when it's pooled, so that we reduce the number of memory copies * in {@link OpenSslEngine}. */ private ByteBuf allocate(ChannelHandlerContext ctx, int capacity) { ByteBufAllocator alloc = ctx.alloc(); if (engineType.wantsDirectBuffer) { return alloc.directBuffer(capacity); } else { return alloc.buffer(capacity); } }
/** * Always prefer a direct buffer when it's pooled, so that we reduce the number of memory copies * in {@link OpenSslEngine}. */ private ByteBuf allocate(ChannelHandlerContext ctx, int capacity) { ByteBufAllocator alloc = ctx.alloc(); if (engineType.wantsDirectBuffer) { return alloc.directBuffer(capacity); } else { return alloc.buffer(capacity); } }
static ByteBuf expandCumulation(ByteBufAllocator alloc, ByteBuf cumulation, int readable) { ByteBuf oldCumulation = cumulation; cumulation = alloc.buffer(oldCumulation.readableBytes() + readable); cumulation.writeBytes(oldCumulation); oldCumulation.release(); return cumulation; }
/** * Once the channel is active, start the SASL auth negotiation. */ @Override public void channelActive(final ChannelHandlerContext ctx) throws Exception { ByteBuf request = ctx.alloc().buffer(); SaslListMechsRequest.init(request); ctx.writeAndFlush(request); }
static ByteBuf expandCumulation(ByteBufAllocator alloc, ByteBuf cumulation, int readable) { ByteBuf oldCumulation = cumulation; cumulation = alloc.buffer(oldCumulation.readableBytes() + readable); cumulation.writeBytes(oldCumulation); oldCumulation.release(); return cumulation; }
@Override public ByteBuf readBytes(int length) { checkReadableBytes(length); if (length == 0) { return Unpooled.EMPTY_BUFFER; } ByteBuf buf = alloc().buffer(length, maxCapacity); buf.writeBytes(this, readerIndex, length); readerIndex += length; return buf; }
@Override public ByteBuf readBytes(int length) { checkReadableBytes(length); if (length == 0) { return Unpooled.EMPTY_BUFFER; } ByteBuf buf = alloc().buffer(length, maxCapacity); buf.writeBytes(this, readerIndex, length); readerIndex += length; return buf; }
private void open(ChannelHandlerContext ctx) { ByteBuf request = ctx.alloc().buffer(); DcpOpenConnectionRequest.init(request); DcpOpenConnectionRequest.connectionName(request, Unpooled.copiedBuffer(connectionName, CharsetUtil.UTF_8)); ctx.writeAndFlush(request); }
private static BinaryMemcacheRequest handleObserveSeqnoRequest(final ChannelHandlerContext ctx, final ObserveSeqnoRequest msg) { ByteBuf content = ctx.alloc().buffer(); content.writeLong(msg.vbucketUUID()); BinaryMemcacheRequest request = new DefaultFullBinaryMemcacheRequest(EMPTY_BYTES, Unpooled.EMPTY_BUFFER, content); request.setOpcode(OP_OBSERVE_SEQ); request.setTotalBodyLength(content.readableBytes()); return request; }
ByteBuf decode(ByteBuf src, int off, int len, ByteBufAllocator allocator, Base64Dialect dialect) { dest = allocator.buffer(decodedBufferSize(len)).order(src.order()); // Upper limit on size of output decodabet = decodabet(dialect); try { src.forEachByte(off, len, this); return dest.slice(0, outBuffPosn); } catch (Throwable cause) { dest.release(); PlatformDependent.throwException(cause); return null; } }
ByteBuf decode(ByteBuf src, int off, int len, ByteBufAllocator allocator, Base64Dialect dialect) { dest = allocator.buffer(decodedBufferSize(len)).order(src.order()); // Upper limit on size of output decodabet = decodabet(dialect); try { src.forEachByte(off, len, this); return dest.slice(0, outBuffPosn); } catch (Throwable cause) { dest.release(); PlatformDependent.throwException(cause); return null; } }
@Override protected ByteBuf encodeMessage(ChannelHandlerContext ctx, M msg) { ByteBuf buf = ctx.alloc().buffer(MINIMUM_HEADER_SIZE + msg.getExtrasLength() + msg.getKeyLength()); encodeHeader(buf, msg); encodeExtras(buf, msg.getExtras()); encodeKey(buf, msg.getKey()); return buf; }
@Override protected ByteBuf encodeMessage(ChannelHandlerContext ctx, M msg) { ByteBuf buf = ctx.alloc().buffer(MINIMUM_HEADER_SIZE + msg.getExtrasLength() + msg.getKeyLength()); encodeHeader(buf, msg); encodeExtras(buf, msg.getExtras()); encodeKey(buf, msg.getKey()); return buf; }
private RawQueryResponse handleRawQueryResponse(boolean lastChunk, ChannelHandlerContext ctx) { if (!lastChunk) { return null; } ResponseStatus status = ResponseStatusConverter.fromHttp(responseHeader.getStatus().code()); ByteBuf responseCopy = ctx.alloc().buffer(responseContent.readableBytes(), responseContent.readableBytes()); responseCopy.writeBytes(responseContent); return new RawQueryResponse(status, currentRequest(), responseCopy, responseHeader.getStatus().code(), responseHeader.getStatus().reasonPhrase()); }
private RawAnalyticsResponse handleRawAnalyticsResponse(boolean lastChunk, ChannelHandlerContext ctx) { if (!lastChunk) { return null; } ResponseStatus status = ResponseStatusConverter.fromHttp(responseHeader.getStatus().code()); ByteBuf responseCopy = ctx.alloc().buffer(responseContent.readableBytes(), responseContent.readableBytes()); responseCopy.writeBytes(responseContent); return new RawAnalyticsResponse(status, currentRequest(), responseCopy, responseHeader.getStatus().code(), responseHeader.getStatus().reasonPhrase()); }
private RawQueryResponse handleRawQueryResponse(boolean lastChunk, ChannelHandlerContext ctx) { if (!lastChunk) { return null; } ResponseStatus status = ResponseStatusConverter.fromHttp(responseHeader.getStatus().code()); ByteBuf responseCopy = ctx.alloc().buffer(responseContent.readableBytes(), responseContent.readableBytes()); responseCopy.writeBytes(responseContent); return new RawQueryResponse(status, currentRequest(), responseCopy, responseHeader.getStatus().code(), responseHeader.getStatus().reasonPhrase()); }
private RawQueryResponse handleRawQueryResponse(boolean lastChunk, ChannelHandlerContext ctx) { if (!lastChunk) { return null; } ResponseStatus status = ResponseStatusConverter.fromHttp(responseHeader.getStatus().code()); ByteBuf responseCopy = ctx.alloc().buffer(responseContent.readableBytes(), responseContent.readableBytes()); responseCopy.writeBytes(responseContent); cleanupQueryStates(); return new RawQueryResponse(status, currentRequest(), responseCopy, responseHeader.getStatus().code(), responseHeader.getStatus().reasonPhrase()); }
private RawAnalyticsResponse handleRawAnalyticsResponse(boolean lastChunk, ChannelHandlerContext ctx) { if (!lastChunk) { return null; } ResponseStatus status = ResponseStatusConverter.fromHttp(responseHeader.getStatus().code()); ByteBuf responseCopy = ctx.alloc().buffer(responseContent.readableBytes(), responseContent.readableBytes()); responseCopy.writeBytes(responseContent); cleanupQueryStates(); return new RawAnalyticsResponse(status, currentRequest(), responseCopy, responseHeader.getStatus().code(), responseHeader.getStatus().reasonPhrase()); }
private RawQueryResponse handleRawQueryResponse(boolean lastChunk, ChannelHandlerContext ctx) { if (!lastChunk) { return null; } ResponseStatus status = ResponseStatusConverter.fromHttp(responseHeader.getStatus().code()); ByteBuf responseCopy = ctx.alloc().buffer(responseContent.readableBytes(), responseContent.readableBytes()); responseCopy.writeBytes(responseContent); cleanupQueryStates(); return new RawQueryResponse(status, currentRequest(), responseCopy, responseHeader.getStatus().code(), responseHeader.getStatus().reasonPhrase()); }
private RawAnalyticsResponse handleRawAnalyticsResponse(boolean lastChunk, ChannelHandlerContext ctx) { if (!lastChunk) { return null; } ResponseStatus status = ResponseStatusConverter.fromHttp(responseHeader.getStatus().code()); ByteBuf responseCopy = ctx.alloc().buffer(responseContent.readableBytes(), responseContent.readableBytes()); responseCopy.writeBytes(responseContent); cleanupQueryStates(); return new RawAnalyticsResponse(status, currentRequest(), responseCopy, responseHeader.getStatus().code(), responseHeader.getStatus().reasonPhrase()); }