Class AioServer

java.lang.Object
org.miaixz.bus.socket.accord.AioServer

public final class AioServer extends Object
AIO服务端
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • AioServer

      public AioServer(int port, Protocol<T> protocol, Handler<T> handler)
      设置服务端启动必要参数配置
      Parameters:
      port - 绑定服务端口号
      protocol - 协议编解码
      handler - 消息处理器
    • AioServer

      public AioServer(String host, int port, Protocol<T> protocol, Handler<T> handler)
      Parameters:
      host - 绑定服务端Host地址
      port - 绑定服务端口号
      protocol - 协议编解码
      handler - 消息处理器
  • Method Details

    • start

      public void start() throws IOException
      启动Server端的AIO服务
      Throws:
      IOException - IO异常
    • start

      public void start(AsynchronousChannelGroup asynchronousChannelGroup) throws IOException
      内部启动逻辑
      Throws:
      IOException - IO异常
    • shutdown

      public void shutdown()
      停止服务端
    • setReadBufferSize

      public AioServer setReadBufferSize(int size)
      设置读缓存区大小
      Parameters:
      size - 单位:byte
      Returns:
      当前AioServer对象
    • setOption

      public <V> AioServer setOption(SocketOption<V> socketOption, V value)
      设置Socket的TCP参数配置。

      AIO客户端的有效可选范围为:
      2. StandardSocketOptions.SO_RCVBUF
      4. StandardSocketOptions.SO_REUSEADDR

      Type Parameters:
      V - 配置项类型
      Parameters:
      socketOption - 配置项
      value - 配置值
      Returns:
      当前AioServer对象
    • setThreadNum

      public AioServer setThreadNum(int threadNum)
      设置服务工作线程数,设置数值必须大于等于2
      Parameters:
      threadNum - 线程数
      Returns:
      当前AioServer对象
    • setWriteBuffer

      public AioServer setWriteBuffer(int bufferSize, int bufferCapacity)
      设置输出缓冲区容量
      Parameters:
      bufferSize - 单个内存块大小
      bufferCapacity - 内存块数量上限
      Returns:
      当前AioServer对象
    • setBacklog

      public AioServer setBacklog(int backlog)
      设置 backlog 大小
      Parameters:
      backlog - backlog大小
      Returns:
      当前AioServer对象
    • setBufferPagePool

      public AioServer setBufferPagePool(BufferPagePool bufferPool)
      设置内存池。 通过该方法设置的内存池,在AioServer执行shutdown时不会触发内存池的释放。 该方法适用于多个AioServer、AioClient共享内存池的场景。 在启用内存池的情况下会有更好的性能表现
      Parameters:
      bufferPool - 内存池对象
      Returns:
      当前AioServer对象
    • setBufferFactory

      public AioServer setBufferFactory(BufferFactory bufferFactory)
      设置内存池的构造工厂。 通过工厂形式生成的内存池会强绑定到当前AioServer对象, 在AioServer执行shutdown时会释放内存池。 在启用内存池的情况下会有更好的性能表现
      Parameters:
      bufferFactory - 内存池工厂
      Returns:
      当前AioServer对象
    • setReadBufferFactory

      public AioServer setReadBufferFactory(VirtualBufferFactory readBufferFactory)
    • setLowMemory

      public AioServer setLowMemory(boolean lowMemory)