public abstract class IoSession<T extends SocketContext> extends Attributes
Modifier and Type | Class and Description |
---|---|
class |
IoSession.State
会话状态管理
|
Modifier and Type | Field and Description |
---|---|
protected ByteBufferChannel |
readByteBufferChannel |
protected ByteBufferChannel |
sendByteBufferChannel |
static HashWheelTimer |
SOCKET_IDLE_WHEEL_TIME |
Modifier and Type | Method and Description |
---|---|
void |
cancelIdle()
停止空闲事件触发
|
void |
checkIdle()
启动空闲事件触发
|
abstract boolean |
close()
关闭会话
|
void |
flush()
推送缓冲区的数据到 socketChannel
|
Object |
getAttachment() |
protected EventRunner |
getEventRunner()
获取 Event 执行器
|
HeartBeat |
getHeartBeat()
获取心跳对象
|
int |
getIdleInterval()
获取空闲事件时间
|
static HashWheelTimer |
getIdleWheelTimer() |
MessageLoader |
getMessageLoader()
获取消息处理类
|
protected abstract MessageSplitter |
getMessageSplitter()
获取消息分割处理类
|
ByteBufferChannel |
getReadByteBufferChannel()
获取读取缓冲区
|
protected SelectionKey |
getSelectionKey()
获取 SelectionKey
|
ByteBufferChannel |
getSendByteBufferChannel()
获取发送缓冲区
|
SocketSelector |
getSocketSelector()
获取 Socket 选择器
|
SSLParser |
getSSLParser()
获取 SSLParser
|
IoSession.State |
getState()
获取状态
|
abstract boolean |
isConnected()
会话是否连接
|
abstract boolean |
isOpen()
会话是否打开
|
boolean |
isSSLMode() |
abstract int |
loaclPort()
获取本地端口
|
abstract String |
localAddress()
获取本地 IP 地址
|
int |
read(ByteBuffer byteBuffer)
直接从缓冲区读取数据
|
protected int |
read0()
读取消息到缓冲区
|
void |
release() |
abstract String |
remoteAddress()
获取对端 IP 地址
|
abstract int |
remotePort()
获取对端端口
|
int |
send(ByteBuffer buffer)
直接向缓冲区发送消息
注意直接调用不会触发 onSent 事件, 也不会经过任何过滤器
|
protected int |
send0(ByteBuffer buffer)
发送消息到 JVM 的 SocketChannel
注意直接调用不会出发 onSent 事件
|
protected int |
sendToBuffer(ByteBuffer buffer)
发送消息到发送缓冲区
|
void |
setAttachment(Object attachment) |
void |
setIdleInterval(int idleInterval)
设置空闲事件时间
|
protected void |
setSocketSelector(SocketSelector socketSelector)
设置 Socket 选择器
|
protected void |
setSSLParser(SSLParser sslParser)
获取 SSLParser
|
T |
socketContext()
获取 socket 连接上下文
|
Object |
syncRead()
同步读取消息
消息会经过 filter 的 decoder 函数处理后再返回
|
void |
syncSend(Object obj)
同步发送消息
消息会经过 filter 的 encoder 函数处理后再发送
|
abstract String |
toString() |
attributes, clearAttribute, containAttribute, getAttribute, isModifyed, removeAttribute, setAttribute, setModifyed
public static HashWheelTimer SOCKET_IDLE_WHEEL_TIME
protected ByteBufferChannel readByteBufferChannel
protected ByteBufferChannel sendByteBufferChannel
public IoSession(T socketContext)
socketContext
- socketContext对象public static HashWheelTimer getIdleWheelTimer()
public Object getAttachment()
public void setAttachment(Object attachment)
public SocketSelector getSocketSelector()
protected void setSocketSelector(SocketSelector socketSelector)
socketSelector
- Socket 选择器protected EventRunner getEventRunner()
protected SelectionKey getSelectionKey()
public HeartBeat getHeartBeat()
public IoSession.State getState()
public void checkIdle()
public void cancelIdle()
public int getIdleInterval()
public void setIdleInterval(int idleInterval)
idleInterval
- 空闲事件时间public ByteBufferChannel getReadByteBufferChannel()
public ByteBufferChannel getSendByteBufferChannel()
public SSLParser getSSLParser()
protected void setSSLParser(SSLParser sslParser)
sslParser
- SSL解析对象public boolean isSSLMode()
public abstract String localAddress()
public abstract int loaclPort()
public abstract String remoteAddress()
public abstract int remotePort()
public T socketContext()
protected int read0() throws IOException
IOException
- IO 异常public int read(ByteBuffer byteBuffer) throws IOException
byteBuffer
- 字节缓冲对象ByteBuffer,读取 前需要使用 enabledMessageSpliter(false) 停止分割器的工作,除非有特殊的需求.IOException
- IO异常public Object syncRead() throws ReadMessageException
ReadMessageException
- 读取消息异常protected int send0(ByteBuffer buffer)
buffer
- 发送缓冲区protected int sendToBuffer(ByteBuffer buffer)
buffer
- 发送到缓冲区的 ByteBuffer 对象public void syncSend(Object obj) throws SendMessageException
obj
- 要发送的对象SendMessageException
- 消息发送异常public int send(ByteBuffer buffer)
buffer
- byte缓冲区public void flush()
public MessageLoader getMessageLoader()
protected abstract MessageSplitter getMessageSplitter()
public abstract boolean isConnected()
public abstract boolean isOpen()
public abstract boolean close()
public void release()
Copyright © 2020 Voovan. All rights reserved.