Module bus.socket

Class AioServer

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

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

    • AioServer

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

      public AioServer(String host, int port, Message<T> message, Handler<T> handler)
      Parameters:
      host - 绑定服务端Host地址
      port - 绑定服务端口号
      message - 协议编解码
      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:
      this
    • 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:
      this
    • setThreadNum

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

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

      public final AioServer setBacklog(int backlog)
      设置 backlog 大小
      Parameters:
      backlog - backlog大小
      Returns:
      this
    • setBufferPagePool

      public AioServer setBufferPagePool(BufferPagePool bufferPool)
      设置读写内存池。 该方法适用于多个AioQuickServer、AioQuickClient共享内存池的场景, 以获得更好的性能表现
      Parameters:
      bufferPool - 内存池对象
      Returns:
      this
    • setBufferPagePool

      public AioServer setBufferPagePool(BufferPagePool readBufferPool, BufferPagePool writeBufferPool)
      设置读写内存池。 该方法适用于多个AioQuickServer、AioQuickClient共享内存池的场景, 以获得更好的性能表现
      Parameters:
      readBufferPool - 读内存池对象
      writeBufferPool - 写内存池对象
      Returns:
      this
    • disableLowMemory

      public AioServer disableLowMemory()
      禁用低代码模式
      Returns:
      this