public abstract class SocketContext<C extends SelectableChannel,S extends IoSession> extends PooledObject
Modifier and Type | Field and Description |
---|---|
static int |
ACCEPT_THREAD_SIZE |
static boolean |
ASYNC_RECIVE |
static boolean |
ASYNC_SEND |
static Boolean |
CHECK_TIMEOUT |
static EventRunnerGroup |
COMMON_ACCEPT_EVENT_RUNNER_GROUP |
static EventRunnerGroup |
COMMON_IO_EVENT_RUNNER_GROUP |
protected ConnectModel |
connectModel |
protected ConnectType |
connectType |
protected Chain<IoFilter> |
filterChain |
protected IoHandler |
handler |
protected String |
host |
protected int |
idleInterval |
static int |
IO_THREAD_SIZE |
protected boolean |
isSynchronous |
protected long |
lastReadTime |
protected MessageSplitter |
messageSplitter |
protected int |
port |
protected int |
readBufferSize |
protected int |
readTimeout |
protected Chain<IoFilter> |
reciveFilterChain |
static int |
SELECT_INTERVAL |
protected int |
sendBufferSize |
protected Chain<IoFilter> |
sendFilterChain |
protected int |
sendTimeout |
protected SSLManager |
sslManager |
Modifier | Constructor and Description |
---|---|
protected |
SocketContext()
无参数构造函数
|
|
SocketContext(String host,
int port,
int readTimeout)
构造函数
默认不会出发空闲事件, 默认发超时时间: 1s
|
|
SocketContext(String host,
int port,
int readTimeout,
int idleInterval)
构造函数
默认发超时时间: 1s
|
|
SocketContext(String host,
int port,
int readTimeout,
int sendTimeout,
int idleInterval)
构造函数
|
Modifier and Type | Method and Description |
---|---|
protected abstract void |
acceptStart()
用于针对 Accept 进来的 Socket 连接的启动
|
void |
bindToSocketSelector(int ops)
绑定到 SocketSelector
|
abstract boolean |
close()
关闭连接
|
protected void |
copyFrom(SocketContext parentSocketContext)
克隆对象
|
static EventRunnerGroup |
createEventRunnerGroup(String name,
int size,
boolean isAccept)
构造事件管理器
|
Chain<IoFilter> |
filterChain()
获取过滤器链
|
EventRunnerGroup |
getAcceptEventRunnerGroup() |
static EventRunnerGroup |
getCommonAcceptEventRunnerGroup()
获取公共的 Accept 事件执行器
|
static EventRunnerGroup |
getCommonIoEventRunnerGroup()
获取公共的 IO 事件执行器
|
ConnectModel |
getConnectModel()
获取连接模式
|
ConnectType |
getConnectType()
获取连接类型
|
String |
getHost()
获取主机地址
|
int |
getIdleInterval()
获取空闲事件时间
|
EventRunnerGroup |
getIoEventRunnerGroup() |
long |
getLastReadTime() |
int |
getPort()
获取主机端口
|
int |
getReadBufferSize()
会话读缓冲区大小
|
int |
getReadTimeout()
获取超时时间
|
protected Chain<IoFilter> |
getReciveFilterChain() |
int |
getSendBufferSize()
会话写缓冲区大小
|
protected Chain<IoFilter> |
getSendFilterChain() |
int |
getSendTimeout() |
abstract S |
getSession() |
SSLManager |
getSSLManager()
获取 SSL 管理器
|
static void |
gracefulShutdown()
平滑的关闭 Socket 线程池
|
IoHandler |
handler()
获取业务处理句柄
|
void |
handler(IoHandler handler)
设置业务处理句柄
|
protected void |
initSSL(IoSession session) |
abstract boolean |
isConnected()
上下文连接是否连接
|
abstract boolean |
isOpen()
上下文连接是否打开
|
boolean |
isRegister() |
boolean |
isTimeOut() |
MessageSplitter |
messageSplitter()
获取消息粘包分割器
|
void |
messageSplitter(MessageSplitter messageSplitter)
设置消息粘包分割器
|
void |
setAcceptEventRunnerGroup(EventRunnerGroup acceptEventRunnerGroup) |
abstract void |
setIdleInterval(int idleInterval)
设置空闲事件时间
|
void |
setIoEventRunnerGroup(EventRunnerGroup ioEventRunnerGroup) |
abstract <T> void |
setOption(SocketOption<T> name,
T value)
设置 Socket 的 Option 选项
|
void |
setReadBufferSize(int readBufferSize)
设置会话读缓冲区大小
|
protected void |
setRegister(boolean register) |
void |
setSendBufferSize(int sendBufferSize)
设置会话写缓冲区大小
|
void |
setSSLManager(SSLManager sslManager)
设置 SSL 管理器
|
abstract C |
socketChannel()
获取 SocketChannel 对象
|
abstract void |
start()
启动上下文连接
阻塞方法
|
abstract void |
syncStart()
启动同步的上下文连接
非阻塞方法
|
void |
updateLastTime() |
void |
waitConnect()
等待连接完成, 包含事件注册和 SSL 握手, 用于在同步调用的方法中同步
|
getPoolObjectId, setPoolObjectId
public static int ACCEPT_THREAD_SIZE
public static int IO_THREAD_SIZE
public static final int SELECT_INTERVAL
public static final Boolean CHECK_TIMEOUT
public static final boolean ASYNC_SEND
public static final boolean ASYNC_RECIVE
public static EventRunnerGroup COMMON_ACCEPT_EVENT_RUNNER_GROUP
public static EventRunnerGroup COMMON_IO_EVENT_RUNNER_GROUP
protected String host
protected int port
protected int readTimeout
protected int sendTimeout
protected IoHandler handler
protected MessageSplitter messageSplitter
protected SSLManager sslManager
protected ConnectModel connectModel
protected ConnectType connectType
protected int readBufferSize
protected int sendBufferSize
protected int idleInterval
protected long lastReadTime
protected boolean isSynchronous
public SocketContext(String host, int port, int readTimeout)
host
- 主机地址port
- 主机端口readTimeout
- 超时时间public SocketContext(String host, int port, int readTimeout, int idleInterval)
host
- 主机地址port
- 主机端口readTimeout
- 读超时时间, 单位: 毫秒idleInterval
- 空闲事件触发时间public SocketContext(String host, int port, int readTimeout, int sendTimeout, int idleInterval)
host
- 主机地址port
- 主机端口readTimeout
- 读超时时间, 单位: 毫秒sendTimeout
- 发超时时间, 单位: 毫秒idleInterval
- 空闲事件触发时间protected SocketContext()
public static EventRunnerGroup createEventRunnerGroup(String name, int size, boolean isAccept)
name
- 事件执行器名称size
- 容纳事件执行器的数量isAccept
- 是否处理 Accept 事件public static EventRunnerGroup getCommonAcceptEventRunnerGroup()
public static EventRunnerGroup getCommonIoEventRunnerGroup()
public EventRunnerGroup getAcceptEventRunnerGroup()
public void setAcceptEventRunnerGroup(EventRunnerGroup acceptEventRunnerGroup)
public EventRunnerGroup getIoEventRunnerGroup()
public void setIoEventRunnerGroup(EventRunnerGroup ioEventRunnerGroup)
protected void initSSL(IoSession session) throws SSLException
SSLException
protected void copyFrom(SocketContext parentSocketContext)
parentSocketContext
- 父 socket 对象public int getIdleInterval()
public abstract void setIdleInterval(int idleInterval)
idleInterval
- 空闲事件时间, 单位:秒public abstract <T> void setOption(SocketOption<T> name, T value) throws IOException
T
- 范型name
- SocketOption类型的枚举, 参照:AsynchronousSocketChannel.setOption的说明value
- SocketOption参数IOException
- IO异常public abstract C socketChannel()
public long getLastReadTime()
public void updateLastTime()
public boolean isTimeOut()
public int getReadBufferSize()
public void setReadBufferSize(int readBufferSize)
readBufferSize
- 读缓冲区大小public int getSendBufferSize()
public void setSendBufferSize(int sendBufferSize)
sendBufferSize
- 读缓冲区大小public boolean isRegister()
protected void setRegister(boolean register)
public SSLManager getSSLManager()
public void setSSLManager(SSLManager sslManager)
sslManager
- SSL 管理器public String getHost()
public int getPort()
public int getReadTimeout()
public int getSendTimeout()
public ConnectModel getConnectModel()
public ConnectType getConnectType()
public IoHandler handler()
public void handler(IoHandler handler)
handler
- 业务处理句柄public MessageSplitter messageSplitter()
public void messageSplitter(MessageSplitter messageSplitter)
messageSplitter
- 消息分割器public abstract S getSession()
public abstract void start() throws IOException
IOException
- IO 异常public abstract void syncStart() throws IOException
IOException
- IO异常protected abstract void acceptStart() throws IOException
IOException
- IO异常public abstract boolean isOpen()
public abstract boolean isConnected()
public abstract boolean close()
public void waitConnect()
public void bindToSocketSelector(int ops)
ops
- 选择的操作类型public static void gracefulShutdown()
Copyright © 2020 Voovan. All rights reserved.