Refine search
public static SocketChannel open(SocketAddress address) throws Exception { SocketChannel socket = null; ChannelFuture future = boot.connect(address).sync(); if (future.isSuccess()) { future.channel().pipeline().get(BusinessHandler.class).latch.await(); socket = chManager.get(future.channel()); } if (null == socket) { throw new IOException("can't create socket!"); } return socket; }
@Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { // Add a handler that just catches the Http2Exception that we fire to tell the codec to gracefully shutdown a connection. // We want to catch it so that it doesn't get logged by the DefaultChannelPipeline as if it was a _real_ // exception. ChannelPipeline parentPipeline = ctx.channel().parent().pipeline(); String handlerName = "h2_exception_swallow_handler"; if (parentPipeline.get(handlerName) == null) { parentPipeline.addLast(handlerName, SWALLOW_EXCEPTION_HANDLER); } }
/** * Most operations we want to do even if the channel is not active, because if it's not, then we want to encounter * the error that occurs when that operation happens and so that it can be passed up to the user. However, removing * handlers should only be done if the channel is active, because the error that is encountered when they aren't * makes no sense to the user (NoSuchElementException). */ private void removeHandlerIfActive(ChannelHandlerContext ctx, String name) { if (ctx.channel().isActive()) { ChannelPipeline pipeline = ctx.pipeline(); ChannelHandler handler = pipeline.get(name); if (handler != null) { pipeline.remove(name); } } }
/** * Finds the {@link SSLSession} of the current TLS connection. * * @return the {@link SSLSession} if found, or {@code null} if not found or {@link Channel} is {@code null}. */ @Nullable public static SSLSession findSslSession(@Nullable Channel channel) { if (channel == null) { return null; } final SslHandler sslHandler = channel.pipeline().get(SslHandler.class); return sslHandler != null ? sslHandler.engine().getSession() : null; }
public void addLoggingHandler(ChannelHandlerContext ctx) { if (ctx.pipeline().get(LoggingHandler.class) != null) { ctx.pipeline().remove(LoggingHandler.class); } if (ctx.pipeline().get(SslHandler.class) != null) { ctx.pipeline().addAfter("SslHandler#0", "LoggingHandler#0", this); } else { ctx.pipeline().addFirst(this); } }