Home / Class/ BufWriterHandler Class — netty Architecture

BufWriterHandler Class — netty Architecture

Architecture documentation for the BufWriterHandler class in SocketBufReleaseTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  7e7bcffa_1366_f855_41f4_cb373829b03f["BufWriterHandler"]
  f4640247_5a36_f487_b958_3736a087ee21["SocketBufReleaseTest.java"]
  7e7bcffa_1366_f855_41f4_cb373829b03f -->|defined in| f4640247_5a36_f487_b958_3736a087ee21
  b7f8052c_cddb_7b41_3b69_420d2bb4190a["handlerAdded()"]
  7e7bcffa_1366_f855_41f4_cb373829b03f -->|method| b7f8052c_cddb_7b41_3b69_420d2bb4190a
  8b4c0973_77f3_6035_baf5_17a24f076d11["channelActive()"]
  7e7bcffa_1366_f855_41f4_cb373829b03f -->|method| 8b4c0973_77f3_6035_baf5_17a24f076d11
  615a1bb2_a6d0_4ab4_21f0_6b063b91e90d["channelRead0()"]
  7e7bcffa_1366_f855_41f4_cb373829b03f -->|method| 615a1bb2_a6d0_4ab4_21f0_6b063b91e90d
  ceafdf0c_bf09_ce54_1989_fc1e14f33800["check()"]
  7e7bcffa_1366_f855_41f4_cb373829b03f -->|method| ceafdf0c_bf09_ce54_1989_fc1e14f33800
  87fb42cc_cb9a_4303_8ed8_0dd8934e5bb1["release()"]
  7e7bcffa_1366_f855_41f4_cb373829b03f -->|method| 87fb42cc_cb9a_4303_8ed8_0dd8934e5bb1

Relationship Graph

Source Code

testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketBufReleaseTest.java lines 76–113

    private static class BufWriterHandler extends SimpleChannelInboundHandler<Object> {

        private final Random random = new Random();
        private final CountDownLatch latch = new CountDownLatch(1);
        private ByteBuf buf;
        private final Promise<Channel> channelFuture = new DefaultPromise<Channel>(executor);

        @Override
        public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
            channelFuture.setSuccess(ctx.channel());
        }

        @Override
        public void channelActive(final ChannelHandlerContext ctx) throws Exception {
            byte[] data = new byte[1024];
            random.nextBytes(data);

            buf = ctx.alloc().buffer();
            // call retain on it so it can't be put back on the pool
            buf.writeBytes(data).retain();

            ctx.channel().writeAndFlush(buf).addListener(future -> latch.countDown());
        }

        @Override
        public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
            // discard
        }

        public void check() throws InterruptedException {
            latch.await();
            assertEquals(1, buf.refCnt());
        }

        void release() {
            buf.release();
        }
    }

Frequently Asked Questions

What is the BufWriterHandler class?
BufWriterHandler is a class in the netty codebase, defined in testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketBufReleaseTest.java.
Where is BufWriterHandler defined?
BufWriterHandler is defined in testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketBufReleaseTest.java at line 76.

Analyze Your Own Codebase

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

Try Supermodel Free