mirror of
https://github.com/Estom/notes.git
synced 2026-02-09 05:24:38 +08:00
Java内容重新整理删除过期的东西
This commit is contained in:
46
Java/JavaDemo/codedemo/reactor/ProcessService.java
Normal file
46
Java/JavaDemo/codedemo/reactor/ProcessService.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package cn.aofeng.demo.reactor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.SocketChannel;
|
||||
|
||||
/**
|
||||
* 业务逻辑处理。
|
||||
*
|
||||
* @author <a href="mailto:aofengblog@163.com">NieYong </a>
|
||||
*/
|
||||
public class ProcessService {
|
||||
|
||||
private SocketChannel _clientChannel;
|
||||
|
||||
private String _line;
|
||||
|
||||
public ProcessService(SocketChannel clientChannel, String line) {
|
||||
this._clientChannel = clientChannel;
|
||||
this._line = line;
|
||||
}
|
||||
|
||||
public String execute() {
|
||||
// 判断客户端是否发送了退出指令
|
||||
String content = _line.substring(0, _line.length()-2);
|
||||
if (isCloseClient(content)) {
|
||||
try {
|
||||
_clientChannel.close();
|
||||
} catch (IOException e) {
|
||||
// nothing
|
||||
}
|
||||
}
|
||||
|
||||
return _line;
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户端是否发送了退出指令("quit" | "exit")。
|
||||
*
|
||||
* @param str 收到的客户端数据
|
||||
* @return 返回true表示收到了退出指令;否则返回false。
|
||||
*/
|
||||
private boolean isCloseClient(String str) {
|
||||
return "exit".equalsIgnoreCase(str) || "quit".equalsIgnoreCase(str);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user