144
|
1 package rep.handler;
|
|
2
|
155
|
3 import java.io.IOException;
|
218
|
4 import java.nio.channels.SelectableChannel;
|
|
5
|
144
|
6 import rep.REPCommand;
|
213
|
7 import rep.REPCommandPacker;
|
144
|
8 import rep.SessionManager;
|
213
|
9 import rep.channel.REPSelectionKey;
|
144
|
10 import rep.channel.REPSocketChannel;
|
|
11
|
|
12 public class REPHandlerImpl implements REPHandler {
|
|
13
|
|
14 private SessionManager manager;
|
|
15
|
|
16
|
170
|
17 public REPHandlerImpl(int sid, SessionManager manager) {
|
144
|
18 this.manager = manager;
|
|
19 }
|
|
20
|
178
|
21 @SuppressWarnings("unchecked")
|
213
|
22 public void handle(REPSelectionKey<REPCommand> key) throws IOException {
|
218
|
23 SelectableChannel s = key.channel();
|
|
24 if(!(s instanceof REPSocketChannel) ){
|
|
25 System.out.println("error");
|
|
26 }
|
|
27 REPSocketChannel<REPCommand> channel = (REPSocketChannel<REPCommand>) key.channel(new REPCommandPacker());
|
237
|
28 System.out.println("REPHandlerImpl.handle() : channel = " + channel);
|
|
29
|
178
|
30 REPCommand command = channel.read();
|
233
|
31 System.out.println("REPHandlerImpl.handle() : command = " + command);
|
178
|
32
|
144
|
33 manager.manage(channel, command);
|
|
34 }
|
|
35
|
|
36 }
|