Mercurial > hg > RemoteEditor > REPSessionManager
changeset 385:1fca50ce3508
first-working-version
author | one@firefly.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Mon, 10 Nov 2008 22:18:14 +0900 |
parents | bcdf5476b8e4 |
children | bba62c4ac323 |
files | Todo rep/REPCommandPacker.java rep/SessionManager.java rep/handler/Dispatcher.java rep/handler/Editor.java rep/handler/FirstConnector.java rep/handler/Forwarder.java rep/xml/SessionXMLDecoder.java test/sematest/TestInterManagerSession.java |
diffstat | 9 files changed, 55 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/Todo Mon Nov 10 22:16:37 2008 +0900 +++ b/Todo Mon Nov 10 22:18:14 2008 +0900 @@ -1,3 +1,8 @@ +Wed Oct 22 19:53:59 JST 2008 + +Todo: (kono) +やっぱり、END_MERGEが繰り返し出るバグがあるらしい。 + Wed Oct 22 02:31:27 JST 2008 Todo: (kono)
--- a/rep/REPCommandPacker.java Mon Nov 10 22:16:37 2008 +0900 +++ b/rep/REPCommandPacker.java Mon Nov 10 22:18:14 2008 +0900 @@ -41,7 +41,9 @@ * @see rep.REPPack#packUConv(rep.REPCommand) */ public ByteBuffer packUConv(REPCommand command){ - ByteBuffer buffer = ByteBuffer.allocateDirect(HEADER_SIZE+(command.string.length()*CHARSIZE)); + int size = 0; + if (command.string!=null) size = command.string.length()*CHARSIZE; + ByteBuffer buffer = ByteBuffer.allocateDirect(HEADER_SIZE+size); buffer.clear(); // position = 0 buffer.putInt(command.cmd.id); buffer.putInt(command.sid);
--- a/rep/SessionManager.java Mon Nov 10 22:16:37 2008 +0900 +++ b/rep/SessionManager.java Mon Nov 10 22:18:14 2008 +0900 @@ -561,7 +561,7 @@ } else return; } else { - editor = new Editor(this, command.cmd==REP.SMCMD_PUT_ACK, command.eid); + editor = new Editor(this, command.eid); } editor.setName(command.string); editor.setSID(command.sid); @@ -610,4 +610,8 @@ if (smList!=null) myId = smList.sessionManagerID(); return "rep.SessionManager-"+myId+"@"+super.toString(); } + + public void addWaitingSessionManager(REPNode fw, REPCommand command) { + smList.addWaitingSessionManager(fw, command); + } }
--- a/rep/handler/Dispatcher.java Mon Nov 10 22:16:37 2008 +0900 +++ b/rep/handler/Dispatcher.java Mon Nov 10 22:18:14 2008 +0900 @@ -2,6 +2,7 @@ import java.io.IOException; +import rep.PacketSet; import rep.REPCommand; import rep.ServerMainLoop; import rep.Session; @@ -64,7 +65,7 @@ * local editor case. */ Editor editor = (Editor)f; - editor.forwardedCommandManage(command, this); + editor.forwardedCommandManage(command); } @@ -75,4 +76,12 @@ public boolean isMerging() { return false; } + + @Override + public void send(REPCommand command) { + assert(command!=null); + assert(channel!=null); + REPCommand c = new REPCommand(command); + manager.addWriteQueue(new PacketSet(channel,null, c)); + } }
--- a/rep/handler/Editor.java Mon Nov 10 22:16:37 2008 +0900 +++ b/rep/handler/Editor.java Mon Nov 10 22:18:14 2008 +0900 @@ -21,8 +21,9 @@ //private REPCommand quit2 = null; private SessionManager manager; private REPCommand quit2=null; + static final boolean doOptimize = true; - public Editor(SessionManager manager,boolean doOptimize,int editorNo){ + public Editor(SessionManager manager,int editorNo){ super(manager); this.manager = manager; eid = editorNo; @@ -34,7 +35,7 @@ } public Editor(SessionManager manager,int editorNo, REPSocketChannel<REPCommand> channel){ - this(manager,false,editorNo); + this(manager,editorNo); this.channel = channel; } @@ -226,7 +227,7 @@ * are handled in the next Editor in a session manager, but * it is forwarded here. */ - public void forwardedCommandManage(REPCommand command, REPNode forwarder) { + public void forwardedCommandManage(REPCommand command) { if (command.cmd==REP.SMCMD_QUIT_2) { // we have to wait next editor's finishing before sending this. // this is odd, but the editor itself does not know it's merging @@ -243,6 +244,14 @@ return; } } - manage(command); + send(command); + } + + @Override + public void send(REPCommand command) { + assert(command!=null); + assert(channel!=null); + REPCommand c = new REPCommand(command); + manager.addWriteQueue(new PacketSet(channel,null, c)); } }
--- a/rep/handler/FirstConnector.java Mon Nov 10 22:16:37 2008 +0900 +++ b/rep/handler/FirstConnector.java Mon Nov 10 22:18:14 2008 +0900 @@ -2,6 +2,8 @@ import java.io.IOException; +import rep.PacketSet; +import rep.REP; import rep.REPCommand; import rep.ServerMainLoop; import rep.Session; @@ -61,7 +63,7 @@ } case SMCMD_SM_JOIN: { - fw = new Dispatcher(manager); + fw = new Dispatcher(manager); // FirstConnector? manager.addWaitingSessionManager(fw, command); break; } @@ -83,4 +85,11 @@ } + @Override + public void send(REPCommand command) { + assert(command!=null && command.cmd==REP.SMCMD_SM_JOIN); + assert(channel!=null); + REPCommand c = new REPCommand(command); + manager.addWriteQueue(new PacketSet(channel,null, c)); + } }
--- a/rep/handler/Forwarder.java Mon Nov 10 22:16:37 2008 +0900 +++ b/rep/handler/Forwarder.java Mon Nov 10 22:18:14 2008 +0900 @@ -31,6 +31,7 @@ return seq++; } + @Override public void send(REPCommand command) { assert(command!=null); assert(channel!=null); @@ -67,7 +68,7 @@ } public boolean manage(REPCommand command) { - next.send(command); + assert false; return true; }
--- a/rep/xml/SessionXMLDecoder.java Mon Nov 10 22:16:37 2008 +0900 +++ b/rep/xml/SessionXMLDecoder.java Mon Nov 10 22:18:14 2008 +0900 @@ -83,14 +83,14 @@ Element elementFile = (Element) nodelistEditorFile.item(0); String file = elementFile.getFirstChild().getNodeValue(); - Editor editor = new Editor(null, false, 0); + Editor editor = new Editor(null, 0); editor.setHost(host);/* editor.setPort(port)*/; editor.setName(file); editor.setEID(Integer.parseInt(eid)); session = new Session(sid, editor); session.addEditor(editor); sessionlist.put(sid,session); }else { - Editor editor = new Editor(null, false, 0); + Editor editor = new Editor(null, 0); editor.setHost(host);/* editor.setPort(port)*/; editor.setName(null); editor.setEID(Integer.parseInt(eid)); if(session != null){ session.addEditor(editor);
--- a/test/sematest/TestInterManagerSession.java Mon Nov 10 22:16:37 2008 +0900 +++ b/test/sematest/TestInterManagerSession.java Mon Nov 10 22:18:14 2008 +0900 @@ -68,7 +68,7 @@ } }; - private int inscnt=2; + //private int inscnt=2; private void startEditor(SessionManager m) { for(TestEditor editor:editors) { @@ -104,9 +104,9 @@ // TestEditor extends Thread LinkedList<REPCommand>cmds = new LinkedList<REPCommand>(); cmds.add(new REPCommand(REP.SMCMD_JOIN,0,0,0,0,"")); - if (inscnt-->0) cmds.add(new REPCommand(REP.REPCMD_INSERT,0,0,0,0,"m0")); + //if (inscnt-->0) cmds.add(new REPCommand(REP.REPCMD_INSERT,0,0,0,0,"m0")); editors[i] = new TestEditor("Editor"+i,host,port,master); - editors[i].setCommand(cmds); + //editors[i].setCommand(cmds); } setupEditor0(); } @@ -119,8 +119,8 @@ LinkedList<REPCommand>cmds = new LinkedList<REPCommand>(); //cmds.add(new REPCommand(REP.SMCMD_JOIN,0,0,0,0,"Editor0-file")); cmds.add(new REPCommand(REP.SMCMD_PUT,0,0,0,0,"Editor0-file")); - //cmds.add(new REPCommand(REP.REPCMD_INSERT,0,0,0,0,"m0")); - //cmds.add(new REPCommand(REP.REPCMD_DELETE,0,0,0,0,"m0")); + cmds.add(new REPCommand(REP.REPCMD_INSERT,0,0,0,0,"m0")); + cmds.add(new REPCommand(REP.REPCMD_DELETE,0,0,0,0,"m0")); editorStartCmds = cmds; LinkedList<REPCommand>nullcmds = new LinkedList<REPCommand>(); editors[0].setCommand(nullcmds);