forked from aofeng/JavaTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessService.java
More file actions
46 lines (37 loc) · 1.15 KB
/
ProcessService.java
File metadata and controls
46 lines (37 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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);
}
}