# HG changeset patch # User kono # Date 1222238949 -32400 # Node ID ad487e63e3c86d1e5f787b3e050d3a677e88fa7a # Parent d6a33e295d471406d098c36d4c89f149762dfc4d *** empty log message *** diff -r d6a33e295d47 -r ad487e63e3c8 rep/REPNode.java --- a/rep/REPNode.java Mon Sep 22 18:21:35 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -package rep; - -public class REPNode { - - public REPNode(Editor editor) { - } - - public REPNode(SessionManagerNode node, int sid) { - } - -} diff -r d6a33e295d47 -r ad487e63e3c8 rep/Session.java --- a/rep/Session.java Mon Sep 22 18:21:35 2008 +0900 +++ b/rep/Session.java Wed Sep 24 15:49:09 2008 +0900 @@ -10,7 +10,6 @@ private int sessionID; private String sessionName; private LinkedList editorList = new LinkedList(); - private LinkedList routingTable = new LinkedList(); private boolean isOwner = false; public Session(int sid, String name, Editor editor) { @@ -52,12 +51,22 @@ editor.setEID(eid); editorList.add(editor); } + + public boolean deleteEditor(REPSocketChannel channel) { + boolean flag = false; + for(Editor editor : editorList){ + if(editor.getChannel() == channel) { + editorList.remove(editor); + flag = true; + } + } + return flag; + } + public void setSID(int sid) { sessionID = sid; } - public void addToRoutingTable(Editor editor) { - routingTable.add(new REPNode(editor)); - } + public boolean hasOwner() { return isOwner; } diff -r d6a33e295d47 -r ad487e63e3c8 rep/SessionManager.java --- a/rep/SessionManager.java Mon Sep 22 18:21:35 2008 +0900 +++ b/rep/SessionManager.java Wed Sep 24 15:49:09 2008 +0900 @@ -113,6 +113,7 @@ return false; } + @SuppressWarnings("unchecked") private void select() throws IOException { SessionManagerEvent e; while((e = waitingQueue.poll())!=null){ @@ -133,10 +134,10 @@ handler.handle(key); } catch (ClosedChannelException x) { key.cancel(); - handler.cancel(); + handler.cancel((REPSocketChannel)key.channel()); } catch (IOException x) { key.cancel(); - handler.cancel(); + handler.cancel((REPSocketChannel)key.channel()); } } } @@ -415,10 +416,10 @@ } private void setNormalState(REPSocketChannel channel, int sid) { - System.out.println("SessionManager.setNormalState() : channel = " + channel); - System.out.println("SessionManager.setNormalState() : selector = " + selector); + //System.out.println("SessionManager.setNormalState() : channel = " + channel); + //System.out.println("SessionManager.setNormalState() : selector = " + selector); SelectionKey key = channel.keyFor(selector); - System.out.println("SessionManager.setNormalState() : key = " + key); + // System.out.println("SessionManager.setNormalState() : key = " + key); key.attach(new REPHandlerImpl(sid, this)); } @@ -604,4 +605,14 @@ updateGUI(); } + public void remove(REPSocketChannel channel) { + for(Session s:sessionList) { + if (s.deleteEditor(channel)) { + return ; + } + } + assert(false); + // can be other session manager? what should I do? + } + } diff -r d6a33e295d47 -r ad487e63e3c8 rep/handler/REPHandler.java --- a/rep/handler/REPHandler.java Mon Sep 22 18:21:35 2008 +0900 +++ b/rep/handler/REPHandler.java Wed Sep 24 15:49:09 2008 +0900 @@ -3,10 +3,11 @@ import java.io.IOException; import rep.REPCommand; import rep.channel.REPSelectionKey; +import rep.channel.REPSocketChannel; public interface REPHandler { void handle(REPSelectionKey key)throws IOException; - void cancel(); + void cancel(REPSocketChannel socketChannel); } diff -r d6a33e295d47 -r ad487e63e3c8 rep/handler/REPHandlerDoWaiting.java --- a/rep/handler/REPHandlerDoWaiting.java Mon Sep 22 18:21:35 2008 +0900 +++ b/rep/handler/REPHandlerDoWaiting.java Wed Sep 24 15:49:09 2008 +0900 @@ -4,19 +4,21 @@ import rep.REPCommand; import rep.SessionManager; import rep.channel.REPSelectionKey; +import rep.channel.REPSocketChannel; public class REPHandlerDoWaiting implements REPHandler { + SessionManager manager; public REPHandlerDoWaiting(SessionManager manager) { + this.manager = manager; } public void handle(REPSelectionKey key) throws IOException { } - - public void cancel() { - // TODO Auto-generated method stub - + + public void cancel(REPSocketChannel socketChannel) { + manager.remove(socketChannel); } } diff -r d6a33e295d47 -r ad487e63e3c8 rep/handler/REPHandlerImpl.java --- a/rep/handler/REPHandlerImpl.java Mon Sep 22 18:21:35 2008 +0900 +++ b/rep/handler/REPHandlerImpl.java Wed Sep 24 15:49:09 2008 +0900 @@ -26,9 +26,9 @@ manager.manage(channel, command); } - public void cancel() { - // TODO Auto-generated method stub - + public void cancel(REPSocketChannel socketChannel) { + manager.remove(socketChannel); } + } diff -r d6a33e295d47 -r ad487e63e3c8 rep/handler/REPHandlerInMerge.java --- a/rep/handler/REPHandlerInMerge.java Mon Sep 22 18:21:35 2008 +0900 +++ b/rep/handler/REPHandlerInMerge.java Wed Sep 24 15:49:09 2008 +0900 @@ -3,7 +3,6 @@ import java.io.IOException; import rep.Editor; import rep.REPCommand; -import rep.REPCommandPacker; import rep.SessionManager; import rep.channel.REPSelectionKey; import rep.channel.REPSocketChannel; @@ -27,6 +26,7 @@ //マージ中のエディタの前のエディタのコマンドをWaitingListに追加する REPSocketChannel channel = (REPSocketChannel) key.channel(); REPCommand command = channel.read(); + System.out.println("REPHandlerImpl.handle() : command = " + command); if(command.sid == sid){ Editor editor = manager.getEditor(channel); manager.addWaitingCommand(new PacketSet(channel, editor, command)); @@ -35,9 +35,7 @@ } } - public void cancel() { - // TODO Auto-generated method stub - + public void cancel(REPSocketChannel socketChannel) { + manager.remove(socketChannel); } - }