# HG changeset patch # User kono # Date 1222523713 -32400 # Node ID c3969dd625b2e6ad1524795bd3cde3cb1e2856fd # Parent a549bd4dadb8cc1f1fa549ca19fb1be72805faac GUIless test routine. diff -r a549bd4dadb8 -r c3969dd625b2 rep/Editor.java --- a/rep/Editor.java Sat Sep 27 15:59:11 2008 +0900 +++ b/rep/Editor.java Sat Sep 27 22:55:13 2008 +0900 @@ -9,7 +9,8 @@ import rep.translater.TranslaterImp1; public class Editor { - private int eid; + private int eid; // unique id in a session + private int sid = -1 ; // globally unique session id private REPSocketChannel myChannel; private String host; private String file; @@ -160,5 +161,11 @@ public boolean isMerging() { return translater.isMerging(); } + public boolean hasSession() { + return sid != -1; + } + public void setSID(int sessionID) { + sid = sessionID; + } } diff -r a549bd4dadb8 -r c3969dd625b2 rep/Session.java --- a/rep/Session.java Sat Sep 27 15:59:11 2008 +0900 +++ b/rep/Session.java Sat Sep 27 22:55:13 2008 +0900 @@ -49,6 +49,7 @@ public void addEditor(Editor editor) { int eid = editorList.size(); editor.setEID(eid); + editor.setSID(sessionID); editorList.add(editor); } diff -r a549bd4dadb8 -r c3969dd625b2 rep/SessionManager.java --- a/rep/SessionManager.java Sat Sep 27 15:59:11 2008 +0900 +++ b/rep/SessionManager.java Sat Sep 27 22:55:13 2008 +0900 @@ -50,14 +50,11 @@ private List editorList; private String maxHost; private List waitingCommandInMerge; - private BlockingQueue waitingQueue; + private BlockingQueue waitingQueue = new LinkedBlockingQueue();; private static int temp_port; private static int send_port; static final int DEFAULT_PORT = 8766; - public SessionManager(int port) { - - } public void openSelector() throws IOException{ selector = REPSelector.create(); @@ -84,7 +81,6 @@ smList = new SessionManagerList(); editorList = new LinkedList(); waitingCommandInMerge = new LinkedList(); - waitingQueue = new LinkedBlockingQueue(); //デフォルトのSessionを作っておく(テスト用に?) //if(sessionList.size() > 0) System.out.println("Error : SessionManager.init():"); @@ -95,6 +91,10 @@ public void mainLoop() throws IOException { while(true){ + SessionManagerEvent e; + while((e = waitingQueue.poll())!=null){ + e.exec(); + } if(checkSend()){ if(selector.selectNow() > 0){ select(); @@ -122,10 +122,6 @@ @SuppressWarnings("unchecked") private void select() throws IOException { - SessionManagerEvent e; - while((e = waitingQueue.poll())!=null){ - e.exec(); - } Set> keys = selector.selectedKeys1(); for(REPSelectionKey key : keys){ @@ -406,27 +402,16 @@ } private void updateGUI() { - if(gui == null){ - //System.out.println("SessionManager.guiUpdate() : gui = " + gui); - return; - } //リストのコピーをGUIに渡す LinkedList sList = new LinkedList(sessionList); LinkedList eList = new LinkedList(editorList); -// for(Editor editor : eList){ -// System.out.println("SessionManager.guiUpdate() : channel = " + editor.getChannel()); -// } -// //GUIに反映 Runnable doRun = new DoGUIUpdate(sList, eList, gui); gui.invokeLater(doRun); } private void setNormalState(REPSocketChannel channel, int sid) { - //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); key.attach(new REPHandlerImpl(sid, this)); } @@ -494,7 +479,7 @@ } temp_port = port; send_port = port_s; - SessionManager sm = new SessionManager(port); + SessionManager sm = new SessionManager(); sm.init(port,new SessionManagerGUIimpl(sm)); @@ -595,6 +580,13 @@ } catch (InterruptedException e) {} selector.wakeup(); } + + public void syncExec(SessionManagerEvent event) { + try { + waitingQueue.put(event); + } catch (InterruptedException e) { + } + } public void closeSession(SessionManagerEvent event) { Session session = ((CloseButtonEvent) event).getSession(); diff -r a549bd4dadb8 -r c3969dd625b2 rep/channel/NetworkSimulator.java --- a/rep/channel/NetworkSimulator.java Sat Sep 27 15:59:11 2008 +0900 +++ b/rep/channel/NetworkSimulator.java Sat Sep 27 22:55:13 2008 +0900 @@ -45,6 +45,7 @@ synchronized public boolean connect(SocketAddress ip, ChannelSimulator

CHclient) { logger.writeLog("connecting..", 1); for (ServerData

sd0: serverList){ + // ANY address (0.0.0.0/0.0.0.0) should be considered. if (!sd0.IP.equals(ip)) continue; ChannelSimulator

CHserver = new ChannelSimulator

(); diff -r a549bd4dadb8 -r c3969dd625b2 test/sematest/TestSessionManager.java --- a/test/sematest/TestSessionManager.java Sat Sep 27 15:59:11 2008 +0900 +++ b/test/sematest/TestSessionManager.java Sat Sep 27 22:55:13 2008 +0900 @@ -6,6 +6,8 @@ import rep.REP; import rep.REPCommand; import rep.SessionManager; +import rep.SessionManagerEvent; +import rep.SessionManagerGUI; import rep.channel.REPLogger; import rep.channel.REPServerSocketChannel; @@ -25,7 +27,7 @@ while(!isStart){ try { - Thread.sleep(50); + Thread.sleep(5); } catch (InterruptedException e) { e.printStackTrace(); } @@ -74,13 +76,14 @@ port = Integer.parseInt(strs[0]); } - SessionManager sm = new SessionManager(port); - sm.openSelector(); - sm.init(port,new testGUI(sm)); + SessionManager sm = new SessionManager(); + SessionManagerGUI gui = new testGUI(sm); logger.writeLog("TestSessionManager.startSessionManager() : start SessionManager"); - isStart = true; - sm.mainLoop(); - + sm.syncExec(new SessionManagerEvent() { + // executed before first select(); + public void exec() { isStart = true; } + }); + sm.init(port,gui); } catch (InterruptedException e) { e.printStackTrace(); } catch (IOException e) { diff -r a549bd4dadb8 -r c3969dd625b2 test/sematest/Tester.java --- a/test/sematest/Tester.java Sat Sep 27 15:59:11 2008 +0900 +++ b/test/sematest/Tester.java Sat Sep 27 22:55:13 2008 +0900 @@ -22,7 +22,7 @@ public Tester(String name, String _host,int _port){ super(name); - REPServerSocketChannel.isSimulation = false; + // REPServerSocketChannel.isSimulation = false; semaIP = new InetSocketAddress(_host, _port); ns = REPLogger.singleton(); ns.setLogLevel(5); diff -r a549bd4dadb8 -r c3969dd625b2 test/sematest/testGUI.java --- a/test/sematest/testGUI.java Sat Sep 27 15:59:11 2008 +0900 +++ b/test/sematest/testGUI.java Sat Sep 27 22:55:13 2008 +0900 @@ -3,7 +3,9 @@ import java.util.LinkedList; import rep.Editor; +import rep.SelectButtonEvent; import rep.Session; +import rep.SessionManagerEvent; import rep.SessionManagerEventListener; import rep.SessionManagerGUI; @@ -18,6 +20,7 @@ public LinkedList slist; public LinkedList elist; SessionManagerEventListener manager; + int count = 0; public testGUI(SessionManagerEventListener manager) { this.manager = manager; @@ -30,6 +33,17 @@ public void update(LinkedList slist, LinkedList elist) { this.slist = slist; this.elist = elist; + // fair and determistic select session for an empty editor + if (slist.size()==0) return; + Session s = slist.get(count++ % slist.size()); + for(Editor e :elist) { + if (!e.hasSession()) { + SessionManagerEvent event = new SelectButtonEvent(e, s, manager); + System.out.println("Select session "+s.getSID()+" and editor "+e.getEID()); + manager.buttonPressed(event); + s = slist.get(count++ % slist.size()); + } + } } }