Mercurial > hg > RemoteEditor > REPSessionManager
diff rep/SessionManager.java @ 123:5b1a0574b406 add-simulator
*** empty log message ***
author | pin |
---|---|
date | Wed, 27 Aug 2008 17:21:25 +0900 |
parents | 790c8dd42a7b |
children | 97a321d91b79 |
line wrap: on
line diff
--- a/rep/SessionManager.java Tue Aug 26 16:33:47 2008 +0900 +++ b/rep/SessionManager.java Wed Aug 27 17:21:25 2008 +0900 @@ -16,6 +16,8 @@ import java.util.LinkedList; import java.util.StringTokenizer; +import rep.channel.REPServerSocketChannel; +import rep.simulator.REPSelector; import rep.xml.SessionXMLDecoder; import rep.xml.SessionXMLEncoder; @@ -26,7 +28,7 @@ //o-------header section (network order)-------------o /*int cmd; // command int sid; // session ID : uniqu to editing file -int eid; // editor ID : owner editor ID = 1。Session に対してユニーク +int eid; // editor ID : owner editor ID = 1。Session に対して unique int seqno; // Sequence number : sequence number はエディタごとに管理 int lineno; // line number int textsize; // textsize : bytesize @@ -57,12 +59,15 @@ } public void openSelector() throws IOException{ - selector = Selector.open(); + //selector = Selector.open(); + selector = REPSelector.open(); } public void sessionManagerNet(int port) throws InterruptedException, IOException { - ServerSocketChannel ssc = ServerSocketChannel.open(); + //ServerSocketChannel ssc = ServerSocketChannel.open(); + ServerSocketChannel ssc = REPServerSocketChannel.open(); + ssc.configureBlocking(false); //reuse address 必須 ssc.socket().setReuseAddress(true); @@ -81,38 +86,19 @@ if(key.isAcceptable()){ /*** serverChannelはenableになったSelectionKeyのchannel ***/ ServerSocketChannel serverChannel = (ServerSocketChannel)key.channel(); - /*** EditorChannel を用いない記述 ***/ SocketChannel channel = serverChannel.accept(); //keyからchannelを取って、accept registerChannel (selector, channel, SelectionKey.OP_READ); channel = null; - - /*** EditorChannel を用いた記述 ****/ - //EditorChannel echannel = (EditorChannel) ssc.accept(); - //echannel.setIO(); - //registerChannel(selector, echannel, SelectionKey.OP_READ); - //echannel = null; - - /*** SelectableEditorChannel ***/ - //SocketChannel channel = ssc.accept(); - //SelectableEditorChannel echannel2 = new SelectableEditorChannel(channel); - //registerChannel(selector, echannel2, SelectionKey.OP_READ); - //channel = null; - //echannel2 = null; + }else if(key.isReadable()){ - /*** EditorChannel を用いない記述 ***/ SocketChannel channel = (SocketChannel)key.channel(); - REPPacketReceive receive = new REPPacketReceive(channel); //getPacket(), putPacket() にする。 + REPPacketReceive receive = new REPPacketReceive(channel); receive.setkey(key); REPCommand receivedCommand = receive.unpackUConv(); - //REPCommand receivedCommand = receive.unpack(); manager(channel, receivedCommand); - /*** EditorChannel を用いた記述 ****/ - //EditorChannel echannel = (EditorChannel) key.channel(); - //REPCommand command = echannel.getPacket(); - //manager(echannel, command); }else if(key.isConnectable()){ System.out.println("Connectable"); @@ -125,7 +111,6 @@ if(channel == null) { return; } - //System.out.println("registerChannel()"); channel.configureBlocking(false); selector.wakeup(); channel.register(selector, ops); @@ -399,7 +384,6 @@ } private int reverseCmd(int cmd) { - // TODO Auto-generated method stub int kindOfCmd = 0; switch(cmd){ case REP.REPCMD_INSERT: