Home / Class/ ReentryWriteSslHandshakeHandler Class — netty Architecture

ReentryWriteSslHandshakeHandler Class — netty Architecture

Architecture documentation for the ReentryWriteSslHandshakeHandler class in ParameterizedSslHandlerTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  fbe5a904_e2f4_3f60_ff77_a8aa6a453d31["ReentryWriteSslHandshakeHandler"]
  04d6489a_517f_c099_10e5_988a66a162f9["ParameterizedSslHandlerTest.java"]
  fbe5a904_e2f4_3f60_ff77_a8aa6a453d31 -->|defined in| 04d6489a_517f_c099_10e5_988a66a162f9
  dc0bc1ef_d695_bbae_02e4_2f07fe2fb723["ReentryWriteSslHandshakeHandler()"]
  fbe5a904_e2f4_3f60_ff77_a8aa6a453d31 -->|method| dc0bc1ef_d695_bbae_02e4_2f07fe2fb723
  dfc8d6f8_b5a6_5bd0_bfcf_d19c2901fc35["channelActive()"]
  fbe5a904_e2f4_3f60_ff77_a8aa6a453d31 -->|method| dfc8d6f8_b5a6_5bd0_bfcf_d19c2901fc35
  04755b28_4cb7_ae25_abb5_9f33152726a9["channelRead0()"]
  fbe5a904_e2f4_3f60_ff77_a8aa6a453d31 -->|method| 04755b28_4cb7_ae25_abb5_9f33152726a9
  34385cfd_5b94_5f19_20c9_139fe1185827["userEventTriggered()"]
  fbe5a904_e2f4_3f60_ff77_a8aa6a453d31 -->|method| 34385cfd_5b94_5f19_20c9_139fe1185827
  8012c2ef_ec06_9bdf_064e_3c1e7ba7f4b8["exceptionCaught()"]
  fbe5a904_e2f4_3f60_ff77_a8aa6a453d31 -->|method| 8012c2ef_ec06_9bdf_064e_3c1e7ba7f4b8
  f60ede47_5a49_014d_9440_53ed2959c4d1["appendError()"]
  fbe5a904_e2f4_3f60_ff77_a8aa6a453d31 -->|method| f60ede47_5a49_014d_9440_53ed2959c4d1

Relationship Graph

Source Code

handler/src/test/java/io/netty/handler/ssl/ParameterizedSslHandlerTest.java lines 629–691

    private static final class ReentryWriteSslHandshakeHandler extends SimpleChannelInboundHandler<ByteBuf> {
        private static final InternalLogger LOGGER =
                InternalLoggerFactory.getInstance(ReentryWriteSslHandshakeHandler.class);
        private final String toWrite;
        private final StringBuilder readQueue;
        private final CountDownLatch doneLatch;

        ReentryWriteSslHandshakeHandler(String toWrite, StringBuilder readQueue, CountDownLatch doneLatch) {
            this.toWrite = toWrite;
            this.readQueue = readQueue;
            this.doneLatch = doneLatch;
        }

        @Override
        public void channelActive(ChannelHandlerContext ctx) {
            // Write toWrite in two chunks, first here then we get SslHandshakeCompletionEvent (which is re-entry).
            ctx.writeAndFlush(writeAscii(ctx.alloc(), toWrite.substring(0, toWrite.length() / 2)));
        }

        @Override
        protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) {
            readQueue.append(msg.toString(CharsetUtil.US_ASCII));
            if (readQueue.length() >= toWrite.length()) {
                doneLatch.countDown();
            }
        }

        @Override
        public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
            if (evt instanceof SslHandshakeCompletionEvent) {
                SslHandshakeCompletionEvent sslEvt = (SslHandshakeCompletionEvent) evt;
                if (sslEvt.isSuccess()) {
                    // this is the re-entry write, it should be ordered after the subsequent write.
                    ctx.writeAndFlush(writeAscii(ctx.alloc(), toWrite.substring(toWrite.length() / 2)));
                } else {
                    appendError(sslEvt.cause());
                }
            }
            ctx.fireUserEventTriggered(evt);
        }

        @Override
        public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
            appendError(cause);
            ctx.fireExceptionCaught(cause);
        }

        private void appendError(Throwable cause) {
            LOGGER.error(new Exception("Caught possible write failure in ParameterizedSslHandlerTest.", cause));
            readQueue.append("failed to write '").append(toWrite).append("': ");

            ByteArrayOutputStream out = new ByteArrayOutputStream();
            try {
                cause.printStackTrace(new PrintStream(out));
                readQueue.append(out.toString(CharsetUtil.US_ASCII.name()));
            } catch (UnsupportedEncodingException ignore) {
                // Let's just fallback to using toString().
                readQueue.append(cause);
            } finally {
                doneLatch.countDown();
            }
        }
    }

Frequently Asked Questions

What is the ReentryWriteSslHandshakeHandler class?
ReentryWriteSslHandshakeHandler is a class in the netty codebase, defined in handler/src/test/java/io/netty/handler/ssl/ParameterizedSslHandlerTest.java.
Where is ReentryWriteSslHandshakeHandler defined?
ReentryWriteSslHandshakeHandler is defined in handler/src/test/java/io/netty/handler/ssl/ParameterizedSslHandlerTest.java at line 629.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free