316
|
1 package rep.handler;
|
|
2
|
|
3 import java.io.IOException;
|
|
4
|
|
5 import rep.Forwarder;
|
|
6 import rep.REPCommand;
|
|
7 import rep.Session;
|
|
8 import rep.SessionManager;
|
|
9 import rep.channel.REPSelectionKey;
|
|
10 import rep.channel.REPSocketChannel;
|
|
11
|
|
12 public class REPSessionManagerHandler implements REPHandler {
|
|
13
|
|
14 private SessionManager manager;
|
|
15
|
|
16 public REPSessionManagerHandler(SessionManager manager) {
|
|
17 this.manager = manager;
|
|
18 }
|
|
19
|
|
20 public void cancel(REPSocketChannel<REPCommand> socketChannel) {
|
|
21 manager.remove(socketChannel);
|
|
22 }
|
|
23
|
|
24 public void handle(REPSelectionKey<REPCommand> key) throws IOException {
|
|
25 /*
|
|
26 * SessionManagerから来たコマンドは、Editor関係のコマンドは、
|
|
27 * sessionとeidを判定して、そのeditorにforwardしてやれば良い。
|
|
28 * 残りは、manager.manage() で処理する。
|
|
29 */
|
|
30 REPSocketChannel<REPCommand> channel = key.channel1();
|
|
31 REPCommand command = channel.read();
|
|
32 System.out.println("REPHandlerImpl.handle() : command = " + command);
|
|
33 Session s = manager.getSession(command.sid);
|
|
34 Forwarder next = s.getForwarder(command.eid);
|
|
35 if (next!=null) {
|
|
36 next.send(command);
|
|
37 } else {
|
|
38 manager.manage(channel, command);
|
|
39 }
|
|
40 }
|
|
41
|
|
42 }
|