# HG changeset patch # User one # Date 1227660683 -32400 # Node ID 2c815dd5f797be45e6633aae9dc3343045a95611 # Parent 795ef563f2a07744bbe01c3a94128aa76c7ba174 add comments. diff -r 795ef563f2a0 -r 2c815dd5f797 rep/ServerMainLoop.java --- a/rep/ServerMainLoop.java Wed Nov 26 09:41:14 2008 +0900 +++ b/rep/ServerMainLoop.java Wed Nov 26 09:51:23 2008 +0900 @@ -15,7 +15,6 @@ import rep.channel.REPSelector; import rep.channel.REPServerSocketChannel; import rep.channel.REPSocketChannel; -import rep.gui.DoGUIUpdate; import rep.gui.SessionManagerEvent; import rep.gui.SessionManagerGUI; import rep.handler.FirstConnector; @@ -27,6 +26,7 @@ * maintain multiple connections * gui interface is provided. * Protocols are handled by our manager. + * We believe this is an protocol independent server. */ public class ServerMainLoop { @@ -42,7 +42,6 @@ protected int parent_port; protected static final int DEFAULT_PORT = 8766; private SessionManagerEvent execAfterConnect = null; - private boolean listLocalEditorOnly = false; public void setReceivePort(int port) { @@ -184,31 +183,6 @@ channel.register(selector, SelectionKey.OP_READ, handler); } - /** - * Notify status change to our GUI - */ - protected void updateGUI() { - //リストのコピーをGUIに渡す - LinkedList sList = new LinkedList(manager.sessionList.values()); - LinkedList eList; - if (listLocalEditorOnly ) { - // Do not list an editor or session outside of this session manager to - // avoid confusion. Actually we can joinSession to an editor outside of - // this manager, but is not secure to do this. - eList = new LinkedList(); - for(REPNode e:manager.editorList.values()) { - if (manager.getSMID(e.eid)==manager.smList.sessionManagerID()) { - eList.add(e); - } - } - } else { - eList = new LinkedList(manager.editorList.values()); - } - //GUIに反映 - Runnable doRun = new DoGUIUpdate(sList, eList, gui); - gui.invokeLater(doRun); - } - public void setMyHostName(String localHostName) { myHost = localHostName + receive_port; setHostToEditor(myHost); diff -r 795ef563f2a0 -r 2c815dd5f797 rep/SessionManager.java --- a/rep/SessionManager.java Wed Nov 26 09:41:14 2008 +0900 +++ b/rep/SessionManager.java Wed Nov 26 09:51:23 2008 +0900 @@ -4,6 +4,7 @@ import java.io.IOException; import java.net.InetSocketAddress; import java.nio.channels.ClosedChannelException; +import java.util.LinkedList; import org.xml.sax.SAXException; @@ -12,6 +13,7 @@ import rep.channel.REPLogger; import rep.channel.REPSocketChannel; import rep.gui.CloseButtonEvent; +import rep.gui.DoGUIUpdate; import rep.gui.SelectButtonEvent; import rep.gui.SessionManagerEvent; import rep.gui.SessionManagerEventListener; @@ -63,7 +65,9 @@ private RoutingTable routingTable = new RoutingTable(this); // sync option public boolean sync = true; - + // list olny local editor in GUI + protected boolean listLocalEditorOnly = false; + static public REPLogger logger = REPLogger.singleton(); public static void main(String[] args) throws InterruptedException, IOException { @@ -104,11 +108,12 @@ * Host 名のSession Manager に SM_JOIN する。自分は、Session を持っていては * ならない。複数のSession Managerにjoinすることは出来ない。(NATを実装するまでは)。 * @param host + * @return error massage, return null when no errors. */ - public void connectSessionManager(String host, int port) { - if (sm_join_channel!=null) return; - if (!sessionList.isEmpty()) return; - if (!smList.isMaster()) return; + public String connectSessionManager(String host, int port) { + if (sm_join_channel!=null) return "No Channel of sessionManager, Network Error."; + if (!sessionList.isEmpty()) return "Cannot connect with sessions."; + if (!smList.isMaster()) return "Already connected to the master."; /* * IPv6 対応では、複数のアドレスを取って、それのすべてに接続を試す必要が * ある。 @@ -123,6 +128,7 @@ sm_join(sm); }catch (IOException e) { } + return null; } public void connectSessionManager(String host) { @@ -264,7 +270,7 @@ Session session = ((CloseButtonEvent) event).getSession(); session.closeSession(); sessionList.remove(session); - updateGUI(); + manager.updateGUI(this); } /* @@ -293,7 +299,7 @@ s.deleteForwarder(editor); editorList.remove(editor); } - updateGUI(); + manager.updateGUI(this); } private void removeSession(Session s0) { @@ -323,7 +329,7 @@ } else { smList.sendToMaster(command); } - updateGUI(); + manager.updateGUI(this); } break; @@ -339,7 +345,7 @@ } case SMCMD_JOIN_ACK: registEditor(forwarder,command); - updateGUI(); + manager.updateGUI(this); break; case SMCMD_PUT: @@ -361,7 +367,7 @@ smList.sendToMaster(command); // registEditor will be done by SMCMD_PUT_ACK } - updateGUI(); + manager.updateGUI(this); } break; @@ -442,7 +448,7 @@ command.setString(mergeUpdate(command)); // 下に知らせる smList.sendToSlaves(command); - updateGUI(); + manager.updateGUI(this); break; default: return false; @@ -614,4 +620,29 @@ } + /** + * Notify status change to our GUI + */ + protected void updateGUI(ServerMainLoop serverMainLoop) { + //リストのコピーをGUIに渡す + LinkedList sList = new LinkedList(sessionList.values()); + LinkedList eList; + if (listLocalEditorOnly ) { + // Do not list an editor or session outside of this session manager to + // avoid confusion. Actually we can joinSession to an editor outside of + // this manager, but is not secure to do this. + eList = new LinkedList(); + for(REPNode e:editorList.values()) { + if (getSMID(e.eid)==smList.sessionManagerID()) { + eList.add(e); + } + } + } else { + eList = new LinkedList(editorList.values()); + } + //GUIに反映 + Runnable doRun = new DoGUIUpdate(sList, eList, serverMainLoop.gui); + serverMainLoop.gui.invokeLater(doRun); + } + }