@Override public void handlerAdded(ChannelHandlerContext ctx) { try { // send the connection header to server first ctx.writeAndFlush(connectionHeaderWithLength.retainedDuplicate()); } catch (Exception e) { // the exception thrown by handlerAdded will not be passed to the exceptionCaught below // because netty will remove a handler if handlerAdded throws an exception. exceptionCaught(ctx, e); } }
@Override public void operationComplete(ChannelFuture future) throws Exception { Channel ch = future.channel(); if (!future.isSuccess()) { failInit(ch, toIOE(future.cause())); rpcClient.failedServers.addToFailedServers(remoteId.address, future.cause()); return; } ch.writeAndFlush(connectionHeaderPreamble.retainedDuplicate()); if (useSasl) { saslNegotiate(ch); } else { // send the connection header to server ch.write(connectionHeaderWithLength.retainedDuplicate()); established(ch); } } }).channel();
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); } }
ch.write(headerBuf.retainedDuplicate()); ch.write(checksumBuf.retainedDuplicate()); ch.writeAndFlush(dataBuf.retainedDuplicate()); }); checksumBuf.release();
} else { ch.write(connectionHeaderWithLength.retainedDuplicate()); established(ch);
@Override public void handlerAdded(ChannelHandlerContext ctx) { try { // send the connection header to server first ctx.writeAndFlush(connectionHeaderWithLength.retainedDuplicate()); } catch (Exception e) { // the exception thrown by handlerAdded will not be passed to the exceptionCaught below // because netty will remove a handler if handlerAdded throws an exception. exceptionCaught(ctx, e); } }
@Override public void operationComplete(ChannelFuture future) throws Exception { Channel ch = future.channel(); if (!future.isSuccess()) { failInit(ch, toIOE(future.cause())); rpcClient.failedServers.addToFailedServers(remoteId.address, future.cause()); return; } ch.writeAndFlush(connectionHeaderPreamble.retainedDuplicate()); if (useSasl) { saslNegotiate(ch); } else { // send the connection header to server ch.write(connectionHeaderWithLength.retainedDuplicate()); established(ch); } } }).channel();
/** * Returns a buffer filled with all zeros that is the appropriate length for a PING frame. */ public static ByteBuf emptyPingBuf() { // Return a duplicate so that modifications to the reader index will not affect the original buffer. return EMPTY_PING.retainedDuplicate(); }
/** * {@inheritDoc} * <p> * This method calls {@code replace(content().retainedDuplicate())} by default. */ @Override public ByteBufHolder retainedDuplicate() { return replace(data.retainedDuplicate()); }
@Override public PemPrivateKey retainedDuplicate() { return replace(content.retainedDuplicate()); }
@Override public PemValue retainedDuplicate() { return replace(content.retainedDuplicate()); }
} else { ch.write(connectionHeaderWithLength.retainedDuplicate()); established(ch);
@Override public FullBinaryMemcacheResponse replace(ByteBuf content) { ByteBuf key = key(); if (key != null) { key = key.retainedDuplicate(); } ByteBuf extras = extras(); if (extras != null) { extras = extras.retainedDuplicate(); } return new DefaultFullBinaryMemcacheResponse(key, extras, content); } }
@Override public void handlerAdded(ChannelHandlerContext ctx) { try { // send the connection header to server first ctx.writeAndFlush(connectionHeaderWithLength.retainedDuplicate()); } catch (Exception e) { // the exception thrown by handlerAdded will not be passed to the exceptionCaught below // because netty will remove a handler if handlerAdded throws an exception. exceptionCaught(ctx, e); } }
@Override public FullBinaryMemcacheResponse retainedDuplicate() { return replace(content().retainedDuplicate()); }
@Override public DefaultHttp2UnknownFrame retainedDuplicate() { return replace(content().retainedDuplicate()); }
@Override public MqttPublishMessage retainedDuplicate() { return replace(content().retainedDuplicate()); }
@Override public FullHttpResponse retainedDuplicate() { return replace(content().retainedDuplicate()); }
@Override public DefaultHttp2PingFrame retainedDuplicate() { return replace(content().retainedDuplicate()); }
@Override public LastHttpContent retainedDuplicate() { return replace(content().retainedDuplicate()); }