Mercurial > hg > RemoteEditor > REPSessionManager
changeset 199:456ba58cd042
*** empty log message ***
author | pin |
---|---|
date | Sat, 30 Aug 2008 10:18:04 +0900 |
parents | ff3fcdcccc85 |
children | 2f0a0448de6b |
files | rep/REPPacketReceive.java rep/RPanel.java rep/SMConnector.java rep/SessionManager.java rep/net/REPNet.java test/ConnectToSessionManager.java |
diffstat | 6 files changed, 10 insertions(+), 167 deletions(-) [+] |
line wrap: on
line diff
--- a/rep/REPPacketReceive.java Sat Aug 30 01:11:27 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -package rep; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.CharBuffer; -import java.nio.channels.SocketChannel; -import java.nio.charset.CharacterCodingException; -import java.nio.charset.Charset; -import java.nio.charset.CharsetDecoder; - - -import rep.channel.REPSocketChannel; - -public class REPPacketReceive implements REPUnpack<REPCommand> { - - private final int HEADER_SIZE = 24; - private boolean debug=false; - - - // このクラスはシミュレーションの時には生成されないので、SocketChannelでいいんだよ REPSocketChannelにしない - public REPCommand unpackUConv(SocketChannel sc) throws IOException { - ByteBuffer header = ByteBuffer.allocateDirect(HEADER_SIZE); - long len = 0; - header.clear(); - len = sc.read(header); - if(len <= 0){ - return null; - } - if (len !=HEADER_SIZE) { - throw new IOException(); - } - header.rewind(); // position = 0 - - int cmd = header.getInt(); - int sid = header.getInt(); - int eid = header.getInt(); - int seqid = header.getInt(); - int lineno = header.getInt(); - int textsiz = header.getInt(); - - ByteBuffer textBuffer = ByteBuffer.allocateDirect(textsiz); - - len = sc.read(textBuffer); - if(len <= 0){ - return null; - } - if (len != textsiz) { - throw new IOException(); - } - textBuffer.rewind(); - - //Decode UTF-8 to System Encoding(UTF-16) - Charset charset = Charset.forName("UTF-8"); - CharsetDecoder decoder = charset.newDecoder(); - CharBuffer cb = null; - try { - cb = decoder.decode(textBuffer); - } catch (CharacterCodingException e) { - e.printStackTrace(); - } - cb.rewind(); - - String string = cb.toString(); - - textsiz = string.length(); - - REPCommand repcommand = new REPCommand(cmd, sid, eid, seqid, lineno, textsiz, string); - - if (debug){ - System.out.println("UnPack Packet: => cmd:"+cmd+" sid:"+sid+" eid:"+eid+"seqid:"+seqid+" lineno:"+lineno+" textsiz:" +textsiz+" text: "+string); - System.out.println("received command: " + repcommand.toString()); - } - - return repcommand; - } -}
--- a/rep/RPanel.java Sat Aug 30 01:11:27 2008 +0900 +++ b/rep/RPanel.java Sat Aug 30 10:18:04 2008 +0900 @@ -166,14 +166,14 @@ } protected void setTableSession(LinkedList<Session> list) { - s_tableModel = new DefaultTableModel(session_column, 0); + e_tableModel.setRowCount(0); for(Session session : list){ setTableSession(session.getSID(), session.getName()); } } protected void setTableEditor(LinkedList<Editor> list) { - //e_tableModel = new DefaultTableModel(editor_column, 0); + e_tableModel.setRowCount(0); for(Editor editor : list){ setTableEditor(editor.getEID(), editor.getChannel()); }
--- a/rep/SMConnector.java Sat Aug 30 01:11:27 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -package rep; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.nio.channels.SocketChannel; - -import rep.channel.REPSocketChannel; - -public class SMConnector { - private REPSocketChannel<REPCommand> sessionchannel; - - public void connectSession(String host) { - int port = 8765; - //int port = Integer.parseInt(args[2]); - InetSocketAddress addr = new InetSocketAddress(host, port); - try { - sessionchannel = REPSocketChannel.<REPCommand>create(); - sessionchannel.configureBlocking(true); - sessionchannel.connect(addr); - System.out.println("connect"); - //sessionchannel.configureBlocking(false); - while(!sessionchannel.finishConnect()){ - System.out.println("afro"); - } - //registerChannel(selector, sessionchannel, SelectionKey.OP_READ); - }catch (IOException e) { - e.printStackTrace(); - } - } -}
--- a/rep/SessionManager.java Sat Aug 30 01:11:27 2008 +0900 +++ b/rep/SessionManager.java Sat Aug 30 10:18:04 2008 +0900 @@ -120,14 +120,18 @@ for(REPSelectionKey<REPCommand> key : selector.selectedKeys1()){ if(key.isAcceptable()){ /*** serverChannelはenableになったSelectionKeyのchannel ***/ - REPServerSocketChannel serverChannel = (REPServerSocketChannel)key.channel(); - REPSocketChannel channel = serverChannel.accept1(); //keyからchannelを取って、accept +// REPServerSocketChannel serverChannel = (REPServerSocketChannel)key.channel(); + REPSocketChannel<REPCommand> channel = key.accept(new REPCommandPacker()); + //REPSocketChannel channel = serverChannel.accept1(); //keyからchannelを取って、accept registerChannel (selector, channel, SelectionKey.OP_READ); channel = null; }else if(key.isReadable()){ - REPHandler handler = (REPHandler)key.attachment(); + //REPHandler handler = (REPHandler)key.attachment(); + + //いんちき + REPHandler handler = new REPHandlerImpl(-1, this); handler.handle(key); }else if(key.isConnectable()){ @@ -166,6 +170,7 @@ //GUIに反映 Runnable doRun = new DoGUIUpdate(sList, eList, gui); SwingUtilities.invokeLater(doRun); + } break;
--- a/rep/net/REPNet.java Sat Aug 30 01:11:27 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -package rep.net; - -import java.io.IOException; -import java.net.InetSocketAddress; -import rep.REPCommand; -import rep.REPPacketReceive; -import rep.REPPacketSend; -import rep.channel.REPSocketChannel; - -public class REPNet { - private REPSocketChannel<REPCommand> sc; - public REPPacketReceive repreceive; - private REPPacketSend repsend; - - public void sm_connect(String host, int port){ - //int port = 8765; - //String host = "localhost"; - InetSocketAddress addr = new InetSocketAddress(host, port); - try { - sc = REPSocketChannel.<REPCommand>create(); - sc.configureBlocking(true); - sc.connect(addr); - while(!sc.finishConnect()){ - System.out.println("afro"); - } - }catch (IOException e) { - e.printStackTrace(); - } - repreceive = new REPPacketReceive(sc); - repsend = new REPPacketSend(sc); - } - - public void send(REPCommand command) { - repsend.send(command); - } -}
--- a/test/ConnectToSessionManager.java Sat Aug 30 01:11:27 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -package test; - -import rep.REPCommand; -import rep.net.REPNet; - -public class ConnectToSessionManager { - private REPNet rnet; - - public static void main(String[] args){ - ConnectToSessionManager test = new ConnectToSessionManager(); - test.sm_join("localhost"); - } - - public void sm_join(String host){ - rnet = new REPNet(); - rnet.sm_connect(host, 8765); - rnet.send(REPCommand.SMCMD_SESSION_JOIN); - } - -}