NettyServerRpcConnection(NettyRpcServer rpcServer, Channel channel) { super(rpcServer); this.channel = channel; InetSocketAddress inetSocketAddress = ((InetSocketAddress) channel.remoteAddress()); this.addr = inetSocketAddress.getAddress(); if (addr == null) { this.hostAddress = "*Unknown*"; } else { this.hostAddress = inetSocketAddress.getAddress().getHostAddress(); } this.remotePort = inetSocketAddress.getPort(); }
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { if (state == State.CLOSED) { return; } failed(ctx.channel(), () -> new IOException("Connection to " + ctx.channel().remoteAddress() + " closed")); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable e) { allChannels.remove(ctx.channel()); NettyRpcServer.LOG.trace("Connection {}; caught unexpected downstream exception.", ctx.channel().remoteAddress(), e.getCause()); ctx.channel().close(); } }
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { allChannels.add(ctx.channel()); NettyRpcServer.LOG.trace("Connection {}; # active connections={}", ctx.channel().remoteAddress(), (allChannels.size() - 1)); super.channelActive(ctx); }
@Override protected void channelRead0(ChannelHandlerContext ctx, PipelineAckProto ack) throws Exception { Status reply = getStatus(ack); if (reply != Status.SUCCESS) { failed(ctx.channel(), () -> new IOException("Bad response " + reply + " for block " + block + " from datanode " + ctx.channel().remoteAddress())); return; } if (PipelineAck.isRestartOOBStatus(reply)) { failed(ctx.channel(), () -> new IOException("Restart response " + reply + " for block " + block + " from datanode " + ctx.channel().remoteAddress())); return; } if (ack.getSeqno() == HEART_BEAT_SEQNO) { return; } completed(ctx.channel()); }
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { allChannels.remove(ctx.channel()); NettyRpcServer.LOG.trace("Disconnection {}; # active connections={}", ctx.channel().remoteAddress(), (allChannels.size() - 1)); super.channelInactive(ctx); }
SASL_ADAPTOR.getTrustedChannelResolver(saslClient); AtomicBoolean fallbackToSimpleAuth = SASL_ADAPTOR.getFallbackToSimpleAuth(saslClient); InetAddress addr = ((InetSocketAddress) channel.remoteAddress()).getAddress(); if (trustedChannelResolver.isTrusted() || trustedChannelResolver.isTrusted(addr)) { saslPromise.trySuccess(null);
@Override public SocketAddress remoteAddress() { return parent().remoteAddress(); }
private boolean handleNewChannel(ChannelHandlerContext ctx) throws Exception { @SuppressWarnings("unchecked") T remoteAddress = (T) ctx.channel().remoteAddress(); // If the remote address is not available yet, defer the decision. if (remoteAddress == null) { return false; } // No need to keep this handler in the pipeline anymore because the decision is going to be made now. // Also, this will prevent the subsequent events from being handled by this handler. ctx.pipeline().remove(this); if (accept(ctx, remoteAddress)) { channelAccepted(ctx, remoteAddress); } else { ChannelFuture rejectedFuture = channelRejected(ctx, remoteAddress); if (rejectedFuture != null) { rejectedFuture.addListener(ChannelFutureListener.CLOSE); } else { ctx.close(); } } return true; }