public final class AioQuickServer extends Object
public class IntegerServer {
public static void main(String[] args) throws IOException {
AioQuickServer server = new AioQuickServer(8888, new IntegerProtocol(), new IntegerServerProcessor());
server.start();
}
}
| 构造器和说明 |
|---|
AioQuickServer(int port,
Protocol<T> protocol,
MessageProcessor<T> messageProcessor)
设置服务端启动必要参数配置
|
AioQuickServer(String host,
int port,
Protocol<T> protocol,
MessageProcessor<T> messageProcessor) |
| 限定符和类型 | 方法和说明 |
|---|---|
AioQuickServer |
setBacklog(int backlog)
设置 backlog 大小
|
AioQuickServer |
setBannerEnabled(boolean bannerEnabled)
是否启用控制台Banner打印
|
AioQuickServer |
setBufferFactory(BufferFactory bufferFactory)
设置内存池的构造工厂。
|
AioQuickServer |
setBufferPagePool(BufferPagePool bufferPool)
设置内存池。
|
AioQuickServer |
setLowMemory(boolean lowMemory) |
<V> AioQuickServer |
setOption(SocketOption<V> socketOption,
V value)
设置Socket的TCP参数配置。
|
AioQuickServer |
setReadBufferFactory(VirtualBufferFactory readBufferFactory) |
AioQuickServer |
setReadBufferSize(int size)
设置读缓存区大小
|
AioQuickServer |
setThreadNum(int threadNum)
设置服务工作线程数,设置数值必须大于等于2
|
AioQuickServer |
setWriteBuffer(int bufferSize,
int bufferCapacity)
设置输出缓冲区容量
|
void |
shutdown()
停止服务端
|
void |
start()
启动Server端的AIO服务
|
void |
start(AsynchronousChannelGroup asynchronousChannelGroup)
内部启动逻辑
|
public AioQuickServer(int port,
Protocol<T> protocol,
MessageProcessor<T> messageProcessor)
port - 绑定服务端口号protocol - 协议编解码messageProcessor - 消息处理器public AioQuickServer(String host, int port, Protocol<T> protocol, MessageProcessor<T> messageProcessor)
host - 绑定服务端Host地址port - 绑定服务端口号protocol - 协议编解码messageProcessor - 消息处理器public void start()
throws IOException
IOException - IO异常public void start(AsynchronousChannelGroup asynchronousChannelGroup) throws IOException
IOException - IO异常public void shutdown()
public final AioQuickServer setReadBufferSize(int size)
size - 单位:bytepublic final AioQuickServer setBannerEnabled(boolean bannerEnabled)
bannerEnabled - true:启用,false:禁用public final <V> AioQuickServer setOption(SocketOption<V> socketOption, V value)
AIO客户端的有效可选范围为:
2. StandardSocketOptions.SO_RCVBUF
4. StandardSocketOptions.SO_REUSEADDR
V - 配置项类型socketOption - 配置项value - 配置值public final AioQuickServer setThreadNum(int threadNum)
threadNum - 线程数public final AioQuickServer setWriteBuffer(int bufferSize, int bufferCapacity)
bufferSize - 单个内存块大小bufferCapacity - 内存块数量上限public final AioQuickServer setBacklog(int backlog)
backlog - backlog大小public final AioQuickServer setBufferPagePool(BufferPagePool bufferPool)
bufferPool - 内存池对象public final AioQuickServer setBufferFactory(BufferFactory bufferFactory)
bufferFactory - 内存池工厂public final AioQuickServer setReadBufferFactory(VirtualBufferFactory readBufferFactory)
public AioQuickServer setLowMemory(boolean lowMemory)
Copyright © 2023. All rights reserved.