Mercurial > hg > RemoteEditor > REPSessionManager
changeset 167:3dc194f5e28f
*** empty log message ***
author | pin |
---|---|
date | Thu, 28 Aug 2008 18:44:05 +0900 |
parents | be2c1a1e9b8d |
children | 4ed6393ec68e |
files | rep/Session.java rep/SessionManager.java rep/handler/REPHandlerInMerge.java |
diffstat | 3 files changed, 35 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/rep/Session.java Thu Aug 28 18:16:23 2008 +0900 +++ b/rep/Session.java Thu Aug 28 18:44:05 2008 +0900 @@ -99,4 +99,10 @@ Editor nextEditor = editorList.get(neid); return nextEditor; } + public Editor getPrevEditor(Editor editor) { + int eid = editor.getEID(); + int peid = (eid + editorList.size() - 1)%editorList.size(); + Editor prevEditor = editorList.get(peid); + return prevEditor; + } }
--- a/rep/SessionManager.java Thu Aug 28 18:16:23 2008 +0900 +++ b/rep/SessionManager.java Thu Aug 28 18:44:05 2008 +0900 @@ -348,35 +348,32 @@ //マージの処理と次のエディタへコマンドを送信する処理 session.translate(channel, receivedCommand); - Editor editor = getEditor(channel); + //マージ中は前のエディタからのコマンドを受信しない + Editor editor = session.getEditor(channel); + Editor prevEditor = session.getPrevEditor(editor); + + if(editor.isFinished){ + set + } + if(editor.isMerging()){ //Handlerを切り替える - setMergeState(channel, selector); + setMergeState(prevEditor.getChannel(), session.getSID()); } } break; } } - private void setMergeState(REPSocketChannel<REPCommand> channel, Selector selector2) { - SelectionKey key = channel.keyFor(selector2); - key.attach(new REPHandlerInMerge(this)); + private void setMergeState(REPSocketChannel<REPCommand> channel, int sid) { + SelectionKey key = channel.keyFor(selector); + key.attach(new REPHandlerInMerge(sid, this)); } private Editor getEditor(String hostport) { return null; } - private Editor getEditor(REPSocketChannel<REPCommand> channel) { - // TODO Auto-generated method stub - for(Editor editor : editorList){ - if(editor.getChannel() == channel){ - return editor; - } - } - return null; - } - private Session getSession(int sid) { for(Session session : sessionList){ if(session.getSID() == sid) return session;
--- a/rep/handler/REPHandlerInMerge.java Thu Aug 28 18:16:23 2008 +0900 +++ b/rep/handler/REPHandlerInMerge.java Thu Aug 28 18:44:05 2008 +0900 @@ -11,22 +11,32 @@ public class REPHandlerInMerge implements REPHandler { private SessionManager manager; - //List<PacketSet> packetList = new LinkedList<PacketSet>(); + private int sid; public REPHandlerInMerge(SessionManager manager) { this.manager = manager; } - public void handle(SelectionKeySimulator key) throws IOException { - REPSocketChannel<REPCommand> channel = (REPSocketChannel<REPCommand>) key.channel(); - REPCommand packet = channel.read(); - manager.addWaitingCommand(new PacketSet(channel, packet)); - REPCommand command = packet; - manager.manage(channel, command); + public REPHandlerInMerge(int sid, SessionManager manager2) { + this.manager = manager2; + this.sid = sid; } public void handle(SelectionKey key) { + REPSocketChannel<REPCommand> channel = (REPSocketChannel<REPCommand>) key.channel(); + REPCommand command = null; + try { + command = channel.read(); + } catch (IOException e) { + e.printStackTrace(); + } + + if(command.sid == sid){ + manager.addWaitingCommand(new PacketSet(channel, command)); + }else{ + manager.manage(channel, command); + } } }