# HG changeset patch # User pin # Date 1219825285 -32400 # Node ID 97a321d91b79dee4fdee4af3c674ff26f718c9cb # Parent 5b1a0574b4064c2b1cf4f54d31d784282c41fc08 *** empty log message *** diff -r 5b1a0574b406 -r 97a321d91b79 .classpath --- a/.classpath Wed Aug 27 17:21:25 2008 +0900 +++ b/.classpath Wed Aug 27 17:21:25 2008 +0900 @@ -1,6 +1,6 @@ - + diff -r 5b1a0574b406 -r 97a321d91b79 rep/EditorChannel.java --- a/rep/EditorChannel.java Wed Aug 27 17:21:25 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -package rep; - -import java.nio.channels.SocketChannel; -import java.nio.channels.spi.SelectorProvider; - -public abstract class EditorChannel extends SocketChannel { - - private REPPacketSend repsend; - private REPPacketReceive reprec; - - protected EditorChannel(SelectorProvider provider) { - super(provider); - } - - public void putPacket(REPCommand comm){ - repsend.send(comm); - } - - public REPCommand getPacket(){ - REPCommand command = reprec.unpack(); - return command; - } - - public void setIO(SocketChannel channel) { - repsend = new REPPacketSend(channel); - reprec = new REPPacketReceive(channel); - } - - public void setIO() { - repsend = new REPPacketSend(this); - reprec = new REPPacketReceive(this); - } - -} diff -r 5b1a0574b406 -r 97a321d91b79 rep/REPPacketReceive.java --- a/rep/REPPacketReceive.java Wed Aug 27 17:21:25 2008 +0900 +++ b/rep/REPPacketReceive.java Wed Aug 27 17:21:25 2008 +0900 @@ -3,6 +3,7 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.nio.CharBuffer; +import java.nio.channels.SelectableChannel; import java.nio.channels.SelectionKey; import java.nio.channels.SocketChannel; import java.nio.charset.CharacterCodingException; @@ -11,13 +12,12 @@ import java.util.LinkedList; import java.util.StringTokenizer; +import rep.channel.ChannelSimulator; + public class REPPacketReceive { SocketChannel socketchannel; private final int HEADER_SIZE = 24; - private final int CHAR_ORDER = 3; - //private String host; - //private int port; SelectionKey key; public REPPacketReceive(SocketChannel sc){ @@ -26,66 +26,8 @@ public void setkey(SelectionKey key) { this.key = key; - //key.cancel(); } - public REPCommand unpack() { - - ByteBuffer header = ByteBuffer.allocateDirect(HEADER_SIZE); - long len = 0; - header.clear(); - try { - len = socketchannel.read(header); - if(len == -1){ - if(key != null){ - key.cancel(); - } - socketchannel.close(); - return null; - }else if(len == 0){ - return null; - } - } catch (IOException e1) { - e1.printStackTrace(); - } // limit = read length - if (len !=HEADER_SIZE) { - System.out.println("てす"); - // this can't happen - } - header.rewind(); // position = 0 - - String text = ""; - int cmd = header.getInt(); - int sid = header.getInt(); - int eid = header.getInt(); - int seqid = header.getInt(); - int lineno = header.getInt(); - int textsiz = header.getInt()/2; - - ByteBuffer textBuffer = ByteBuffer.allocateDirect(textsiz*2); - - try { - len = socketchannel.read(textBuffer); - } catch (IOException e1) { - e1.printStackTrace(); - } // limit = read length - if (len != textsiz * 2) { - // this can't happen - System.out.println("あと"); - } - textBuffer.rewind(); - for(int i=0;i 2){ -// System.out.println(string); -// } - //System.out.println("CharBuffer size: " +cb.length()); - - //System.out.println("textsize: " +textsiz); - - //System.out.println(cb.toString()); REPCommand repcommand = new REPCommand(cmd, sid, eid, seqid, lineno, textsiz, string); System.out.println("UnPack Packet: => cmd:"+cmd+" sid:"+sid+" eid:"+eid+"seqid:"+seqid+" lineno:"+lineno+" textsiz:" +textsiz+" text: "+string); @@ -169,23 +101,4 @@ return repcommand; } - - private void getSocket(REPCommand command) { - if(command.cmd != REP.SMCMD_JOIN){ - String string = command.string; - StringTokenizer st2 = new StringTokenizer(string, ":"); - LinkedList list = new LinkedList(); - while (st2.hasMoreTokens()){ - list.add(st2.nextToken()); - } - String port = list.getLast(); - list.removeLast(); - String host = list.getLast(); - int socketInfoLength = host.length() + port.length() + 2; - System.out.println(host.length() + ":" + port.length() + ":" + socketInfoLength); - command.setString(string.substring(0, string.length() - socketInfoLength)); - command.setHost(host); - command.setPort(port); - } - } } diff -r 5b1a0574b406 -r 97a321d91b79 rep/SelectableEditorChannel.java --- a/rep/SelectableEditorChannel.java Wed Aug 27 17:21:25 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,85 +0,0 @@ -package rep; - -import java.io.IOException; -import java.nio.channels.ClosedChannelException; -import java.nio.channels.SelectableChannel; -import java.nio.channels.SelectionKey; -import java.nio.channels.Selector; -import java.nio.channels.SocketChannel; -import java.nio.channels.spi.SelectorProvider; - -public class SelectableEditorChannel extends SelectableChannel{ - - private SocketChannel channel; - private REPPacketSend repsend; - private REPPacketReceive reprec; - - public SelectableEditorChannel(SocketChannel channel){ - this.channel = channel; - repsend = new REPPacketSend(channel); - reprec = new REPPacketReceive(channel); - - } - - @Override - public Object blockingLock() { - return channel.blockingLock(); - //return null; - } - - @Override - public SelectableChannel configureBlocking(boolean block) throws IOException { - return channel.configureBlocking(block); - //return null; - } - - @Override - public boolean isBlocking() { - - return channel.isBlocking(); - } - - @Override - public boolean isRegistered() { - return channel.isRegistered(); - } - - @Override - public SelectionKey keyFor(Selector sel) { - return channel.keyFor(sel); - } - - @Override - public SelectorProvider provider() { - return channel.provider(); - } - - @Override - public SelectionKey register(Selector sel, int ops, Object att) throws ClosedChannelException { - return channel.register(sel, ops, att); - } - - @Override - public int validOps() { - return channel.validOps(); - } - - @Override - protected void implCloseChannel() throws IOException { - - } - - public void putPacket(REPCommand comm){ - repsend.send(comm); - } - public REPCommand getPacket(){ - REPCommand command = reprec.unpack(); - return command; - } - - //public void setIO(SocketChannel channel) { - // repsend = new REPPacketSend(channel); - // reprec = new REPPacketReceive(channel); - //} - -} diff -r 5b1a0574b406 -r 97a321d91b79 rep/SessionManager.java --- a/rep/SessionManager.java Wed Aug 27 17:21:25 2008 +0900 +++ b/rep/SessionManager.java Wed Aug 27 17:21:25 2008 +0900 @@ -66,7 +66,7 @@ public void sessionManagerNet(int port) throws InterruptedException, IOException { //ServerSocketChannel ssc = ServerSocketChannel.open(); - ServerSocketChannel ssc = REPServerSocketChannel.open(); + REPServerSocketChannel ssc = REPServerSocketChannel.open(); ssc.configureBlocking(false); //reuse address 必須