@Override public void operationComplete(Future<Void> future) throws Exception { if (future.isSuccess()) { // setup response processing pipeline first, then send request. processWriteBlockResponse(channel, dnInfo, promise, timeoutMs); requestWriteBlock(channel, storageType, writeBlockProtoBuilder); } else { promise.tryFailure(future.cause()); } } });
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { promise.tryFailure(cause); } });
static Pair<EventLoopGroup, Class<? extends Channel>> getEventLoopConfig(Configuration conf) { String name = conf.get(EVENT_LOOP_CONFIG); if (StringUtils.isBlank(name)) { // create new event loop group if config is empty return Pair.<EventLoopGroup, Class<? extends Channel>> newPair( new NioEventLoopGroup(0, new DefaultThreadFactory("AsyncFSWAL", true, Thread.MAX_PRIORITY)), NioSocketChannel.class); } return EVENT_LOOP_CONFIG_MAP.get(name); }
@AfterClass public static void tearDownAfterClass() throws Exception { AbstractTestProtobufLog.tearDownAfterClass(); EVENT_LOOP_GROUP.shutdownGracefully().syncUninterruptibly(); }
private void tryComplete(ChannelHandlerContext ctx) { if (!saslRpcClient.isComplete()) { return; } saslRpcClient.setupSaslHandler(ctx.pipeline()); setCryptoAESOption(); saslPromise.setSuccess(true); }
private static void initialize(Configuration conf, Channel channel, DatanodeInfo dnInfo, Enum<?> storageType, OpWriteBlockProto.Builder writeBlockProtoBuilder, int timeoutMs, DFSClient client, Token<BlockTokenIdentifier> accessToken, Promise<Channel> promise) throws IOException { Promise<Void> saslPromise = channel.eventLoop().newPromise(); trySaslNegotiate(conf, channel, dnInfo, timeoutMs, client, accessToken, saslPromise); saslPromise.addListener(new FutureListener<Void>() { @Override public void operationComplete(Future<Void> future) throws Exception { if (future.isSuccess()) { // setup response processing pipeline first, then send request. processWriteBlockResponse(channel, dnInfo, promise, timeoutMs); requestWriteBlock(channel, storageType, writeBlockProtoBuilder); } else { promise.tryFailure(future.cause()); } } }); }
@AfterClass public static void tearDown() throws IOException, InterruptedException { if (EVENT_LOOP_GROUP != null) { EVENT_LOOP_GROUP.shutdownGracefully().sync(); } TEST_UTIL.shutdownMiniDFSCluster(); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { saslPromise.tryFailure(cause); }
public NettyRpcClient(Configuration configuration, String clusterId, SocketAddress localAddress, MetricsConnection metrics) { super(configuration, clusterId, localAddress, metrics); Pair<EventLoopGroup, Class<? extends Channel>> groupAndChannelClass = NettyRpcClientConfigHelper .getEventLoopConfig(conf); if (groupAndChannelClass == null) { // Use our own EventLoopGroup. this.group = new NioEventLoopGroup(0, new DefaultThreadFactory("IPC-NioEventLoopGroup", true, Thread.MAX_PRIORITY)); this.channelClass = NioSocketChannel.class; this.shutdownGroupWhenClose = true; } else { this.group = groupAndChannelClass.getFirst(); this.channelClass = groupAndChannelClass.getSecond(); this.shutdownGroupWhenClose = false; } }
@AfterClass public static void tearDownAfterClass() throws Exception { if (WALS != null) { WALS.close(); } EVENT_LOOP_GROUP.shutdownGracefully().syncUninterruptibly(); UTIL.shutdownMiniDFSCluster(); }
@Override protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception { // read the ConnectionHeaderResponse from server int len = msg.readInt(); byte[] buff = new byte[len]; msg.readBytes(buff); RPCProtos.ConnectionHeaderResponse connectionHeaderResponse = RPCProtos.ConnectionHeaderResponse.parseFrom(buff); // Get the CryptoCipherMeta, update the HBaseSaslRpcClient for Crypto Cipher if (connectionHeaderResponse.hasCryptoCipherMeta()) { CryptoAES cryptoAES = EncryptionUtil.createCryptoAES( connectionHeaderResponse.getCryptoCipherMeta(), conf); // replace the Sasl handler with Crypto AES handler setupCryptoAESHandler(ctx.pipeline(), cryptoAES); } saslPromise.setSuccess(true); }
@AfterClass public static void tearDownAfterClass() throws IOException, InterruptedException { if (EVENT_LOOP_GROUP != null) { EVENT_LOOP_GROUP.shutdownGracefully().sync(); } if (KDC != null) { KDC.stop(); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { promise.tryFailure(cause); }
public NettyEventLoopGroupConfig(Configuration conf, String threadPoolName) { boolean useEpoll = useEpoll(conf); int workerCount = conf.getInt("hbase.netty.worker.count", 0); ThreadFactory eventLoopThreadFactory = new DefaultThreadFactory(threadPoolName, true, Thread.MAX_PRIORITY); if (useEpoll) { group = new EpollEventLoopGroup(workerCount, eventLoopThreadFactory); serverChannelClass = EpollServerSocketChannel.class; clientChannelClass = EpollSocketChannel.class; } else { group = new NioEventLoopGroup(workerCount, eventLoopThreadFactory); serverChannelClass = NioServerSocketChannel.class; clientChannelClass = NioSocketChannel.class; } }
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { promise.tryFailure(new IOException("connection to " + dnInfo + " is closed")); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { saslRpcClient.dispose(); saslPromise.tryFailure(cause); } }
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof IdleStateEvent && ((IdleStateEvent) evt).state() == READER_IDLE) { promise.tryFailure(new IOException("Timeout(" + timeoutMs + "ms) waiting for response")); } else { super.userEventTriggered(ctx, evt); } } }
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof IdleStateEvent && ((IdleStateEvent) evt).state() == READER_IDLE) { promise .tryFailure(new IOException("Timeout(" + timeoutMs + "ms) waiting for response")); } else { super.userEventTriggered(ctx, evt); } }
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { saslRpcClient.dispose(); saslPromise.tryFailure(new ConnectionClosedException("Connection closed")); ctx.fireChannelInactive(); }