# HG changeset patch # User one # Date 1232444342 -32400 # Node ID 7ff127c8ad649873ab5815c80744770023f1b8b5 # Parent d1bfcff0cdd214feeb05a865dc91f6d394134cb9 (no commit message) diff -r d1bfcff0cdd2 -r 7ff127c8ad64 test/editortest/LogTarget.java --- a/test/editortest/LogTarget.java Wed Dec 31 18:29:35 2008 +0900 +++ b/test/editortest/LogTarget.java Tue Jan 20 18:39:02 2009 +0900 @@ -2,6 +2,6 @@ public interface LogTarget { - void printLog(String msg); + public void printLog(String msg); } diff -r d1bfcff0cdd2 -r 7ff127c8ad64 test/editortest/Main.java --- a/test/editortest/Main.java Wed Dec 31 18:29:35 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -package test.editortest; - -public class Main { - - public static void main(String[] args){ - REPSimpleEditor frame = new REPSimpleEditor(); - frame.setDefaultCloseOperation(REPSimpleEditor.EXIT_ON_CLOSE); - frame.setVisible(true); - } - -} diff -r d1bfcff0cdd2 -r 7ff127c8ad64 test/editortest/REPCommandReceiver.java --- a/test/editortest/REPCommandReceiver.java Wed Dec 31 18:29:35 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -package test.editortest; - -import java.io.IOException; -import java.nio.channels.SelectionKey; - -import rep.REPCommand; -import rep.channel.REPSelectionKey; -import rep.channel.REPSelector; -import rep.channel.REPSocketChannel; - -public class REPCommandReceiver extends Thread{ - - REPSocketChannel channel; - boolean running = true; - private boolean inputLock=false; - long timeout = 1; - private int syncCounter=0; - - public REPCommandReceiver(REPSocketChannel channel, REPSelector selector){ - this.channel = channel; - } - - public void run(){ - try { - mainloop(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - private void mainloop() throws IOException { - - channel.configureBlocking(false); - REPSelector selector = REPSelector.create(); - channel.register(selector, SelectionKey.OP_READ); - while(running) { - if (inputLock) { - // No user input during merge mode (optional) - if (selector.select(0)>0) { - handle(channel.read()); - } - continue; - } else if (selector.select(timeout)<=0) { - if (syncCounter>0) { - syncText(); // send the master editor buffer to clients. - } - userInput(); - } - // selector(timeout) returns 0, but it may contain readable channel.. - for(REPSelectionKey key : selector.selectedKeys1()) { - REPSocketChannel ch = key.channel1(); - handle(ch.read()); - } - } - } - - private void userInput() { - // TODO Auto-generated method stub - - } - - private void syncText() { - // TODO Auto-generated method stub - - } - - private void handle(REPCommand read) { - // TODO Auto-generated method stub - - } -} diff -r d1bfcff0cdd2 -r 7ff127c8ad64 test/editortest/REPEditor.java --- a/test/editortest/REPEditor.java Wed Dec 31 18:29:35 2008 +0900 +++ b/test/editortest/REPEditor.java Tue Jan 20 18:39:02 2009 +0900 @@ -27,7 +27,7 @@ private int eid; private int sid; private REPText repText; - private boolean hasInputLock; + private boolean hasInputLock = false; private boolean master; private boolean syncEnable = true; private LogTarget logTarget; @@ -53,7 +53,7 @@ addUserInput(new REPCommand(REP.REPCMD_INSERT_USER, 0, 0, 0, event.getLineno(), event.getText())); } - private void addUserInput(final REPCommand command) { + public void addUserInput(final REPCommand command) { Runnable runner = new Runnable(){ public void run(){ userCommand.add(command); @@ -136,6 +136,7 @@ private void handle(REPCommand command) { Logger.print(logTarget, command); +// if(inputLock) Logger.print(logTarget, command); if(command == null) return; switch(command.cmd){ case REPCMD_DELETE: @@ -244,4 +245,8 @@ logTarget = target; } + public REPText getREPText() { + return repText; + } + } diff -r d1bfcff0cdd2 -r 7ff127c8ad64 test/editortest/REPSimpleEditor.java --- a/test/editortest/REPSimpleEditor.java Wed Dec 31 18:29:35 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,227 +0,0 @@ -package test.editortest; - -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.IOException; -import java.net.InetSocketAddress; - -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JScrollPane; -import javax.swing.JSplitPane; -import javax.swing.JTextArea; -import javax.swing.JTextField; -import javax.swing.JToolBar; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; -import javax.swing.text.BadLocationException; -import javax.swing.text.Document; - -import rep.REP; -import rep.REPCommand; -import rep.REPCommandPacker; -import rep.channel.REPSocketChannel; -import test.Text; - -public class REPSimpleEditor extends JFrame implements DocumentListener, ActionListener, LogTarget{ - - /** - * - */ - private static final long serialVersionUID = 1L; - private String BR = System.getProperty("line.separator"); - private Document document; - private JTextArea textArea; - private int seq; - private int eid; - private int sid; - private JButton putButton; - private JButton joinButton; - private REPText repText; - private TestEditor2 testEditor; - private JSplitPane splitPane; - private JScrollPane scrollPane1; - private JTextArea console; - private JScrollPane scrollPane2; - private JTextField lineField; - private JTextField textField; - private REPSocketChannel channel; - - public REPSimpleEditor(String title){ - super(title); - setSize(new Dimension(640, 480)); - setLayout(new BorderLayout()); - - setToolBar(); - setEditor(); - setConsole(); - setSplitPane(); - } - - public REPSimpleEditor(){ - this("Sample Editor"); - } - - private void setToolBar() { - JToolBar toolbar = new JToolBar(); - putButton = new JButton("put"); - joinButton = new JButton("join"); - - putButton.addActionListener(this); - joinButton.addActionListener(this); - - JLabel label1 = new JLabel("line"); - JLabel label2 = new JLabel("text"); - lineField = new JTextField(); - textField = new JTextField(); - - textField.addActionListener(this); - - toolbar.add(putButton); - toolbar.add(joinButton); - toolbar.addSeparator(); - toolbar.add(label1); - toolbar.add(lineField); - toolbar.add(label2); - toolbar.add(textField); - - add(toolbar, BorderLayout.NORTH); - } - - private void setEditor(){ - textArea = new JTextArea(); - textArea.setEditable(false); - textArea.setFont(new Font("Monaco", Font.PLAIN, textArea.getFont().getSize())); - document = textArea.getDocument(); - document.addDocumentListener(this); - - scrollPane1 = new JScrollPane(textArea); - - repText = new REPTextImpl(textArea); - } - - private void setConsole(){ - console = new JTextArea(); - console.setFont(new Font("Monaco", Font.PLAIN, console.getFont().getSize())); - console.setEditable(false); - scrollPane2 = new JScrollPane(console); - } - - private void setSplitPane(){ - splitPane = new JSplitPane(); - splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); - splitPane.add(scrollPane1, JSplitPane.TOP); - splitPane.add(scrollPane2, JSplitPane.BOTTOM); - splitPane.setDividerLocation(300); - add(splitPane, BorderLayout.CENTER); - } - - public void setButtonEnabled(boolean b) { - putButton.setEnabled(b); - joinButton.setEnabled(b); - } - - private REPCommand createREPCommand(int offset, int length) { - REPCommand command = null; - try { - int lineno = textArea.getLineOfOffset(offset); - int lineStart = textArea.getLineStartOffset(lineno); - int lineEnd = textArea.getLineEndOffset(lineno); - String text = textArea.getText(lineStart, lineEnd-lineStart); - command = new REPCommand(REP.REPCMD_INSERT_USER, sid, eid, seq++, lineno, text); - } catch (BadLocationException e1) { - e1.printStackTrace(); - } - return command; - } - - public void changedUpdate(DocumentEvent e) { - Logger.print(e); - } - - public void insertUpdate(DocumentEvent e) { - int offset = e.getOffset(); - int length = e.getLength(); - createREPCommand(offset, length); - } - - public void removeUpdate(DocumentEvent e) { - Logger.print(e); - } - - public void actionPerformed(ActionEvent e) { - if(e.getSource() == putButton){ - repPut(); - }else if(e.getSource() == joinButton){ - repJoin(); - }else if(e.getSource() == textField){ - testEditor.addUserInput(new REPCommand(REP.REPCMD_INSERT_USER, 0, 0, 0, 0, textField.getText())); - lineField.setText(""); - textField.setText(""); - } - } - - private void repJoin() { -// testEditor = new TestEditor2("TestEditor", "localhost", 8766, false); -// testEditor.setREPText(repText); -// testEditor.setLogTarget(this); -// testEditor.start(); - } - - private void repPut() { - setMasterText(); - connectToSessionManager(); -// testEditor = new TestEditor2("TestEditor", "localhost", 8766, true); -// testEditor.setText(repText.list()); -// testEditor.setREPText(repText); -// testEditor.setLogTarget(this); -// testEditor.start(); - } - - private void setMasterText() { - textArea.append("AAAAA" + BR); - textArea.append("BBBBB" + BR); - textArea.append("CCCCC" + BR); - textArea.append("DDDDD" + BR); - } - - private void connectToSessionManager() { - InetSocketAddress semaIP = new InetSocketAddress("localhost", 8766); - try { - channel = REPSocketChannel.create(new REPCommandPacker()); - } catch (IOException e) { - e.printStackTrace(); return; - } - try { - while (!channel.connect(semaIP)){ - Logger.print("SeMa not listen to socket yet, wait"); - } - } catch (IOException e) { - e.printStackTrace(); return; - } - - } - - public void printLog(String msg) { - console.append(msg + BR); - } - - public REPText getREPText() { - return repText; - } - - public void setText(Text text) { - for(String str : text){ - textArea.append(str + BR); - } - } - - public void setTestEditor(TestEditor2 testEditor2) { - testEditor = testEditor2; - } - -} diff -r d1bfcff0cdd2 -r 7ff127c8ad64 test/editortest/REPTextWithJTextArea.java --- a/test/editortest/REPTextWithJTextArea.java Wed Dec 31 18:29:35 2008 +0900 +++ b/test/editortest/REPTextWithJTextArea.java Tue Jan 20 18:39:02 2009 +0900 @@ -12,6 +12,8 @@ import javax.swing.event.DocumentListener; import javax.swing.text.BadLocationException; +import rep.REPCommand; + public class REPTextWithJTextArea implements REPText, DocumentListener, ActionListener { private JTextArea textArea; @@ -152,5 +154,14 @@ listener.textInserted(new REPTextEvent(lineno, text)); } } + + public void userInsert(REPCommand command) { + int lineno = command.lineno; + String text = command.string; + insert(lineno, text); + for(REPTextListener listener : textListenerList){ + listener.textInserted(new REPTextEvent(lineno, text)); + } + } } diff -r d1bfcff0cdd2 -r 7ff127c8ad64 test/editortest/SimpleEditorForREPEditor.java --- a/test/editortest/SimpleEditorForREPEditor.java Wed Dec 31 18:29:35 2008 +0900 +++ b/test/editortest/SimpleEditorForREPEditor.java Tue Jan 20 18:39:02 2009 +0900 @@ -33,6 +33,7 @@ private String BR = System.getProperty("line.separator"); private JButton deleteButton; private JButton insertButton; + private REPEditor repEditor; public SimpleEditorForREPEditor(String title){ super(title); @@ -106,16 +107,16 @@ } } - private void repPut() { - REPEditor repEditor = new REPEditor(new REPTextWithJTextArea(textArea, lineField, textField, deleteButton, insertButton), true); + public void repPut() { + repEditor = new REPEditor(new REPTextWithJTextArea(textArea, lineField, textField, deleteButton, insertButton), true); repEditor.start(); repEditor.setLogTarget(this); putButton.setEnabled(false); joinButton.setEnabled(false); } - private void repJoin() { - REPEditor repEditor = new REPEditor(new REPTextWithJTextArea(textArea, lineField, textField, deleteButton, insertButton), false); + public void repJoin() { + repEditor = new REPEditor(new REPTextWithJTextArea(textArea, lineField, textField, deleteButton, insertButton), false); repEditor.start(); repEditor.setLogTarget(this); putButton.setEnabled(false); @@ -131,4 +132,8 @@ editor.setVisible(true); } + public REPEditor getREPEditor() { + return repEditor; + } + } diff -r d1bfcff0cdd2 -r 7ff127c8ad64 test/editortest/TestEditor2.java --- a/test/editortest/TestEditor2.java Wed Dec 31 18:29:35 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,366 +0,0 @@ -package test.editortest; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.nio.channels.SelectionKey; -import java.util.LinkedList; -import java.util.List; - -import rep.REP; -import rep.REPCommand; -import rep.REPCommandPacker; -import rep.SessionManager; -import rep.channel.REPLogger; -import rep.channel.REPSelectionKey; -import rep.channel.REPSelector; -import rep.channel.REPSocketChannel; -import test.Text; - - -/** - * @author kono - * Basic Remote Editor client implementation - * should support multi-session - * currently multi-session requires new channel, that is - * only one session for this editor. - */ -public class TestEditor2 extends Thread{ - private InetSocketAddress semaIP; - private REPLogger ns; - private int seq = 0; - public Text text; - public LinkedList cmds; - private int eid = 0; - private int sid = 0; - REPSocketChannel channel; - REPCommand nop = new REPCommand(REP.REPCMD_NOP, 0, 0, 0, 0, ""); - boolean running = true; - long timeout = 1; - private String name; - private boolean inputLock=false; - public boolean detached=false; - public boolean master=false; - REPCommand quit=null; - private int syncCounter=0; - private boolean hasInputLock=false; - private int port; - private REPSelector selector; - private boolean syncEnable=true; - private LogTarget logTarget; - private REPText repText; - private REPSimpleEditor simpleEditor; - - - public TestEditor2(String name, String _host,int _port, boolean master){ - super(name); - LinkedListcmdList = new LinkedList(); - String[] txts = { - "aaa", "bbb", // "ccc", "ddd", "eee", - }; - port = _port; - semaIP = new InetSocketAddress(_host, _port); - ns = REPLogger.singleton(); - this.name = name; - cmds = cmdList; - if (master) { - this.master=true; - text = new Text(txts); - cmds.add(new REPCommand(REP.SMCMD_PUT,0,0,0,0,name+"-file")); - cmds.add(new REPCommand(REP.REPCMD_INSERT_USER,0,0,0,0,"m0")); - cmds.add(new REPCommand(REP.REPCMD_DELETE_USER,0,0,0,0,"m0")); - cmds.add(new REPCommand(REP.SMCMD_QUIT,0,0,0,0,"")); - } else { - text = new Text(new String[0]); - cmds.add(new REPCommand(REP.SMCMD_JOIN,0,0,0,0,name)); - cmds.add(new REPCommand(REP.REPCMD_INSERT_USER,0,0,0,0,"c0")); - cmds.add(new REPCommand(REP.REPCMD_DELETE_USER,0,0,0,0,"c0")); - } - - simpleEditor = new REPSimpleEditor(); - simpleEditor.setVisible(true); - simpleEditor.setButtonEnabled(false); - simpleEditor.setTestEditor(this); - simpleEditor.setText(text); - repText = simpleEditor.getREPText(); - logTarget = simpleEditor; - } - - public TestEditor2(String name, String _host,int _port, boolean master, - String[] txts,LinkedList cmdList){ - super(name); - port = _port; - semaIP = new InetSocketAddress(_host, _port); - ns = REPLogger.singleton(); - this.name = name; - cmds = cmdList; - if (master) { - this.master=true; - text = new Text(txts); - } else { - text = new Text(new String[0]); - } - } - - public void run(){ - /* - * Create Socket and connect to the session manager - */ - try { - channel = REPSocketChannel.create(new REPCommandPacker()); - } catch (IOException e) { return; } - - ns.writeLog("try to connect to SessionManager whose ip is "+semaIP+" "+name, 1); - try { - while (!channel.connect(semaIP)){ - ns.writeLog("SeMa not listen to socket yet, wait", 1); - } - } catch (IOException e) { return; } - ns.writeLog("successes to connect "+name); - /* - * Start editor main loop - * public REPCommand(REP cmd,int sid,int eid, int seq, int lineno, String string) - */ - try { - mainloop(); - } catch (IOException e) { - } - } - - /* - * Editor main loop with input lock - */ - private void mainloop() throws IOException { - - channel.configureBlocking(false); - REPSelector selector = REPSelector.create(); - channel.register(selector, SelectionKey.OP_READ); - this.selector = selector; - while(running) { - if (inputLock) { - // No user input during merge mode (optional) - if (selector.select(0)>0) { - handle(channel.read()); - } - continue; - } else if (selector.select(timeout)<=0) { - if (syncCounter>0) { - syncText(); // send the master editor buffer to clients. - } - userInput(); - } - // selector(timeout) returns 0, but it may contain readable channel.. - for(REPSelectionKey key : selector.selectedKeys1()) { - REPSocketChannel ch = key.channel1(); - handle(ch.read()); - } - } - } - - private void syncText() { - /* - * Send delete/insert one at a time to synchronize - * all clients. SYNC is requested by the session manager. - */ - if (syncCounter>text.size()) { - SessionManager.logger.writeLog("Sync Completed."); - syncCounter=0; - } else { - if (inputLock) return; - int i=syncCounter-1; - REPCommand del = new REPCommand(REP.REPCMD_DELETE_USER,sid,eid,0,i, text.get(i)); - REPCommand ins = new REPCommand(REP.REPCMD_INSERT_USER,sid,eid,0,i, text.get(i)); - sendCommand(del); - sendCommand(ins); - syncCounter++; - } - } - - /* - * Simulate User Input - */ - private void userInput() { - REPCommand cmd = cmds.poll(); - if (cmd!=null) { - Logger.print(logTarget, "User Input : " + cmd); - switch(cmd.cmd) { - case REPCMD_INSERT_USER: - text.insert(cmd.lineno, cmd.string); - repText.insert(cmd.lineno, cmd.string); - sendCommand(cmd); - break; - case REPCMD_DELETE_USER: - String del = text.delete(cmd.lineno); - del = repText.delete(cmd.lineno); - cmd.setString(del); - sendCommand(cmd); - break; - case SMCMD_QUIT: - /* - * start termination phase 1 by the master editor. - * after this command do not send any user input. - * clients simply disconnect from the session manager. - */ - cmds.clear(); - cmd.eid = -1; - quit = cmd; - break; - case SMCMD_JOIN: - case SMCMD_PUT: - sendCommand(cmd); - /* - * To prevent confusion, stop user input until the ack - */ - inputLock = true; // wait until ACK - break; - default: - assert(false); - } - } else { - if(syncCounter==0) { - // no more command to send, and we don't have syncCounter - timeout = 0; - if (quit!=null) { - if (quit.eid==-1) - sendCommand(quit); - else - forwardCommand(quit); - quit=null; - } - } - } - } - - - private void sendCommand(REPCommand cmd1) { - REPCommand cmd = new REPCommand(cmd1); - cmd.setSEQID(seq++); - cmd.setEID(eid); - cmd.setSID(sid); - ns.writeLog(name +" send "+cmd); - channel.write(cmd); - } - - private void forwardCommand(REPCommand cmd1) { - REPCommand cmd = new REPCommand(cmd1); - ns.writeLog(name +" forward "+cmd); - //Logger.print(logTarget, "write : " + cmd); - channel.write(cmd); - } - - private void handle(REPCommand cmd) { - if (cmd==null) return; - ns.writeLog(name +": read "+cmd + " textsize="+text.size()); - Logger.print(logTarget, "read : " + cmd); - switch(cmd.cmd) { - case REPCMD_INSERT : - if (cmd.eid!=eid) { - text.insert(cmd.lineno, cmd.string); - repText.insert(cmd.lineno, cmd.string); - } - forwardCommand(cmd); - break; - case REPCMD_DELETE : - if (cmd.eid!=eid) { - String del=""; - if(cmd.lineno cmds) { - this.cmds = cmds; - timeout=1; - if(selector!=null) selector.wakeup(); - } - - public void setText(List list) { - text = new Text(list); - } - - public void setLogTarget(LogTarget target) { - logTarget = target; - } - - public void setREPText(REPText repText) { - this.repText = repText; - } - - public void addUserInput(REPCommand command) { - cmds.add(command); - if(selector!=null) selector.wakeup(); - } -} diff -r d1bfcff0cdd2 -r 7ff127c8ad64 test/editortest/TestInterManagerSession2.java --- a/test/editortest/TestInterManagerSession2.java Wed Dec 31 18:29:35 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,162 +0,0 @@ -package test.editortest; - - -import java.util.LinkedList; - -import rep.REP; -import rep.REPCommand; -import rep.SessionManager; -import rep.channel.REPServerSocketChannel; -import rep.gui.SessionManagerEvent; - -public class TestInterManagerSession2 extends TestSessionManager2 { - - /* - * All test is performed in localhost, so all session manager - * should have differenct port number each other. - * Test Pattern List - * Connect port for each editor - * Master/client flag for each editor - * Editor or slave session manager must be started by - * master session managers using syncExec. - */ - - public int slavePort[] = {masterPort,masterPort,masterPort}; - public int editorPort[] = {masterPort,masterPort+1,masterPort+2}; - public boolean editorMaster[] = {true,false,false,false}; - private LinkedList editorStartCmds; - - private SessionManagerEvent ev2[] = { - new SessionManagerEvent() { - public void exec(SessionManager manager) { - int i = sessionManagers.length; - for(SessionManager slave:slaveSessionManagers) { - if (slave.getParentPort()==masterPort) { - logger.writeLog("Start slave "+slave); - i = startSessionManager(slave,i,masterPort + i); - } - } - } - }, - new SessionManagerEvent() { - public void exec(SessionManager manager) { - manager.connectSessionManager(host); - } - }, - new SessionManagerEvent() { - public void exec(SessionManager manager) { - // try to make a loop - if (false) { - sessionManagers[0].connectSessionManager(host, - manager.getPort()); - } - manager.connectSessionManager(host); - manager.execAfterConnect( - new SessionManagerEvent() { - public void exec(SessionManager manager) { - for(SessionManager m:sessionManagers) { - startEditor(m); - } - for(SessionManager m:slaveSessionManagers) { - startEditor(m); - } - editors[0].setCommand(editorStartCmds); - } - } - ); - } - - } - }; - //private int inscnt=2; - - private void startEditor(SessionManager m) { - for(TestEditor2 editor:editors) { - if(editor.getPort()==m.getPort()) { - logger.writeLog("Start client "+editor); - editor.start(); - } - } - } - - /* - * Create all editors, master session managers and slave session - * managers with specified port. All instances are not started yet. - */ - - public TestInterManagerSession2(int sm, int ss, int e) { - super(sm,ss,e); - - sessionManagers = new SessionManager[sm]; - slaveSessionManagers = new SessionManager[ss]; - editors = new TestEditor2[e]; - for(int i=0;icmds = new LinkedList(); - 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")); - editors[i] = new TestEditor2("Editor"+i,host,port,master); - //editors[i].setCommand(cmds); - } - setupEditor0(); - } - - private void setupEditor0() { - /* - * do not startup Editor0 until SessionManagers are ready. - * Define pending command and set null command for now. - */ - LinkedListcmds = new LinkedList(); - //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_USER,0,0,0,0,"m0")); - cmds.add(new REPCommand(REP.REPCMD_DELETE_USER,0,0,0,0,"m0")); - cmds.add(new REPCommand(REP.SMCMD_QUIT,0,0,0,0,"")); - editorStartCmds = cmds; - LinkedListnullcmds = new LinkedList(); - editors[0].setCommand(nullcmds); - } - - @Override - public void setSMEvent(SessionManager s,int i) { - if (i commandList; + private LinkedList othersCommandList; + + public static void main(String[] args){ + TestMerger test = new TestMerger(); + test.setCommands(); + test.start(); + } + + public TestMerger(){ + eid = 1; + sid = 1; + trans = new Translator(eid, new NullOptimizer()); + } + + private void setCommands() { + commandList = new LinkedList(); + commandList.add(new REPCommand(REP.REPCMD_INSERT, sid, eid, seq++, 10, "AAAAA")); + commandList.add(new REPCommand(REP.REPCMD_INSERT, sid, eid, seq++, 10, "BBBBB")); + othersCommandList = new LinkedList(); + othersCommandList.add(new REPCommand(REP.REPCMD_INSERT, sid, eid+1, seq++, 10, "CCCCC")); + } + + private void start() { + for(REPCommand command : commandList){ + trans.transSendCmd(command); + } + for(REPCommand command : othersCommandList){ + trans.transSendCmd(command); + } + for(int i = 0; i < commandList.size(); i++){ + trans.catchOwnCommand(this); + System.out.println(); + } + } + + @Override + public void cancel(REPSocketChannel channel1) { + // TODO Auto-generated method stub + + } + + @Override + public void checkWaitingCommandInMerge() { + // TODO Auto-generated method stub + + } + + @Override + public void forwardedCommandManage(REPCommand command) { + // TODO Auto-generated method stub + + } + + @Override + public String getLocalHostName() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void handle(REPCommand command, REPSelectionKey key) + throws IOException { + // TODO Auto-generated method stub + + } + + @Override + public boolean isMerging() { + // TODO Auto-generated method stub + return false; + } + + @Override + public void joinAck(REPCommand sendCommand, int sid) { + // TODO Auto-generated method stub + + } + + @Override + public boolean manage(REPCommand command) { + // TODO Auto-generated method stub + return false; + } + + @Override + public void selectSession(REPCommand sendCommand, Session session) { + // TODO Auto-generated method stub + + } + + @Override + public void send(REPCommand command) { + // TODO Auto-generated method stub + Logger.print(command); + } + + @Override + public void sendWithSeq(REPCommand command) { + // TODO Auto-generated method stub + + } + + @Override + public int seq() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void setQuit2(REPCommand receivedCommand) { + // TODO Auto-generated method stub + + } +} diff -r d1bfcff0cdd2 -r 7ff127c8ad64 test/editortest/TestSessionManager2.java --- a/test/editortest/TestSessionManager2.java Wed Dec 31 18:29:35 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,128 +0,0 @@ -package test.editortest; - -import java.io.IOException; - -import rep.SessionManager; -import rep.channel.REPLogger; -import rep.channel.REPServerSocketChannel; -import rep.gui.SessionManagerEvent; -import rep.gui.SessionManagerGUI; -import rep.handler.Editor; -import test.sematest.TestGUI; - - -public class TestSessionManager2 { - - static public REPLogger logger = REPLogger.singleton(); - public int masterPort = 8766; - public String host = "localhost"; - public SessionManager sessionManagers[]; - public SessionManager slaveSessionManagers[]; - public TestEditor2 editors[]; - - /* - * All test is performed in localhost, so all session manager - * should have differenct port number each other. - */ - - /* - * Test Pattern List - * Connect port for each editor - * Master/client flag for each editor - * Editor or slave session manager must be started by - * master session managers using syncExec. - */ - public int editorPort[] = {masterPort,masterPort,masterPort}; - public boolean editorMaster[] = {true,false,false,false}; - private SessionManagerEvent ev1[] = { - new SessionManagerEvent() { - // executed before first select(); - public void exec(SessionManager manager) { - for(TestEditor2 editor:editors) { - editor.start(); - } - int i = sessionManagers.length; - for(SessionManager slave:slaveSessionManagers) { - i = startSessionManager(slave,i,masterPort + i); - } - } - }}; - - /* - * Create all editors, master session managers and slave session - * managers with specified port. All instances are not started yet. - */ - - public TestSessionManager2(int sm, int ss, int e) { - sessionManagers = new SessionManager[sm]; - slaveSessionManagers = new SessionManager[ss]; - editors = new TestEditor2[e]; - for(int i=0;i editorList; + private LinkedList userInputList; + private JButton initButton; + + public UserSimulator(String title){ + super(title); + + editorList = new LinkedList(); + + setButton(); + pack(); + } + + private void setUserInput() { + userInputList = new LinkedList(); + userInputList.add(new REPCommand(REP.REPCMD_INSERT_USER, 0, 0, 0, 0, "AAAAA")); + userInputList.add(new REPCommand(REP.REPCMD_INSERT_USER, 0, 0, 0, 1, "BBBBB")); + userInputList.add(new REPCommand(REP.REPCMD_INSERT_USER, 0, 0, 0, 2, "CCCCC")); + } + + private void init(){ + setUserInput(); + editorList.get(0).repPut(); + for(int i = 1; i < editorList.size(); i++){ + editorList.get(i).repJoin(); + } + initButton.setEnabled(false); + } + + private void setButton() { + setLayout(new FlowLayout()); + + initButton = new JButton("init"); + startButton = new JButton("start"); + add(initButton); + add(startButton); + + initButton.addActionListener(this); + startButton.addActionListener(this); + } + + public void add(SimpleEditorForREPEditor editor) { + editorList.add(editor); + } + + public void actionPerformed(ActionEvent e) { + if(e.getSource() == startButton){ + userStart(); + }else if(e.getSource() == initButton){ + init(); + } + } + + private void userStart() { + UserThread user = new UserThread(); + user.start(); + } + + class UserThread extends Thread{ + public void run(){ +// for(REPCommand command : userInputList){ + for(int i = 0; i < 5; i++){ + for(SimpleEditorForREPEditor editor : editorList){ + REPCommand command = new REPCommand(REP.REPCMD_INSERT_USER, 0, 0, 0, i, editor.getTitle() + ":" + i); + ((REPTextWithJTextArea) editor.getREPEditor().getREPText()).userInsert(command); + } + } + } + } + +}