annotate rep/handler/REPHandlerImpl.java @ 267:c513cf1ce9cc

call handle.cancel() on socket channel close. fix unterminated read() on closed channel. on socket channel close, key.isreadable() and read() will return -1 we should throw IOException in this case.
author kono
date Thu, 11 Sep 2008 14:39:32 +0900
parents 6589b148dd13
children ad487e63e3c8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
144
0bf7f8d0f5f7 *** empty log message ***
pin
parents:
diff changeset
1 package rep.handler;
0bf7f8d0f5f7 *** empty log message ***
pin
parents:
diff changeset
2
155
bbd2801d8ce0 *** empty log message ***
pin
parents: 148
diff changeset
3 import java.io.IOException;
144
0bf7f8d0f5f7 *** empty log message ***
pin
parents:
diff changeset
4 import rep.REPCommand;
0bf7f8d0f5f7 *** empty log message ***
pin
parents:
diff changeset
5 import rep.SessionManager;
213
4d9b32666ed2 *** empty log message ***
pin
parents: 178
diff changeset
6 import rep.channel.REPSelectionKey;
144
0bf7f8d0f5f7 *** empty log message ***
pin
parents:
diff changeset
7 import rep.channel.REPSocketChannel;
0bf7f8d0f5f7 *** empty log message ***
pin
parents:
diff changeset
8
0bf7f8d0f5f7 *** empty log message ***
pin
parents:
diff changeset
9 public class REPHandlerImpl implements REPHandler {
0bf7f8d0f5f7 *** empty log message ***
pin
parents:
diff changeset
10
0bf7f8d0f5f7 *** empty log message ***
pin
parents:
diff changeset
11 private SessionManager manager;
0bf7f8d0f5f7 *** empty log message ***
pin
parents:
diff changeset
12
0bf7f8d0f5f7 *** empty log message ***
pin
parents:
diff changeset
13
170
30cf7747d134 *** empty log message ***
pin
parents: 155
diff changeset
14 public REPHandlerImpl(int sid, SessionManager manager) {
144
0bf7f8d0f5f7 *** empty log message ***
pin
parents:
diff changeset
15 this.manager = manager;
0bf7f8d0f5f7 *** empty log message ***
pin
parents:
diff changeset
16 }
0bf7f8d0f5f7 *** empty log message ***
pin
parents:
diff changeset
17
178
a097b1d619a1 *** empty log message ***
pin
parents: 170
diff changeset
18 @SuppressWarnings("unchecked")
213
4d9b32666ed2 *** empty log message ***
pin
parents: 178
diff changeset
19 public void handle(REPSelectionKey<REPCommand> key) throws IOException {
238
6589b148dd13 *** empty log message ***
kono
parents: 237
diff changeset
20 REPSocketChannel<REPCommand> channel = (REPSocketChannel<REPCommand>) key.channel();
237
c52e0e831d91 *** empty log message ***
pin
parents: 233
diff changeset
21 System.out.println("REPHandlerImpl.handle() : channel = " + channel);
c52e0e831d91 *** empty log message ***
pin
parents: 233
diff changeset
22
178
a097b1d619a1 *** empty log message ***
pin
parents: 170
diff changeset
23 REPCommand command = channel.read();
233
dae90ded1bcd *** empty log message ***
pin
parents: 218
diff changeset
24 System.out.println("REPHandlerImpl.handle() : command = " + command);
178
a097b1d619a1 *** empty log message ***
pin
parents: 170
diff changeset
25
144
0bf7f8d0f5f7 *** empty log message ***
pin
parents:
diff changeset
26 manager.manage(channel, command);
0bf7f8d0f5f7 *** empty log message ***
pin
parents:
diff changeset
27 }
0bf7f8d0f5f7 *** empty log message ***
pin
parents:
diff changeset
28
267
c513cf1ce9cc call handle.cancel() on socket channel close.
kono
parents: 238
diff changeset
29 public void cancel() {
c513cf1ce9cc call handle.cancel() on socket channel close.
kono
parents: 238
diff changeset
30 // TODO Auto-generated method stub
c513cf1ce9cc call handle.cancel() on socket channel close.
kono
parents: 238
diff changeset
31
c513cf1ce9cc call handle.cancel() on socket channel close.
kono
parents: 238
diff changeset
32 }
c513cf1ce9cc call handle.cancel() on socket channel close.
kono
parents: 238
diff changeset
33
144
0bf7f8d0f5f7 *** empty log message ***
pin
parents:
diff changeset
34 }