Home / Function/ reentrantReadThenRemoveSafety() — netty Function Reference

reentrantReadThenRemoveSafety() — netty Function Reference

Architecture documentation for the reentrantReadThenRemoveSafety() function in ByteToMessageDecoderTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  57fadee4_a4df_d372_a731_64cc8bd2b464["reentrantReadThenRemoveSafety()"]
  b1c999fe_35fb_8b70_a958_296cffb0616a["ByteToMessageDecoderTest"]
  57fadee4_a4df_d372_a731_64cc8bd2b464 -->|defined in| b1c999fe_35fb_8b70_a958_296cffb0616a
  5082856a_b229_862d_0072_81f9b24f56a3["EmbeddedChannel()"]
  57fadee4_a4df_d372_a731_64cc8bd2b464 -->|calls| 5082856a_b229_862d_0072_81f9b24f56a3
  aa1df8f4_7da8_b487_8429_185255a151e0["read()"]
  57fadee4_a4df_d372_a731_64cc8bd2b464 -->|calls| aa1df8f4_7da8_b487_8429_185255a151e0
  style 57fadee4_a4df_d372_a731_64cc8bd2b464 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-base/src/test/java/io/netty/handler/codec/ByteToMessageDecoderTest.java lines 719–762

    @Test
    void reentrantReadThenRemoveSafety() throws Exception {
        EmbeddedChannel channel = new EmbeddedChannel();
        ByteToMessageDecoder decoder = new ByteToMessageDecoder() {
            boolean removed;
            int reentrancy;

            @Override
            protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
                assertFalse(removed);
                reentrancy++;
                if (reentrancy == 1) {
                    ByteBuf buf2 = channel.alloc().buffer();
                    buf2.writeLong(42); // Adding 8 bytes.
                    assertFalse(channel.writeInbound(buf2)); // Reentrant call back into ByteToMessageDecoder
                    ByteBuf buf3 = channel.alloc().buffer();
                    buf3.writeShort(42); // Adding 2 bytes.
                    assertFalse(channel.writeInbound(buf3)); // Reentrant call back into ByteToMessageDecoder
                    ctx.read();
                } else if (reentrancy == 2) {
                    ctx.pipeline().remove(this);
                }
                int bytes = in.readableBytes();
                out.add(bytes);
                in.skipBytes(bytes);
            }

            @Override
            protected void handlerRemoved0(ChannelHandlerContext ctx) throws Exception {
                removed = true;
            }
        };
        channel.pipeline().addLast(decoder);
        ByteBuf buf1 = channel.alloc().buffer();
        buf1.writeInt(42); // Adding 4 bytes.
        assertTrue(channel.writeInbound(buf1));
        Integer first = channel.readInbound();
        Integer second = channel.readInbound();
        Integer third = channel.readInbound();
        assertEquals(4, first);
        assertEquals(8, second);
        assertEquals(2, third);
        assertFalse(channel.finishAndReleaseAll());
    }

Domain

Subdomains

Frequently Asked Questions

What does reentrantReadThenRemoveSafety() do?
reentrantReadThenRemoveSafety() is a function in the netty codebase, defined in codec-base/src/test/java/io/netty/handler/codec/ByteToMessageDecoderTest.java.
Where is reentrantReadThenRemoveSafety() defined?
reentrantReadThenRemoveSafety() is defined in codec-base/src/test/java/io/netty/handler/codec/ByteToMessageDecoderTest.java at line 719.
What does reentrantReadThenRemoveSafety() call?
reentrantReadThenRemoveSafety() calls 2 function(s): EmbeddedChannel, read.

Analyze Your Own Codebase

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

Try Supermodel Free