java.lang.Object
org.miaixz.bus.socket.Session
org.miaixz.bus.socket.accord.TcpSession
AIO传输层会话
Session为最核心的类,封装AsynchronousSocketChannel API接口,简化IO操作。
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Field Summary
Fields inherited from class org.miaixz.bus.socket.Session
eof, modCount, SESSION_STATUS_CLOSED, SESSION_STATUS_CLOSING, SESSION_STATUS_ENABLED, status -
Constructor Summary
ConstructorsConstructorDescriptionTcpSession(AsynchronousSocketChannel channel, Context context, BufferPage writeBufferPage, Supplier<VirtualBuffer> readBufferSupplier) -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidclose(boolean immediate) 是否立即关闭会话获得数据输入流对象。getInputStream(int length) 获取已知长度的InputStream获取当前会话的本地连接地址获取当前会话的远程连接地址获取读缓冲区对象void触发通道的读回调操作获取WriteBuffer用以数据输出Methods inherited from class org.miaixz.bus.socket.Session
close, getAttachment, getSessionID, isInvalid, setAttachment
-
Constructor Details
-
TcpSession
public TcpSession(AsynchronousSocketChannel channel, Context context, BufferPage writeBufferPage, Supplier<VirtualBuffer> readBufferSupplier) - Parameters:
channel- Socket通道
-
-
Method Details
-
close
public void close(boolean immediate) 是否立即关闭会话 -
writeBuffer
Description copied from class:Session获取WriteBuffer用以数据输出- Specified by:
writeBufferin classSession- Returns:
- 输入流
-
readBuffer
Description copied from class:Session获取读缓冲区对象- Specified by:
readBufferin classSession
-
awaitRead
public void awaitRead() -
signalRead
public void signalRead()触发通道的读回调操作- Specified by:
signalReadin classSession
-
getLocalAddress
Description copied from class:Session获取当前会话的本地连接地址- Specified by:
getLocalAddressin classSession- Returns:
- 本地地址
- Throws:
IOException- IO异常- See Also:
-
getRemoteAddress
Description copied from class:Session获取当前会话的远程连接地址- Specified by:
getRemoteAddressin classSession- Returns:
- 远程地址
- Throws:
IOException- IO异常- See Also:
-
getInputStream
获得数据输入流对象。faster模式下调用该方法会触发UnsupportedOperationException异常。 Handler采用异步处理消息的方式时,调用该方法可能会出现异常。
- Overrides:
getInputStreamin classSession- Returns:
- 同步读操作的流对象
- Throws:
IOException- io异常
-
getInputStream
获取已知长度的InputStream- Overrides:
getInputStreamin classSession- Parameters:
length- InputStream长度- Returns:
- 同步读操作的流对象
- Throws:
IOException- io异常
-