cn.hutool.socket.aio.AcceptHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hutool-all Show documentation
Show all versions of hutool-all Show documentation
Hutool是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Java拥有函数式语言般的优雅,让Java语言也可以“甜甜的”。
package cn.hutool.socket.aio;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.channels.CompletionHandler;
import cn.hutool.log.StaticLog;
/**
* 接入完成回调,单例使用
*
* @author looly
*
*/
public class AcceptHandler implements CompletionHandler {
@Override
public void completed(AsynchronousSocketChannel socketChannel, AioServer aioServer) {
// 继续等待接入(异步)
aioServer.accept();
final IoAction ioAction = aioServer.ioAction;
// 创建Session会话
final AioSession session = new AioSession(socketChannel, ioAction, aioServer.config);
// 处理请求接入(同步)
ioAction.accept(session);
// 处理读(异步)
session.read();
}
@Override
public void failed(Throwable exc, AioServer aioServer) {
StaticLog.error(exc);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy