T - 消息对象类型public class QuickAioClient<T> extends Object
| Constructor and Description |
|---|
QuickAioClient(String host,
int port,
Protocol<T> protocol,
MessageProcessor<T> messageProcessor)
当前构造方法设置了启动Aio客户端的必要参数,基本实现开箱即用。
|
| Modifier and Type | Method and Description |
|---|---|
QuickAioClient<T> |
bindLocal(String local,
int port)
绑定本机地址、端口用于连接远程服务
|
QuickAioClient<T> |
connectTimeout(int timeout)
客户端连接超时时间,单位:毫秒
|
QuickAioClient<T> |
setBufferFactory(BufferFactory bufferFactory)
设置内存池的构造工厂。
通过工厂形式生成的内存池会强绑定到当前AioQuickClient对象,
在AioQuickClient执行shutdown时会释放内存池。
在启用内存池的情况下会有更好的性能表现
|
<V> QuickAioClient<T> |
setOption(SocketOption<V> socketOption,
V value)
设置Socket的TCP参数配置
AIO客户端的有效可选范围为:
1.
|
QuickAioClient<T> |
setPageBufferPool(org.aoju.bus.core.io.ByteBuffer bufferPool)
设置内存池。
通过该方法设置的内存池,在AioQuickClient执行shutdown时不会触发内存池的释放。
该方法适用于多个AioQuickServer、AioQuickClient共享内存池的场景。
在启用内存池的情况下会有更好的性能表现
|
QuickAioClient<T> |
setReadBufferSize(int size)
设置读缓存区大小
|
QuickAioClient<T> |
setWriteBuffer(int bufferSize,
int bufferCapacity)
设置输出缓冲区容量
|
void |
shutdown()
停止客户端服务.
|
void |
shutdownNow()
立即关闭客户端
|
AioSession |
start()
启动客户端
本方法会构建线程数为2的
asynchronousChannelGroup,
并通过调用start(AsynchronousChannelGroup)启动服务 |
AioSession |
start(AsynchronousChannelGroup asynchronousChannelGroup)
启动客户端
在与服务端建立连接期间,该方法处于阻塞状态。直至连接建立成功,或者发生异常
该start方法支持外部指定AsynchronousChannelGroup,实现多个客户端共享一组线程池资源,有效提升资源利用率。
|
public QuickAioClient(String host, int port, Protocol<T> protocol, MessageProcessor<T> messageProcessor)
host - 远程服务器地址port - 远程服务器端口号protocol - 协议编解码messageProcessor - 消息处理器public AioSession start(AsynchronousChannelGroup asynchronousChannelGroup) throws IOException
asynchronousChannelGroup - IO事件处理线程组IOException - IOExceptionAsynchronousSocketChannel.connect(SocketAddress)public final AioSession start() throws IOException
asynchronousChannelGroup,
并通过调用start(AsynchronousChannelGroup)启动服务IOException - IOExceptionstart(AsynchronousChannelGroup)public final void shutdown()
调用该方法会触发AioSession的close方法,并且如果当前客户端若是通过执行start()方法构建的,同时会触发asynchronousChannelGroup的shutdown动作。
public final void shutdownNow()
public final QuickAioClient<T> setReadBufferSize(int size)
size - 单位:bytepublic final <V> QuickAioClient<T> setOption(SocketOption<V> socketOption, V value)
V - 泛型socketOption - 配置项value - 配置值public final QuickAioClient<T> bindLocal(String local, int port)
local - 若传null则由系统自动获取port - 若传0则由系统指定public final QuickAioClient<T> setPageBufferPool(org.aoju.bus.core.io.ByteBuffer bufferPool)
bufferPool - 内存池对象public final QuickAioClient<T> setBufferFactory(BufferFactory bufferFactory)
bufferFactory - 内存池工厂public final QuickAioClient<T> setWriteBuffer(int bufferSize, int bufferCapacity)
bufferSize - 单个内存块大小bufferCapacity - 内存块数量上限public final QuickAioClient<T> connectTimeout(int timeout)
timeout - 超时时间Copyright © 2021. All rights reserved.