public class AioQuickClient<T> extends Object
| Modifier and Type | Field and Description |
|---|---|
protected BufferPool |
bufferPool |
protected org.aoju.bus.socket.origin.ServerConfig<T> |
config
客户端服务配置
调用AioQuickClient的各setXX()方法,都是为了设置config的各配置项
|
protected org.aoju.bus.socket.origin.TcpAioSession<T> |
session
网络连接的会话对象
|
| Constructor and Description |
|---|
AioQuickClient(String host,
int port,
Protocol<T> protocol,
Message<T> messageProcessor)
当前构造方法设置了启动Aio客户端的必要参数,基本实现开箱即用
|
| Modifier and Type | Method and Description |
|---|---|
AioQuickClient<T> |
bindLocal(String local,
int port)
绑定本机地址、端口用于连接远程服务
|
AioQuickClient<T> |
setBufferPagePool(BufferPool bufferPool) |
<V> AioQuickClient<T> |
setOption(SocketOption<V> socketOption,
V value)
设置Socket的TCP参数配置
AIO客户端的有效可选范围为:
1.
|
AioQuickClient<T> |
setReadBufferSize(int size)
设置读缓存区大小
|
AioQuickClient<T> |
setWriteQueueCapacity(int writeQueueCapacity)
设置write缓冲区容量
|
void |
shutdown()
停止客户端服务.
|
void |
shutdownNow()
立即关闭客户端
|
AioSession<T> |
start()
启动客户端
本方法会构建线程数为2的
asynchronousChannelGroup, 并通过调用
start(AsynchronousChannelGroup)启动服务 |
AioSession<T> |
start(AsynchronousChannelGroup asynchronousChannelGroup)
启动客户端
在与服务端建立连接期间,该方法处于阻塞状态 直至连接建立成功,或者发生异常
该start方法支持外部指定AsynchronousChannelGroup,实现多个客户端共享一组线程池资源,有效提升资源利用率
|
protected org.aoju.bus.socket.origin.ServerConfig<T> config
protected org.aoju.bus.socket.origin.TcpAioSession<T> session
TcpAioSessionprotected BufferPool bufferPool
public AioSession<T> start(AsynchronousChannelGroup asynchronousChannelGroup) throws IOException, ExecutionException, InterruptedException
asynchronousChannelGroup - IO事件处理线程组IOException - 异常ExecutionException - 异常InterruptedException - 异常AsynchronousSocketChannel.connect(SocketAddress)public final AioSession<T> start() throws IOException, ExecutionException, InterruptedException
asynchronousChannelGroup, 并通过调用
start(AsynchronousChannelGroup)启动服务IOException - 异常ExecutionException - 异常InterruptedException - 异常start(AsynchronousChannelGroup)public final void shutdown()
start()方法构建的,
同时会触发asynchronousChannelGroup的shutdown动作public final void shutdownNow()
public final AioQuickClient<T> setReadBufferSize(int size)
size - 单位:bytepublic final <V> AioQuickClient<T> setOption(SocketOption<V> socketOption, V value)
V - 对象socketOption - 配置项value - 配置值public final AioQuickClient<T> bindLocal(String local, int port)
local - 若传null则由系统自动获取port - 若传0则由系统指定public final AioQuickClient<T> setBufferPagePool(BufferPool bufferPool)
public final AioQuickClient<T> setWriteQueueCapacity(int writeQueueCapacity)
writeQueueCapacity - 缓冲区大小Copyright © 2020. All rights reserved.