This commit is contained in:
hyl
2020-07-27 10:32:24 +08:00
parent 28c9801566
commit 7e4640804a
2 changed files with 14 additions and 66 deletions

View File

@@ -105,7 +105,6 @@ public abstract class NioClient implements Closeable {
this.executorService = Executors.newSingleThreadExecutor(r -> {
final Thread thread = Executors.defaultThreadFactory().newThread(r);
thread.setName("nio-client-listen");
thread.setDaemon(true);
return thread;
});
this.executorService.execute(() -> {
@@ -139,13 +138,6 @@ public abstract class NioClient implements Closeable {
* @param key SelectionKey
*/
private void handle(SelectionKey key) throws IOException {
//连接建立完成
// if (key.isConnectable()) {
// if (this.channel.finishConnect()) {
// this.channel.register(selector, SelectionKey.OP_READ);
// }
// }
// 读事件就绪
if (key.isReadable()) {
final SocketChannel socketChannel = (SocketChannel) key.channel();
@@ -161,22 +153,6 @@ public abstract class NioClient implements Closeable {
*/
protected abstract void read(SocketChannel socketChannel);
/**
* 处理读事件<br>
* 当收到读取准备就绪的信号后,回调此方法,用户可读取从客户端传世来的消息
*
* @param buffer 服务端数据存储缓存
* @return this
*/
public NioClient read(ByteBuffer buffer) {
try {
this.channel.read(buffer);
} catch (IOException e) {
throw new IORuntimeException(e);
}
return this;
}
/**
* 实现写逻辑<br>
* 当收到写出准备就绪的信号后,回调此方法,用户可向客户端发送消息