comparison rep/SessionManager.java @ 146:20beee6ca31a

*** empty log message ***
author pin
date Wed, 27 Aug 2008 23:14:39 +0900
parents 0bf7f8d0f5f7
children 6a5fe529b192
comparison
equal deleted inserted replaced
145:ec625f8f8d7c 146:20beee6ca31a
18 import java.util.Set; 18 import java.util.Set;
19 import java.util.StringTokenizer; 19 import java.util.StringTokenizer;
20 20
21 import rep.channel.REPServerSocketChannel; 21 import rep.channel.REPServerSocketChannel;
22 import rep.channel.REPSocketChannel; 22 import rep.channel.REPSocketChannel;
23 import rep.channel.SelectionKeySimulator;
24 import rep.channel.SelectorSimulator;
23 import rep.handler.PacketSet; 25 import rep.handler.PacketSet;
26 import rep.handler.REPHandler;
24 import rep.simulator.REPSelector; 27 import rep.simulator.REPSelector;
25 import rep.xml.SessionXMLDecoder; 28 import rep.xml.SessionXMLDecoder;
26 import rep.xml.SessionXMLEncoder; 29 import rep.xml.SessionXMLEncoder;
27 30
28 //+-------+--------+--------+-------+--------+---------+------+ 31 //+-------+--------+--------+-------+--------+---------+------+
60 public SessionManager(int port) { 63 public SessionManager(int port) {
61 gui = new SessionManagerGUI(); 64 gui = new SessionManagerGUI();
62 } 65 }
63 66
64 public void openSelector() throws IOException{ 67 public void openSelector() throws IOException{
65 //selector = Selector.open();
66 selector = REPSelector.open(); 68 selector = REPSelector.open();
67 } 69 }
68 70
69 public void mainLoop(int port) throws InterruptedException, IOException { 71 public void mainLoop(int port) throws InterruptedException, IOException {
70 72
89 select(); 91 select();
90 } 92 }
91 } 93 }
92 94
93 private void select() throws IOException { 95 private void select() throws IOException {
94 for(SelectionKey key : selector.selectedKeys()){ 96 for(SelectionKeySimulator key : selector.selectedKeys()){
95 if(key.isAcceptable()){ 97 if(key.isAcceptable()){
96 /*** serverChannelはenableになったSelectionKeyのchannel ***/ 98 /*** serverChannelはenableになったSelectionKeyのchannel ***/
97 ServerSocketChannel serverChannel = (ServerSocketChannel)key.channel(); 99 REPServerSocketChannel serverChannel = (REPServerSocketChannel)key.channel();
98 SocketChannel channel = serverChannel.accept(); //keyからchannelを取って、accept 100 REPSocketChannel channel = serverChannel.accept(); //keyからchannelを取って、accept
99 registerChannel (selector, channel, SelectionKey.OP_READ); 101 registerChannel (selector, channel, SelectionKey.OP_READ);
100 channel = null; 102 channel = null;
101 103
102 104
103 }else if(key.isReadable()){ 105 }else if(key.isReadable()){
104 106
105 REPSocketChannel<REPCommand> channel = (REPSocketChannel<REPCommand>)key.channel(); 107 // REPSocketChannel<REPCommand> channel = (REPSocketChannel<REPCommand>)key.channel();
106 REPPacketReceive receive = new REPPacketReceive(channel); 108 // REPPacketReceive receive = new REPPacketReceive(channel);
107 receive.setkey(key); 109 // receive.setkey(key);
108 REPCommand receivedCommand = receive.unpackUConv(); 110 // REPCommand receivedCommand = receive.unpackUConv();
109 manage(channel, receivedCommand); 111 // manage(channel, receivedCommand);
110 112
113 REPHandler handler = (REPHandler)key.attachment();
114 handler.handle(key);
111 115
112 }else if(key.isConnectable()){ 116 }else if(key.isConnectable()){
113 System.out.println("Connectable"); 117 System.out.println("Connectable");
114 } 118 }
115 } 119 }