Mercurial > hg > RemoteEditor > REPSessionManager
changeset 122:790c8dd42a7b
*** empty log message ***
author | kono |
---|---|
date | Tue, 26 Aug 2008 16:33:47 +0900 |
parents | 80ef604d09dc |
children | 5b1a0574b406 |
files | rep/Editor.java rep/EditorList.java rep/REP.java rep/REPActionListener.java rep/REPPacketReceive.java rep/RPanel.java rep/ServerSample.java rep/SessionList.java rep/SessionManager.java rep/SessionManagerGUI.java rep/xml/SessionXMLEncoder.java test/TestUTF8.java test/XMLTest.java |
diffstat | 13 files changed, 258 insertions(+), 126 deletions(-) [+] |
line wrap: on
line diff
--- a/rep/Editor.java Tue Aug 26 09:52:08 2008 +0900 +++ b/rep/Editor.java Tue Aug 26 16:33:47 2008 +0900 @@ -1,6 +1,7 @@ package rep; import java.nio.channels.SocketChannel; +import java.util.LinkedList; import java.util.StringTokenizer; public class Editor { @@ -11,6 +12,8 @@ private String port; //public int getEID; private String file; + private LinkedList<REPCommand> undoCommandList = new LinkedList<REPCommand>(); + private LinkedList<Integer> temp = new LinkedList<Integer>(); public Editor(int editorNo, SocketChannel channel){ this.eid = editorNo; @@ -82,4 +85,33 @@ myChannel = channel; } + public void addUndoCommand(REPCommand command) { + if(command.cmd == REP.SMCMD_GET_UNDO_ACK){ + command.setCMD((temp.get(0)).intValue()); + temp.remove(); + } + + undoCommandList.addFirst(command); + System.out.println(undoCommandList); +// if(undoCommandList.size() > 10){ +// for(REPCommand undoCommand : undoCommandList){ +// send(undoCommand); +// } +// undoCommandList.clear(); +// } + } + + public void undo() { + // TODO Auto-generated method stub + for(REPCommand undoCommand : undoCommandList){ + send(undoCommand); + } + undoCommandList.clear(); + } + + public void setKindOfUndoCmd(int cmd) { + // TODO Auto-generated method stub + temp .add(cmd); + } + }
--- a/rep/EditorList.java Tue Aug 26 09:52:08 2008 +0900 +++ b/rep/EditorList.java Tue Aug 26 16:33:47 2008 +0900 @@ -107,4 +107,24 @@ return numberOfEditor; } + + public Editor getEditor(SocketChannel channel) { + // TODO Auto-generated method stub + Editor editor1 = null; + for(Editor editor: editorList){ + if(channel == editor.getChannel()){ + editor1 = editor; + } + } + return editor1; + } + + + public void undoAllEditors() { + // TODO Auto-generated method stub + for(Editor editor : editorList){ + editor.undo(); + } + } + }
--- a/rep/REP.java Tue Aug 26 09:52:08 2008 +0900 +++ b/rep/REP.java Tue Aug 26 16:33:47 2008 +0900 @@ -37,4 +37,6 @@ public static final int SMCMD_UPDATE_DOWN = 68; //obsolete public static final int SMCMD_CH_MASTER = 69; public static final int SMCMD_CH_MASTER_ACK = 70; + public static final int SMCMD_GET_UNDO = 71; + public static final int SMCMD_GET_UNDO_ACK = 72; }
--- a/rep/REPActionListener.java Tue Aug 26 09:52:08 2008 +0900 +++ b/rep/REPActionListener.java Tue Aug 26 16:33:47 2008 +0900 @@ -1,5 +1,8 @@ package rep; public interface REPActionListener { + public void ActionOccured(REPActionEvent event); + + public void undo(); }
--- a/rep/REPPacketReceive.java Tue Aug 26 09:52:08 2008 +0900 +++ b/rep/REPPacketReceive.java Tue Aug 26 16:33:47 2008 +0900 @@ -49,7 +49,7 @@ e1.printStackTrace(); } // limit = read length if (len !=HEADER_SIZE) { - System.out.println("‚Ä‚·"); + System.out.println("ã¦ã™"); // this can't happen } header.rewind(); // position = 0 @@ -71,7 +71,7 @@ } // limit = read length if (len != textsiz * 2) { // this can't happen - System.out.println("‚ ‚Æ"); + System.out.println("ã‚ã¨"); } textBuffer.rewind(); for(int i=0;i<textsiz;i++) { @@ -106,7 +106,7 @@ e1.printStackTrace(); } // limit = read length if (len !=HEADER_SIZE) { - System.out.println("‚Ä‚·"); + System.out.println("ã¦ã™"); // this can't happen } header.rewind(); // position = 0 @@ -136,7 +136,7 @@ } // limit = read length if (len != textsiz) { // this can't happen - System.out.println("‚ ‚Æ"); + System.out.println("ã‚ã¨"); } textBuffer.rewind();
--- a/rep/RPanel.java Tue Aug 26 09:52:08 2008 +0900 +++ b/rep/RPanel.java Tue Aug 26 16:33:47 2008 +0900 @@ -53,6 +53,8 @@ private JComboBox comboSession; private JButton buttonSelect; private REPActionListener actionListener; + private JButton buttonUndo; + private REPActionListener undoListener; public RPanel() { button = new JButton("Connect"); @@ -70,6 +72,7 @@ comboEditor = new JComboBox(); comboSession = new JComboBox(); buttonSelect = new JButton("Select"); + buttonUndo = new JButton("Undo"); button.setBounds(160, 5, 100, 20); @@ -91,6 +94,7 @@ comboEditor.setBounds(450, 50, 100, 50); comboSession.setBounds(450, 100, 100, 50); buttonSelect.setBounds(450, 180, 100, 20); + buttonUndo.setBounds(450, 140, 100, 20); this.setLayout(null); @@ -106,9 +110,11 @@ //this.add(comboEditor); //this.add(comboSession); this.add(buttonSelect); + this.add(buttonUndo); button.addActionListener(this); buttonSelect.addActionListener(this); + buttonUndo.addActionListener(this); } public void addSessionTree(int SID){ @@ -126,6 +132,9 @@ */ actionListener.ActionOccured(new REPActionEvent((EditorPlus) e_list.get(editor_table.getSelectedRow()), (SessionPlus)s_list.get(session_table.getSelectedRow()))); + }else if(event.getSource() == buttonUndo){ + //System.out.println("Undo!"); + actionListener.undo(); } } @@ -133,13 +142,17 @@ System.out.println(listener.toString()); this.listener = listener; } + + public void addUndoListener(REPActionListener listener3){ + undoListener = listener3; + } public void setComboEditor(int eid, SocketChannel channel) { //comboEditor.addItem("Editor:"+eid); comboEditor.addItem(new EditorPlus(eid, channel)); } - public void REPActionListener(REPActionListener listener2) { + public void addREPActionListener(REPActionListener listener2) { this.actionListener = listener2; }
--- a/rep/ServerSample.java Tue Aug 26 09:52:08 2008 +0900 +++ b/rep/ServerSample.java Tue Aug 26 16:33:47 2008 +0900 @@ -6,88 +6,88 @@ public class ServerSample { - public static void main(String[] argv) - throws Exception - { - // セレクタã®ç”¨æ„ - Selector selector = Selector.open(); +public static void main(String[] argv) +throws Exception +{ +// セレクタã®ç”¨æ„ +Selector selector = Selector.open(); - // サーãƒã‚½ã‚±ãƒƒãƒˆãƒãƒ£ãƒ³ãƒãƒ«ã‚’作æˆã€‚5100番ãƒãƒ¼ãƒˆã‚’å—付ãƒãƒ¼ãƒˆã«æŒ‡å®š - // (éžãƒ–ãƒãƒƒã‚¯ãƒ¢ãƒ¼ãƒ‰ã«è¨å®šï¼šé‡è¦ï¼‰ - ServerSocketChannel serverSocketChannel = ServerSocketChannel.open(); - serverSocketChannel.configureBlocking(false); - serverSocketChannel.socket().bind(new InetSocketAddress(5100)); +// サーãƒã‚½ã‚±ãƒƒãƒˆãƒãƒ£ãƒ³ãƒãƒ«ã‚’作æˆã€‚5100番ãƒãƒ¼ãƒˆã‚’å—付ãƒãƒ¼ãƒˆã«æŒ‡å®š +// (éžãƒ–ãƒãƒƒã‚¯ãƒ¢ãƒ¼ãƒ‰ã«è¨å®šï¼šé‡è¦ï¼‰ +ServerSocketChannel serverSocketChannel = ServerSocketChannel.open(); +serverSocketChannel.configureBlocking(false); +serverSocketChannel.socket().bind(new InetSocketAddress(5100)); - // セレクタã«ã‚µãƒ¼ãƒã‚½ã‚±ãƒƒãƒˆãƒãƒ£ãƒ³ãƒãƒ«ã‚’登録。サーãƒã¸ã®å—付を監視 - serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT); +// セレクタã«ã‚µãƒ¼ãƒã‚½ã‚±ãƒƒãƒˆãƒãƒ£ãƒ³ãƒãƒ«ã‚’登録。サーãƒã¸ã®å—付を監視 +serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT); - // セレクタã«ã‚¤ãƒ™ãƒ³ãƒˆãŒé€šçŸ¥ã•ã‚Œã‚‹ã”ã¨ã«å‡¦ç† - while (true) { +// セレクタã«ã‚¤ãƒ™ãƒ³ãƒˆãŒé€šçŸ¥ã•ã‚Œã‚‹ã”ã¨ã«å‡¦ç† +while (true) { - // セレクタã«ã‚¤ãƒ™ãƒ³ãƒˆãŒç™ºç”Ÿã™ã‚‹ã¾ã§ãƒ–ãƒãƒƒã‚¯ - selector.select(); +// セレクタã«ã‚¤ãƒ™ãƒ³ãƒˆãŒç™ºç”Ÿã™ã‚‹ã¾ã§ãƒ–ãƒãƒƒã‚¯ +selector.select(); - // ç²å¾—ã—ãŸã‚¤ãƒ™ãƒ³ãƒˆã”ã¨ã«å‡¦ç†ã‚’実行 - for (SelectionKey selectionKey : selector.selectedKeys()) { +// ç²å¾—ã—ãŸã‚¤ãƒ™ãƒ³ãƒˆã”ã¨ã«å‡¦ç†ã‚’実行 +for (SelectionKey selectionKey : selector.selectedKeys()) { - // サーãƒã®å—付処ç†: - // イベントãŒå—付å¯èƒ½ã§ã‚ã‚‹å ´åˆã€å—ã‘付ã‘ã‚‹ã¹ã対象ãŒã‚れ㰠- // セレクタã«å–å¾—ã—ãŸã‚½ã‚±ãƒƒãƒˆãƒãƒ£ãƒ³ãƒãƒ«ã‚’登録 - if (selectionKey.isAcceptable()) { +// サーãƒã®å—付処ç†: +// イベントãŒå—付å¯èƒ½ã§ã‚ã‚‹å ´åˆã€å—ã‘付ã‘ã‚‹ã¹ã対象ãŒã‚れ㰠+// セレクタã«å–å¾—ã—ãŸã‚½ã‚±ãƒƒãƒˆãƒãƒ£ãƒ³ãƒãƒ«ã‚’登録 +if (selectionKey.isAcceptable()) { - // サーãƒã‚½ã‚±ãƒƒãƒˆãƒãƒ£ãƒ³ãƒãƒ«ã‹ã‚‰ã‚½ã‚±ãƒƒãƒˆãƒãƒ£ãƒ³ãƒãƒ«ã‚’ç²å¾— - // ソケットãƒãƒ£ãƒ³ãƒãƒ«ã‚’経由ã—ã¦ã‚¯ãƒ©ã‚¤ã‚¢ãƒ³ãƒˆã¨é€šä¿¡ã§ãã‚‹ - SocketChannel socketChannel = serverSocketChannel.accept(); +// サーãƒã‚½ã‚±ãƒƒãƒˆãƒãƒ£ãƒ³ãƒãƒ«ã‹ã‚‰ã‚½ã‚±ãƒƒãƒˆãƒãƒ£ãƒ³ãƒãƒ«ã‚’ç²å¾— +// ソケットãƒãƒ£ãƒ³ãƒãƒ«ã‚’経由ã—ã¦ã‚¯ãƒ©ã‚¤ã‚¢ãƒ³ãƒˆã¨é€šä¿¡ã§ãã‚‹ +SocketChannel socketChannel = serverSocketChannel.accept(); - // 接続先ãŒãªãã¦ã‚‚ã“ã“ã«å‡¦ç†ãŒé£›ã¶ã“ã¨ãŒã‚る。対象㌠- // nullã®å ´åˆã¯å‡¦ç†ã‚’抜ã‘ã‚‹ - if (null == socketChannel) continue; +// 接続先ãŒãªãã¦ã‚‚ã“ã“ã«å‡¦ç†ãŒé£›ã¶ã“ã¨ãŒã‚る。対象㌠+// nullã®å ´åˆã¯å‡¦ç†ã‚’抜ã‘ã‚‹ +if (null == socketChannel) continue; - // ソケットãƒãƒ£ãƒ³ãƒãƒ«ã‚’éžãƒ–ãƒãƒƒã‚¯ãƒ¢ãƒ¼ãƒ‰ã«è¨å®šï¼ˆé‡è¦ï¼‰ã—〠- // セレクタã«èªã¿è¾¼ã¿ã‚’対象ã¨ã—ã¦ç™»éŒ² - socketChannel.configureBlocking(false); - socketChannel.register(selector, SelectionKey.OP_READ); - socketChannel = null; - } +// ソケットãƒãƒ£ãƒ³ãƒãƒ«ã‚’éžãƒ–ãƒãƒƒã‚¯ãƒ¢ãƒ¼ãƒ‰ã«è¨å®šï¼ˆé‡è¦ï¼‰ã—〠+// セレクタã«èªã¿è¾¼ã¿ã‚’対象ã¨ã—ã¦ç™»éŒ² +socketChannel.configureBlocking(false); +socketChannel.register(selector, SelectionKey.OP_READ); +socketChannel = null; +} - // クライアントã¨ã®é€šä¿¡å‡¦ç† - // èªè¾¼ã¿å¯èƒ½ã§ã‚ã‚‹å ´åˆã€å†…容物をèªã¿ã“ã‚“ã§æ¨™æº–出力ã«è¡¨ç¤ºã€‚ - // メッセージをクライアントã«é€ä¿¡ã—ã¦ã€ã‚³ãƒã‚¯ã‚·ãƒ§ãƒ³ã‚’切æ–。 - // セレクタã‹ã‚‰ç™»éŒ²ã‚’解除 - else if (selectionKey.isReadable()) { +// クライアントã¨ã®é€šä¿¡å‡¦ç† +// èªè¾¼ã¿å¯èƒ½ã§ã‚ã‚‹å ´åˆã€å†…容物をèªã¿ã“ã‚“ã§æ¨™æº–出力ã«è¡¨ç¤ºã€‚ +// メッセージをクライアントã«é€ä¿¡ã—ã¦ã€ã‚³ãƒã‚¯ã‚·ãƒ§ãƒ³ã‚’切æ–。 +// セレクタã‹ã‚‰ç™»éŒ²ã‚’解除 +else if (selectionKey.isReadable()) { - // 登録ã•ã‚Œã¦ã„るソケットãƒãƒ£ãƒ³ãƒãƒ«ã‚’å–å¾— - SocketChannel socketChannel = - (SocketChannel)selectionKey.channel(); +// 登録ã•ã‚Œã¦ã„るソケットãƒãƒ£ãƒ³ãƒãƒ«ã‚’å–å¾— +SocketChannel socketChannel = +(SocketChannel)selectionKey.channel(); - Charset charset = Charset.forName("US-ASCII"); - ByteBuffer byteBuffer = ByteBuffer.allocate(8192); +Charset charset = Charset.forName("US-ASCII"); +ByteBuffer byteBuffer = ByteBuffer.allocate(8192); - // クライアントã‹ã‚‰ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã®å—ä¿¡ - switch (socketChannel.read(byteBuffer)) { - case -1: - // クライアントå´ãŒæŽ¥ç¶šã‚’切æ–ã—ã¦ã„ãŸå ´åˆã¯ã€ã‚µãƒ¼ãƒã‚‚ - // 接続を切æ–。セレクタã‹ã‚‰ç™»éŒ²ã‚’削除 - socketChannel.close(); - break; - case 0: - // èªã¿è¾¼ã‚€ã¹ãメッセージã¯å±Šã„ã¦ã„ãªã„ã®ã§å‡¦ç†ã‚’飛ã°ã™ - continue; - default: - // クライアントã‹ã‚‰ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã‚’å–å¾—ã—ã€æ¨™æº–出力㸠- byteBuffer.flip(); - System.out.print("EEE: " + charset.decode(byteBuffer)); +// クライアントã‹ã‚‰ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã®å—ä¿¡ +switch (socketChannel.read(byteBuffer)) { +case -1: +// クライアントå´ãŒæŽ¥ç¶šã‚’切æ–ã—ã¦ã„ãŸå ´åˆã¯ã€ã‚µãƒ¼ãƒã‚‚ +// 接続を切æ–。セレクタã‹ã‚‰ç™»éŒ²ã‚’削除 +socketChannel.close(); +break; +case 0: +// èªã¿è¾¼ã‚€ã¹ãメッセージã¯å±Šã„ã¦ã„ãªã„ã®ã§å‡¦ç†ã‚’飛ã°ã™ +continue; +default: +// クライアントã‹ã‚‰ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã‚’å–å¾—ã—ã€æ¨™æº–出力㸠+byteBuffer.flip(); +System.out.print("EEE: " + charset.decode(byteBuffer)); - // クライアントã¸ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã‚’é€ä¿¡ - socketChannel.write(charset.encode("Good bye!\r\n")); +// クライアントã¸ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã‚’é€ä¿¡ +socketChannel.write(charset.encode("Good bye!\r\n")); - // クライアントã¨ã®æŽ¥ç¶šã‚’切æ–。セレクタã‹ã‚‰ç™»éŒ²ã‚’削除 - //socketChannel.close(); - break; - } - } - System.out.println(selectionKey.toString()); - } - } - } +// クライアントã¨ã®æŽ¥ç¶šã‚’切æ–。セレクタã‹ã‚‰ç™»éŒ²ã‚’削除 +//socketChannel.close(); +break; +} +} +System.out.println(selectionKey.toString()); +} +} +} } \ No newline at end of file
--- a/rep/SessionList.java Tue Aug 26 09:52:08 2008 +0900 +++ b/rep/SessionList.java Tue Aug 26 16:33:47 2008 +0900 @@ -16,6 +16,7 @@ private boolean channelequals = false; private LinkedList<Session> tmpSessionList = new LinkedList<Session>(); private String maxHost; + private LinkedList<Integer> temp = new LinkedList<Integer>(); //private TranslaterImp1 translater; @@ -51,9 +52,9 @@ public void addEditor(SocketChannel channel, int sid, REPCommand repCmd) { int editorID = repCmd.eid; -// if(session3.get(sid) == null) System.out.println("‚Ê‚é‚ÛI"); +// if(session3.get(sid) == null) System.out.println("ã¬ã‚‹ã½ï¼"); // session3.get(sid).addEditor(editorID, channel); - sessionLinkedList.get(sid-1).addEditor(editorID, channel); //–{“–‚Íforƒ‹[ƒv‚ÅŒŸõ‚µ‚È‚¢‚Æ‚¢‚¯‚È‚¢‚æB + sessionLinkedList.get(sid-1).addEditor(editorID, channel); //本当ã¯forループã§æ¤œç´¢ã—ãªã„ã¨ã„ã‘ãªã„よ。 } // public int getSessionID(SocketChannel channel) { @@ -67,7 +68,7 @@ public void sendCmd(SocketChannel channel2, REPCommand repCmd) { // LinkedList <Editor> editorList = session3.get(repCmd.sid).getEditorList(); - LinkedList <Editor> editorList = sessionLinkedList.get(repCmd.sid).getEditorList(); //‚±‚±‚àforƒ‹[ƒv‚ÅŒŸõ‚µ‚È‚¢‚Æ‚¢‚¯‚È‚¢‚æB + LinkedList <Editor> editorList = sessionLinkedList.get(repCmd.sid).getEditorList(); //ã“ã“ã‚‚forループã§æ¤œç´¢ã—ãªã„ã¨ã„ã‘ãªã„よ。 for(Editor editor : editorList){ SocketChannel channel = editor.getChannel(); if(channel.equals(channel2)) { @@ -81,7 +82,7 @@ public void sendCmd(SocketChannel channel, REPCommand repCmd, boolean ring){ // LinkedList <Editor> editorList = session3.get(repCmd.sid).getEditorList(); - LinkedList <Editor> editorList = sessionLinkedList.get(repCmd.sid).getEditorList(); //‚±‚±‚àforƒ‹[ƒv‚ÅŒŸõ‚µ‚È‚¢‚Æ‚¢‚¯‚È‚¢‚æB + LinkedList <Editor> editorList = sessionLinkedList.get(repCmd.sid).getEditorList(); //ã“ã“ã‚‚forループã§æ¤œç´¢ã—ãªã„ã¨ã„ã‘ãªã„よ。 REPPacketSend repsend = null; for(Editor editor : editorList){ SocketChannel channel2 = editor.getChannel(); @@ -122,7 +123,7 @@ Editor editor3; // LinkedList <Editor> editorList = session3.get(repCmd.sid).getEditorList(); // this.getSession(sid); - LinkedList <Editor> editorList = sessionLinkedList.get(repCmd.sid-1).getEditorList(); //‚±‚±‚àforƒ‹[ƒv‚ÅŒŸõ‚µ‚È‚¢‚Æ‚¢‚¯‚È‚¢‚æB + LinkedList <Editor> editorList = sessionLinkedList.get(repCmd.sid-1).getEditorList(); //ã“ã“ã‚‚forループã§æ¤œç´¢ã—ãªã„ã¨ã„ã‘ãªã„よ。 for(Editor editor : editorList){ SocketChannel channel2 = editor.getChannel(); if(channel.equals(channel2)){ @@ -139,12 +140,35 @@ editor3 = editorList.get(editorList.indexOf(editor2)+1); } if(editor3 != null){ + //temp.add(repCmd.cmd); + REPCommand getUndoCommand = new REPCommand(); + getUndoCommand.setCMD(REP.SMCMD_GET_UNDO); + getUndoCommand.lineno = repCmd.lineno; + editor3.send(getUndoCommand); + editor3.setKindOfUndoCmd(reverseCmd(repCmd.cmd)); editor3.send(repCmd); //REPPacketSend send = new REPPacketSend(editor3.getChannel()); //send.send(repCmd); } } + private int reverseCmd(int cmd) { + // TODO Auto-generated method stub + int kindOfCmd = 0; + switch(cmd){ + case REP.REPCMD_INSERT: + kindOfCmd = REP.REPCMD_DELETE; + break; + case REP.REPCMD_DELETE: + kindOfCmd = REP.REPCMD_INSERT; + break; + case REP.REPCMD_REPLACE: + kindOfCmd = REP.REPCMD_REPLACE; + break; + } + return kindOfCmd; + } + public void addEditor(SocketChannel editorChannel, int sid, int eid) { // session3.get(sid).addEditor(eid, editorChannel); sessionLinkedList.get(sid-1).addEditor(eid, editorChannel); @@ -162,7 +186,7 @@ } // public String getXML() { -///* SessionList‚ðXML‚É‘‚«o‚·B‚Æ‚«‚ÌŒ`Ž® +///* SessionListã‚’XMLã«æ›¸ã出ã™ã€‚ã¨ãã®å½¢å¼ // * <Session> // * <editor> // * <sid/>
--- a/rep/SessionManager.java Tue Aug 26 09:52:08 2008 +0900 +++ b/rep/SessionManager.java Tue Aug 26 16:33:47 2008 +0900 @@ -26,8 +26,8 @@ //o-------header section (network order)-------------o /*int cmd; // command int sid; // session ID : uniqu to editing file -int eid; // editor ID : owner editor ID = 1BSession ‚ɑ΂µ‚ă†ƒj[ƒN -int seqno; // Sequence number : sequence number ‚̓GƒfƒBƒ^‚²‚Æ‚ÉŠÇ— +int eid; // editor ID : owner editor ID = 1。Session ã«å¯¾ã—ã¦ãƒ¦ãƒ‹ãƒ¼ã‚¯ +int seqno; // Sequence number : sequence number ã¯ã‚¨ãƒ‡ã‚£ã‚¿ã”ã¨ã«ç®¡ç† int lineno; // line number int textsize; // textsize : bytesize byte[] text;*/ @@ -42,7 +42,7 @@ private SessionManagerList smList; private String myHost; private boolean isMaster = true; - private EditorList allEditorList; + private EditorList ownEditorList; private String maxHost; //private boolean addressIsGlobal; //private SocketChannel sessionchannel; @@ -63,7 +63,7 @@ public void sessionManagerNet(int port) throws InterruptedException, IOException { ServerSocketChannel ssc = ServerSocketChannel.open(); - ssc.configureBlocking(false); //reuse address •K{ + ssc.configureBlocking(false); //reuse address å¿…é ˆ ssc.socket().setReuseAddress(true); @@ -73,20 +73,20 @@ sessionlist = new SessionList(); smList = new SessionManagerList(); - allEditorList = new EditorList(); + ownEditorList = new EditorList(); while(true){ selector.select(); for(SelectionKey key : selector.selectedKeys()){ if(key.isAcceptable()){ - /*** serverChannel‚Íenable‚É‚È‚Á‚½SelectionKey‚Ìchannel ***/ + /*** serverChannelã¯enableã«ãªã£ãŸSelectionKeyã®channel ***/ ServerSocketChannel serverChannel = (ServerSocketChannel)key.channel(); - /*** EditorChannel ‚ð—p‚¢‚È‚¢‹Lq ***/ - SocketChannel channel = serverChannel.accept(); //key‚©‚çchannel‚ðŽæ‚Á‚ÄAaccept + /*** EditorChannel を用ã„ãªã„記述 ***/ + SocketChannel channel = serverChannel.accept(); //keyã‹ã‚‰channelã‚’å–ã£ã¦ã€accept registerChannel (selector, channel, SelectionKey.OP_READ); channel = null; - /*** EditorChannel ‚ð—p‚¢‚½‹Lq ****/ + /*** EditorChannel を用ã„ãŸè¨˜è¿° ****/ //EditorChannel echannel = (EditorChannel) ssc.accept(); //echannel.setIO(); //registerChannel(selector, echannel, SelectionKey.OP_READ); @@ -101,15 +101,15 @@ }else if(key.isReadable()){ - /*** EditorChannel ‚ð—p‚¢‚È‚¢‹Lq ***/ + /*** EditorChannel を用ã„ãªã„記述 ***/ SocketChannel channel = (SocketChannel)key.channel(); - REPPacketReceive receive = new REPPacketReceive(channel); //getPacket(), putPacket() ‚É‚·‚éB + REPPacketReceive receive = new REPPacketReceive(channel); //getPacket(), putPacket() ã«ã™ã‚‹ã€‚ receive.setkey(key); REPCommand receivedCommand = receive.unpackUConv(); //REPCommand receivedCommand = receive.unpack(); manager(channel, receivedCommand); - /*** EditorChannel ‚ð—p‚¢‚½‹Lq ****/ + /*** EditorChannel を用ã„ãŸè¨˜è¿° ****/ //EditorChannel echannel = (EditorChannel) key.channel(); //REPCommand command = echannel.getPacket(); //manager(echannel, command); @@ -144,7 +144,7 @@ case REP.SMCMD_JOIN: editor = new Editor(channel); editor.setHost(myHost); - int tempeid = allEditorList.addEditor(editor); + int tempeid = ownEditorList.addEditor(editor); gui.setComboEditor(tempeid, channel); break; @@ -158,7 +158,7 @@ case REP.SMCMD_PUT: editor = new Editor(channel); editor.setHost(myHost); - allEditorList.addEditor(editor); + ownEditorList.addEditor(editor); editor.setEID(1); //String string2 = setUTF16(receivedCommand.string); editor.setName(receivedCommand.string); @@ -198,7 +198,7 @@ // break; case REP.SMCMD_SELECT: -// sessionlist.addEditor(channel, repCmd.sid, repCmd); //sessionlist‚֒ljÁ +// sessionlist.addEditor(channel, repCmd.sid, repCmd); //sessionlistã¸è¿½åŠ editor = new Editor(channel); session = sessionlist.getSession(receivedCommand.sid); @@ -223,7 +223,7 @@ case REP.SMCMD_SELECT_ACK: String hostport = receivedCommand.string; - Editor editor2 = allEditorList.getEditor(hostport); + Editor editor2 = ownEditorList.getEditor(hostport); if(editor2 != null) { REPCommand command2 = new REPCommand(); command2.setCMD(REP.SMCMD_JOIN_ACK); @@ -245,20 +245,20 @@ case REP.SMCMD_SM_JOIN: - //SessionManager‚̃ŠƒXƒg‚֒ljÁ + //SessionManagerã®ãƒªã‚¹ãƒˆã¸è¿½åŠ smList.add(channel); - //XML‚©‚çSessionListƒIƒuƒWƒFƒNƒg‚𶬂·‚éB + //XMLã‹ã‚‰SessionListオブジェクトを生æˆã™ã‚‹ã€‚ SessionXMLDecoder decoder = new SessionXMLDecoder(); SessionList receivedSessionList = decoder.decode(receivedCommand.string); - //SessionList‚֒ljÁ‚µ•ÏŠ·ƒe[ƒuƒ‹‚𶬂·‚éB + //SessionListã¸è¿½åŠ ã—変æ›ãƒ†ãƒ¼ãƒ–ルを生æˆã™ã‚‹ã€‚ sessionlist.update(channel, receivedSessionList); - //myHost ‚ðÝ’èB + //myHost ã‚’è¨å®šã€‚ if(myHost == null) setMyHostName(getLocalHostName(channel)); - //maxHost ‚ðÝ’èB + //maxHost ã‚’è¨å®šã€‚ if(setMaxHost(channel, receivedSessionList.getMaxHost())){ sendCommand = new REPCommand(); sendCommand.setCMD(REP.SMCMD_CH_MASTER); @@ -266,21 +266,21 @@ smList.sendExcept(channel, sendCommand); } - //SessionList‚©‚çXML‚ð¶¬B - //join‚µ‚Ä‚«‚½SessionManager‚ɑ΂µ‚ÄACK‚ð‘—MB + //SessionListã‹ã‚‰XMLを生æˆã€‚ + //joinã—ã¦ããŸSessionManagerã«å¯¾ã—ã¦ACKã‚’é€ä¿¡ã€‚ SessionXMLEncoder sessionlistEncoder = new SessionXMLEncoder(sessionlist); sendCommand = new REPCommand(); sendCommand.setCMD(REP.SMCMD_SM_JOIN_ACK); sendCommand.setString(sessionlistEncoder.sessionListToXML()); send.send(sendCommand); - //‚»‚Ì‘¼‚Ì SessionManager ‚ɑ΂µ‚Ä SMCMD_UPDATE‚ð ‘—MB + //ãã®ä»–ã® SessionManager ã«å¯¾ã—㦠SMCMD_UPDATEã‚’ é€ä¿¡ã€‚ sendCommand = new REPCommand(); sendCommand.setCMD(REP.SMCMD_UPDATE); sendCommand.setString(receivedCommand.string); smList.sendExcept(channel, sendCommand); - //‚»‚Ì‘¼‚ÌSessionManager‚ɑ΂µ‚ÄSMCMD_SM_JOIN‚ð‘—MB + //ãã®ä»–ã®SessionManagerã«å¯¾ã—ã¦SMCMD_SM_JOINã‚’é€ä¿¡ã€‚ //sendCommand = new REPCommand(); //sendCommand.setCMD(REP.SMCMD_SM_JOIN); //sendCommand.setString(receivedCommand.string); @@ -294,11 +294,11 @@ case REP.SMCMD_SM_JOIN_ACK: - //XML‚©‚çSessionListƒIƒuƒWƒFƒNƒg‚ð¶¬B + //XMLã‹ã‚‰SessionListオブジェクトを生æˆã€‚ SessionXMLDecoder decoder2 = new SessionXMLDecoder(); SessionList receivedSessionList2 = decoder2.decode(receivedCommand.string); - //maxHost‚ðŒˆ’èB + //maxHostを決定。 if(setMaxHost(channel, receivedSessionList2.getMaxHost())){ sendCommand = new REPCommand(); sendCommand.setCMD(REP.SMCMD_CH_MASTER); @@ -317,7 +317,7 @@ SessionXMLDecoder decoder3 = new SessionXMLDecoder(); SessionList receivedSessionList3 = decoder3.decode(receivedCommand.string); - //SessionList‚֒ljÁ‚µ•ÏŠ·ƒe[ƒuƒ‹‚𶬂·‚éB + //SessionListã¸è¿½åŠ ã—変æ›ãƒ†ãƒ¼ãƒ–ルを生æˆã™ã‚‹ã€‚ sessionlist.update(channel, receivedSessionList3); smList.sendExcept(channel, receivedCommand); @@ -326,7 +326,7 @@ gui.setComboSession(session3.getSID(), session3.getName()); } - //Session‚Ìowner‚ÌEditor + //Sessionã®ownerã®Editor //editor = new Editor(channel); //editor.setName(receivedCommand.string); @@ -368,7 +368,7 @@ // break; case REP.SMCMD_CH_MASTER: - //maxHost ‚ðÝ’èB + //maxHost ã‚’è¨å®šã€‚ if(setMaxHost(channel, receivedCommand.string)){ sendCommand = new REPCommand(); sendCommand.setCMD(REP.SMCMD_CH_MASTER); @@ -377,13 +377,44 @@ } break; + case REP.SMCMD_GET_UNDO_ACK: + editor = ownEditorList.getEditor(channel); + editor.addUndoCommand(receivedCommand); + break; + default: //sessionlist.sendCmd(channel, repCmd); + editor = ownEditorList.getEditor(channel); + if(receivedCommand.seq < 0){ + //editor = ownEditorList.getEditor(channel); + if(editor != null) { + editor.addUndoCommand(receivedCommand); + } + break; + } + //editor.setKindOfUndoCmd(reverseCmd(receivedCommand.cmd)); sessionlist.sendToNextEditor(channel, receivedCommand); break; } } + private int reverseCmd(int cmd) { + // TODO Auto-generated method stub + int kindOfCmd = 0; + switch(cmd){ + case REP.REPCMD_INSERT: + kindOfCmd = REP.REPCMD_DELETE; + break; + case REP.REPCMD_DELETE: + kindOfCmd = REP.REPCMD_INSERT; + break; + case REP.REPCMD_REPLACE: + kindOfCmd = REP.REPCMD_REPLACE; + break; + } + return kindOfCmd; + } + private String setUTF16(String string) { //CharBuffer cb = CharBuffer.wrap(string); Charset charset = Charset.forName("UTF-16"); @@ -409,8 +440,8 @@ sessionlist.setMaxHost(maxHost); } if(host.compareTo(maxHost) > 0){ - //host > MaxHost ‚È‚ç maxHost = host - //master‚ðÝ’è‚·‚éB + //host > MaxHost ãªã‚‰ maxHost = host + //masterã‚’è¨å®šã™ã‚‹ã€‚ maxHost = host; sessionlist.setMaxHost(maxHost); setMaster(false, channel); @@ -426,7 +457,7 @@ maxHost = myHost; sessionlist.setMaxHost(maxHost); } - allEditorList.setHost(myHost); + ownEditorList.setHost(myHost); } private void setMaster(boolean b, SocketChannel channel) { @@ -482,23 +513,23 @@ private void sm_join(SocketChannel channel){ - //SM_JOINƒRƒ}ƒ“ƒh‚ð¶¬B + //SM_JOINコマンドを生æˆã€‚ REPCommand command = new REPCommand(); command.setCMD(REP.SMCMD_SM_JOIN); - //hostname‚ðƒZƒbƒgB + //hostnameをセット。 setMyHostName(getLocalHostName(channel)); - //XML‚ð¶¬B‘—MƒRƒ}ƒ“ƒh‚ɃZƒbƒgB + //XMLを生æˆã€‚é€ä¿¡ã‚³ãƒžãƒ³ãƒ‰ã«ã‚»ãƒƒãƒˆã€‚ SessionXMLEncoder encoder = new SessionXMLEncoder(sessionlist); String string = encoder.sessionListToXML(); command.setString(string); - //SM_JOINƒRƒ}ƒ“ƒh‚ð‘—MB + //SM_JOINコマンドをé€ä¿¡ã€‚ REPPacketSend send = new REPPacketSend(channel); send.send(command); - //SessionManager‚ÌList‚ɒljÁB + //SessionManagerã®Listã«è¿½åŠ 。 smList.add(channel); } @@ -526,7 +557,7 @@ public void ActionOccured(REPActionEvent event) { - /*** Œ³‚Ì ***/ + /*** 元㮠***/ // SocketChannel editorChannel = event.getEditorChannel(); // int sid = event.getSID(); // Editor editor = new Editor(editorChannel); @@ -542,7 +573,7 @@ // command.setString(editor.getHost() + ":" + editor.getPort()); // owner.send(command); - /*** ‘‚«’¼‚µ ***/ + /*** 書ãç›´ã— ***/ SocketChannel channel = event.getEditorChannel(); int sid = event.getSID(); Session session = sessionlist.getSession(sid); @@ -579,4 +610,10 @@ //sessionlist.sendSelect(sid); } + + public void undo() { + // TODO Auto-generated method stub + ownEditorList.undoAllEditors(); + System.out.println("Undo!"); + } }
--- a/rep/SessionManagerGUI.java Tue Aug 26 09:52:08 2008 +0900 +++ b/rep/SessionManagerGUI.java Tue Aug 26 16:33:47 2008 +0900 @@ -58,7 +58,7 @@ public void addREPActionListener(REPActionListener listener) { // TODO Auto-generated method stub - rp.REPActionListener(listener); + rp.addREPActionListener(listener); } public void setComboSession(int sessionID, String string) { @@ -66,4 +66,5 @@ rp.setComboSession(sessionID, string); rp.setTableSession(sessionID, string); } + } \ No newline at end of file
--- a/rep/xml/SessionXMLEncoder.java Tue Aug 26 09:52:08 2008 +0900 +++ b/rep/xml/SessionXMLEncoder.java Tue Aug 26 16:33:47 2008 +0900 @@ -38,7 +38,7 @@ } public String sessionListToXML() { - /* SessionList‚ðXML‚É‘‚«o‚·B‚Æ‚«‚ÌŒ`Ž® + /* SessionListã‚’XMLã«æ›¸ã出ã™ã€‚ã¨ãã®å½¢å¼ * <Session> * <editor> * <sid> 1 </sid>
--- a/test/TestUTF8.java Tue Aug 26 09:52:08 2008 +0900 +++ b/test/TestUTF8.java Tue Aug 26 16:33:47 2008 +0900 @@ -100,7 +100,7 @@ } public static void main(String[] args) throws IOException{ - String text = "‚ ‚¢‚¤‚¦‚¨A‚©‚«‚‚¯‚±A‚³‚µ‚·‚¹‚»"; + String text = "ã‚ã„ã†ãˆãŠã€ã‹ããã‘ã“ã€ã•ã—ã™ã›ã"; REP rep; REPCommand utf8buf = new REPCommand(1, 2, 3, 4, 5, 0, text); REPCommand buf = new REPCommand(1, 2, 3, 4, 5, 0, text);
--- a/test/XMLTest.java Tue Aug 26 09:52:08 2008 +0900 +++ b/test/XMLTest.java Tue Aug 26 16:33:47 2008 +0900 @@ -29,16 +29,16 @@ sessionlist.setMaxHost("naha.ie.u-ryukyu.ac.jp"); sessionlist.addSession(session); - /*** SessionList ‚©‚ç XML ‚Ö ***/ + /*** SessionList ã‹ã‚‰ XML 㸠***/ //SessionXMLEncoder encoder = new SessionXMLEncoder(sessionlist.getList()); SessionXMLEncoder encoder = new SessionXMLEncoder(sessionlist); System.out.println(encoder.sessionListToXML()); - /*** XML ‚©‚ç SessionList ‚Ö ***/ + /*** XML ã‹ã‚‰ SessionList 㸠***/ SessionXMLDecoder decoder = new SessionXMLDecoder(); SessionList sessionlist2 = decoder.decode(encoder.sessionListToXML()); - /*** SessionList ‚©‚ç XML ‚Ö ***/ + /*** SessionList ã‹ã‚‰ XML 㸠***/ //SessionXMLEncoder encoder2 = new SessionXMLEncoder(sessionlist2.getList()); SessionXMLEncoder encoder2 = new SessionXMLEncoder(sessionlist2); System.out.println(encoder2.sessionListToXML());