Mercurial > hg > RemoteEditor > REPSessionManager
changeset 179:763aad2da6b3
*** empty log message ***
author | pin |
---|---|
date | Thu, 28 Aug 2008 22:53:05 +0900 |
parents | a097b1d619a1 |
children | f34608ae1ed2 |
files | rep/Editor.java rep/REPActionListener.java rep/RPanel.java rep/Session.java rep/SessionManager.java rep/SessionManagerGUI.java rep/xml/SessionXMLDecoder.java rep/xml/SessionXMLEncoder.java test/XMLTest.java |
diffstat | 9 files changed, 36 insertions(+), 78 deletions(-) [+] |
line wrap: on
line diff
--- a/rep/Editor.java Thu Aug 28 22:04:48 2008 +0900 +++ b/rep/Editor.java Thu Aug 28 22:53:05 2008 +0900 @@ -1,7 +1,5 @@ package rep; -import java.io.IOException; -import java.nio.ByteBuffer; import java.util.LinkedList; import java.util.List; @@ -53,6 +51,15 @@ translater.transSendCmd(command); list.add(command); } + }else if(eid == REP.MERGE_EID){ + //マージコマンドが返ってきた + if(translater.checkMergeConflict(command)){ + //マージ中にエディタからの割り込みがあった場合 + LinkedList<REPCommand> mergeAgainList = translater.getMergeAgain(); + for(REPCommand againCommand: mergeAgainList){ + myChannel.write(againCommand); + } + } }else{ //他のエディタからの編集コマンド REPCommand[] cmds = translater.transReceiveCmd(command); @@ -65,13 +72,9 @@ private void sendMergedCommand(REPCommand[] cmds) { for(int i = 0; i < cmds.length; i++){ - try { - REPCommand mergeCommand = cmds[i]; - mergeCommand.setEID(REP.MERGE_EID); - myChannel.write(pack(mergeCommand)); - } catch (IOException e) { - e.printStackTrace(); - } + REPCommand mergeCommand = cmds[i]; + mergeCommand.setEID(REP.MERGE_EID); + myChannel.write(mergeCommand); } } @@ -125,17 +128,8 @@ file = string; } - public void send(REPCommand repCmd) { - try { - myChannel.write(pack(repCmd)); - } catch (IOException e) { - e.printStackTrace(); - } - } - - private ByteBuffer pack(REPCommand repCmd) { - // TODO Auto-generated method stub - return null; + public void send(REPCommand command) { + myChannel.write(command); } public void setChannel(REPSocketChannel<REPCommand> channel) {
--- a/rep/REPActionListener.java Thu Aug 28 22:04:48 2008 +0900 +++ b/rep/REPActionListener.java Thu Aug 28 22:53:05 2008 +0900 @@ -4,5 +4,4 @@ public void ActionOccured(REPActionEvent<P> event); - public void undo(); }
--- a/rep/RPanel.java Thu Aug 28 22:04:48 2008 +0900 +++ b/rep/RPanel.java Thu Aug 28 22:53:05 2008 +0900 @@ -3,8 +3,6 @@ import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.nio.channels.SocketChannel; - import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JLabel; @@ -55,8 +53,6 @@ private JComboBox comboSession; private JButton buttonSelect; private REPActionListener<REPCommand> actionListener; - private JButton buttonUndo; - private REPActionListener<REPCommand> undoListener; public RPanel() { button = new JButton("Connect"); @@ -74,7 +70,6 @@ comboEditor = new JComboBox(); comboSession = new JComboBox(); buttonSelect = new JButton("Select"); - buttonUndo = new JButton("Undo"); button.setBounds(160, 5, 100, 20); @@ -96,7 +91,6 @@ 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); @@ -112,11 +106,10 @@ //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){ @@ -134,9 +127,6 @@ */ actionListener.ActionOccured(new REPActionEvent<REPCommand>((EditorPlus<REPCommand>) e_list.get(editor_table.getSelectedRow()), (SessionPlus)s_list.get(session_table.getSelectedRow()))); - }else if(event.getSource() == buttonUndo){ - //System.out.println("Undo!"); - actionListener.undo(); } } @@ -145,9 +135,6 @@ this.listener = (SessionManager) listener; } - public void addUndoListener(REPActionListener<REPCommand> listener3){ - undoListener = listener3; - } public void setComboEditor(int eid, REPSocketChannel<REPCommand> channel) { //comboEditor.addItem("Editor:"+eid); @@ -163,7 +150,6 @@ } public void setTableEditor(int eid, REPSocketChannel<REPCommand> channel) { - //comboEditor.addItem("Editor:"+eid); EditorPlus<REPCommand> ep = new EditorPlus<REPCommand>(eid, channel); e_list.add(ep);
--- a/rep/Session.java Thu Aug 28 22:04:48 2008 +0900 +++ b/rep/Session.java Thu Aug 28 22:53:05 2008 +0900 @@ -1,9 +1,6 @@ package rep; -import java.nio.channels.SocketChannel; import java.util.LinkedList; -import java.util.List; - import rep.channel.REPSocketChannel; public class Session { @@ -11,21 +8,16 @@ private int sessionID; private String sessionName; private LinkedList<Editor> editorList = new LinkedList<Editor>(); - private String masterHost; - private String masterPort; private LinkedList<REPNode> routingTable = new LinkedList<REPNode>(); - private int incrementEID; private boolean isOwner = false; - public Session(int sessionID, String string, REPSocketChannel channel) { + public Session(int sessionID, String string, REPSocketChannel<REPCommand> channel) { masterEditor = new Editor(sessionID, channel); this.sessionID = sessionID; this.sessionName = string; } public Session(Editor editor) { masterEditor = editor; - masterHost = editor.getHost(); - //masterPort = editor.getPort(); this.sessionID = 0; this.sessionName = editor.getName(); } @@ -35,7 +27,7 @@ masterEditor = editor; editorList.add(editor); } - public void addEditor(int editorID, REPSocketChannel channel) { + public void addEditor(int editorID, REPSocketChannel<REPCommand> channel) { editorList.add(new Editor(editorID, channel)); } public LinkedList<Editor> getEditorList() { @@ -78,7 +70,6 @@ } } public Editor getEditor(REPSocketChannel<REPCommand> channel) { - // TODO Auto-generated method stub for(Editor editor : editorList){ if(editor.getChannel() == channel) return editor; }
--- a/rep/SessionManager.java Thu Aug 28 22:04:48 2008 +0900 +++ b/rep/SessionManager.java Thu Aug 28 22:53:05 2008 +0900 @@ -2,28 +2,17 @@ import java.io.IOException; import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.nio.ByteBuffer; -import java.nio.CharBuffer; import java.nio.channels.SelectableChannel; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; -import java.nio.channels.ServerSocketChannel; -import java.nio.channels.SocketChannel; -import java.nio.charset.CharacterCodingException; -import java.nio.charset.Charset; -import java.nio.charset.CharsetEncoder; + import java.util.Iterator; import java.util.LinkedList; import java.util.List; -import java.util.Set; -import java.util.StringTokenizer; import java.util.concurrent.BlockingQueue; import rep.channel.REPServerSocketChannel; import rep.channel.REPSocketChannel; -import rep.channel.SelectionKeySimulator; -import rep.channel.SelectorSimulator; import rep.handler.PacketSet; import rep.handler.REPHandler; import rep.handler.REPHandlerImpl; @@ -324,6 +313,7 @@ //SessionListへ追加し変換テーブルを生成する。 //sessionlist.update(channel, receivedSessionList3); + sessionList.add(new Session(new Editor(channel))); smList.sendExcept(channel, receivedCommand); @@ -349,10 +339,6 @@ smList.sendToSlave(receivedCommand); break; -// case REP.REPCMD_READ: -// //sessionlist.sendCmd(channel, repCmd); -// break; - case REP.SMCMD_CH_MASTER: //maxHost を設定。 if(setMaxHost(channel, receivedCommand.string)){ @@ -374,7 +360,7 @@ Editor editor = session.getEditor(channel); Editor prevEditor = session.getPrevEditor(editor); -// マージ中は前のエディタからのコマンドを受信しない + //マージ中は前のエディタからのコマンドを受信しない if(editor.isMerging()){ //Handlerを切り替える setMergeState(prevEditor.getChannel(), session.getSID()); @@ -422,8 +408,12 @@ } private boolean setMaxHost(REPSocketChannel channel, String maxHost2) { - // TODO Auto-generated method stub - return false; + if(maxHost.compareTo(maxHost2) > 0){ + return false; + }else{ + maxHost = maxHost2; + return true; + } } private void setMyHostName(String localHostName) { @@ -460,7 +450,6 @@ private void openWindow() { Thread th = new Thread( gui ); th.start(); - //System.out.println(sessionmanagerGUI.toString()); gui.addConnectionListener(this); gui.addREPActionListener(this); } @@ -557,12 +546,7 @@ } public void addWaitingCommand(PacketSet set) { - // TODO Auto-generated method stub packetSetList.add(set); } - public void undo() { - // TODO Auto-generated method stub - - } }
--- a/rep/SessionManagerGUI.java Thu Aug 28 22:04:48 2008 +0900 +++ b/rep/SessionManagerGUI.java Thu Aug 28 22:53:05 2008 +0900 @@ -58,4 +58,8 @@ rp.setTableSession(sessionID, string); } + public void update() { + + } + } \ No newline at end of file
--- a/rep/xml/SessionXMLDecoder.java Thu Aug 28 22:04:48 2008 +0900 +++ b/rep/xml/SessionXMLDecoder.java Thu Aug 28 22:53:05 2008 +0900 @@ -97,14 +97,14 @@ String file = elementFile.getFirstChild().getNodeValue(); Editor editor = new Editor(); - editor.setHost(host); editor.setPort(port); editor.setName(file); editor.setEID(Integer.parseInt(eid)); + editor.setHost(host);/* editor.setPort(port)*/; editor.setName(file); editor.setEID(Integer.parseInt(eid)); session = new Session(editor); session.addEditor(editor); sessionlist.addSession(session); }else { Editor editor = new Editor(); - editor.setHost(host); editor.setPort(port); editor.setName(null); editor.setEID(Integer.parseInt(eid)); + editor.setHost(host);/* editor.setPort(port)*/; editor.setName(null); editor.setEID(Integer.parseInt(eid)); if(session != null){ session.addEditor(editor); //sessionlist.addSession(session); @@ -132,7 +132,7 @@ String host = nodelistEditorInfo.item(0).getTextContent(); editor.setHost(host); String port = nodelistEditorInfo.item(1).getTextContent(); - editor.setPort(port); +// editor.setPort(port); if(nodelistEditorInfo.getLength() == 3){ String name = nodelistEditorInfo.item(2).getTextContent(); editor.setName(name);
--- a/rep/xml/SessionXMLEncoder.java Thu Aug 28 22:04:48 2008 +0900 +++ b/rep/xml/SessionXMLEncoder.java Thu Aug 28 22:53:05 2008 +0900 @@ -88,7 +88,7 @@ Element elementPort = doc.createElement("port"); elementEditor.appendChild(elementPort); - elementPort.setTextContent(editor.getPort()); + //elementPort.setTextContent(editor.getPort()); if(editor.getName() != null){ Element elementName = doc.createElement("file");
--- a/test/XMLTest.java Thu Aug 28 22:04:48 2008 +0900 +++ b/test/XMLTest.java Thu Aug 28 22:53:05 2008 +0900 @@ -13,13 +13,13 @@ Editor editor = new Editor(0, null); editor.setEID(1); editor.setHost("firefly.cr.ie.u-ryukyu.ac.jp"); - editor.setPort("56789"); + //editor.setPort("56789"); editor.setName("Test.java"); Editor editor2 = new Editor(1, null); editor2.setEID(2); editor2.setHost("teto.cr.ie.u-ryukyu.ac.jp"); - editor2.setPort("45678"); + //editor2.setPort("45678"); Session session = new Session(editor); session.addEditor(editor);