@Override public void run() { buf.release(); } };
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof ByteBuf) { ByteBuf buf = (ByteBuf) msg; try { readResponse(ctx, buf); } finally { buf.release(); } } else { super.channelRead(ctx, msg); } }
private void endBlock() throws IOException { Preconditions.checkState(waitingAckQueue.isEmpty(), "should call flush first before calling close"); if (state != State.STREAMING) { throw new IOException("stream already broken"); } state = State.CLOSING; long finalizedLength = ackedBlockLength; PacketHeader header = new PacketHeader(4, finalizedLength, nextPacketSeqno, true, 0, false); buf.release(); buf = null; int headerLen = header.getSerializedSize(); ByteBuf headerBuf = alloc.directBuffer(headerLen); header.putInBuffer(headerBuf.nioBuffer(0, headerLen)); headerBuf.writerIndex(headerLen); CompletableFuture<Long> future = new CompletableFuture<>(); waitingAckQueue.add(new Callback(future, finalizedLength, datanodeList)); datanodeList.forEach(ch -> ch.writeAndFlush(headerBuf.retainedDuplicate())); headerBuf.release(); try { future.get(); } catch (InterruptedException e) { throw (IOException) new InterruptedIOException().initCause(e); } catch (ExecutionException e) { Throwable cause = e.getCause(); Throwables.propagateIfPossible(cause, IOException.class); throw new IOException(cause); } }
void process(final ByteBuf buf) throws IOException, InterruptedException { if (connectionHeaderRead) { this.callCleanup = new RpcServer.CallCleanup() { @Override public void run() { buf.release(); } }; process(new SingleByteBuff(buf.nioBuffer())); } else { ByteBuffer connectionHeader = ByteBuffer.allocate(buf.readableBytes()); buf.readBytes(connectionHeader); buf.release(); process(connectionHeader); } }
encryptBuf.nioBuffer(trailingPartialChunkLength, toEncryptLength)); } catch (IOException e) { encryptBuf.release(); future.completeExceptionally(e); return; buf.release(); buf = encryptBuf; trailingPartialChunkLength); buf.release(); this.buf = newBuf; nextPacketOffsetInBlock += dataLen - trailingPartialChunkLength;
@Override protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception { ByteBuf inBuf; boolean release = false; if (msg.nioBufferCount() == 1) { inBuf = msg; } else { inBuf = ctx.alloc().directBuffer(msg.readableBytes()); msg.readBytes(inBuf); release = true; } ByteBuffer inBuffer = inBuf.nioBuffer(); ByteBuffer outBuffer = out.nioBuffer(0, inBuf.readableBytes()); encryptor.encrypt(inBuffer, outBuffer); out.writerIndex(inBuf.readableBytes()); if (release) { inBuf.release(); } } }
private RPCProtos.RequestHeader getHeader(ByteBuf in, int headerSize) throws IOException { ByteBuf msg = in.readRetainedSlice(headerSize); try { byte[] array; int offset; int length = msg.readableBytes(); if (msg.hasArray()) { array = msg.array(); offset = msg.arrayOffset() + msg.readerIndex(); } else { array = new byte[length]; msg.getBytes(msg.readerIndex(), array, 0, length); offset = 0; } RPCProtos.RequestHeader.Builder builder = RPCProtos.RequestHeader.newBuilder(); ProtobufUtil.mergeFrom(builder, array, offset, length); return builder.build(); } finally { msg.release(); } }
@Override protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception { ByteBuf inBuf; boolean release = false; if (msg.nioBufferCount() == 1) { inBuf = msg; } else { inBuf = ctx.alloc().directBuffer(msg.readableBytes()); msg.readBytes(inBuf); release = true; } ByteBuffer inBuffer = inBuf.nioBuffer(); ByteBuf outBuf = ctx.alloc().directBuffer(inBuf.readableBytes()); ByteBuffer outBuffer = outBuf.nioBuffer(0, inBuf.readableBytes()); decryptor.decrypt(inBuffer, outBuffer); outBuf.writerIndex(inBuf.readableBytes()); if (release) { inBuf.release(); } ctx.fireChannelRead(outBuf); } }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof ByteBuf) { ByteBuf buf = (ByteBuf) msg; try { readResponse(ctx, buf); } finally { buf.release(); } } else { super.channelRead(ctx, msg); } }
/** * Releases the {@code clientPrefaceString}. Any active streams will be left in the open. */ private void cleanup() { if (clientPrefaceString != null) { clientPrefaceString.release(); clientPrefaceString = null; } }
@Override public boolean release(int decrement) { return buf.release(decrement); } }
@Override public void delete() { if (byteBuf != null) { byteBuf.release(); byteBuf = null; } }
/** * Closes this builder and frees any resources. */ void close() { if (headerBlock != null) { headerBlock.release(); headerBlock = null; } // Clear the member variable pointing at this instance. headersContinuation = null; } }
@Override protected final void deallocate() { // We need to first store a reference to the parent before recycle this instance. This is needed as // otherwise it is possible that the same AbstractPooledDerivedByteBuf is again obtained and init(...) is // called before we actually have a chance to call release(). This leads to call release() on the wrong parent. ByteBuf parent = this.parent; recyclerHandle.recycle(this); parent.release(); }
@Override protected void deallocate() { for (int i = 0; i < buffers.length; i++) { buffer(i).release(); } }
@Override public BinaryMemcacheMessage setKey(ByteBuf key) { if (this.key != null) { this.key.release(); } this.key = key; short oldKeyLength = keyLength; keyLength = key == null ? 0 : (short) key.readableBytes(); totalBodyLength = totalBodyLength + keyLength - oldKeyLength; return this; }
@Override protected void deallocate() { if (sensitive) { SslUtils.zeroout(content); } content.release(); } }
@Override protected void deallocate() { super.deallocate(); content.release(); }
/** * Creates an HTTP2-Settings header with the given payload. The payload buffer is released. */ private static ByteBuf createSettingsFrame(ChannelHandlerContext ctx, ByteBuf payload) { ByteBuf frame = ctx.alloc().buffer(FRAME_HEADER_LENGTH + payload.readableBytes()); writeFrameHeader(frame, payload.readableBytes(), SETTINGS, new Http2Flags(), 0); frame.writeBytes(payload); payload.release(); return frame; } }