Class BinaryAwareRecvByteBufAllocator

java.lang.Object
org.mockserver.netty.unification.BinaryAwareRecvByteBufAllocator
All Implemented Interfaces:
io.netty.channel.MaxMessagesRecvByteBufAllocator, io.netty.channel.RecvByteBufAllocator

public final class BinaryAwareRecvByteBufAllocator extends Object implements io.netty.channel.MaxMessagesRecvByteBufAllocator
Sizes the buffer each read of an accepted connection is given: as the channel's own allocator does (adaptive, following recent reads down to 64 bytes) until the connection is found to be binary, then BINARY_READ_SIZE for every read, so that a binary message is not cut by a buffer that has followed small messages down. It also knows when the channel is inside a read loop. One instance per channel, installed before its first read: Netty takes the handle once, on that read, and the native transports wrap it, so only this object can be told, or asked.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface io.netty.channel.RecvByteBufAllocator

    io.netty.channel.RecvByteBufAllocator.DelegatingHandle, io.netty.channel.RecvByteBufAllocator.ExtendedHandle, io.netty.channel.RecvByteBufAllocator.Handle
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The largest buffer Netty's adaptive allocator grows to, so no read is larger than one it could already be.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    install(io.netty.channel.Channel channel)
    Wraps the channel's allocator.
    static boolean
    isReading(io.netty.channel.Channel channel)
    Whether the channel is inside a read loop: from its first read until just before its channelReadComplete.
    int
     
    io.netty.channel.MaxMessagesRecvByteBufAllocator
    maxMessagesPerRead(int maxMessagesPerRead)
     
    io.netty.channel.RecvByteBufAllocator.Handle
     
    static void
    readWholeMessages(io.netty.channel.Channel channel)
    Every later read of the channel is given BINARY_READ_SIZE.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • BINARY_READ_SIZE

      public static final int BINARY_READ_SIZE
      The largest buffer Netty's adaptive allocator grows to, so no read is larger than one it could already be.
      See Also:
  • Method Details

    • install

      public static void install(io.netty.channel.Channel channel)
      Wraps the channel's allocator. Has no effect on the reads of a channel that has already been read.
    • readWholeMessages

      public static void readWholeMessages(io.netty.channel.Channel channel)
      Every later read of the channel is given BINARY_READ_SIZE. Call on the channel's event loop.
    • isReading

      public static boolean isReading(io.netty.channel.Channel channel)
      Whether the channel is inside a read loop: from its first read until just before its channelReadComplete.
    • maxMessagesPerRead

      public int maxMessagesPerRead()
      Specified by:
      maxMessagesPerRead in interface io.netty.channel.MaxMessagesRecvByteBufAllocator
    • maxMessagesPerRead

      public io.netty.channel.MaxMessagesRecvByteBufAllocator maxMessagesPerRead(int maxMessagesPerRead)
      Specified by:
      maxMessagesPerRead in interface io.netty.channel.MaxMessagesRecvByteBufAllocator
    • newHandle

      public io.netty.channel.RecvByteBufAllocator.Handle newHandle()
      Specified by:
      newHandle in interface io.netty.channel.RecvByteBufAllocator