# HG changeset patch # User kono # Date 1224324100 -32400 # Node ID b18c24dcc5d21f230c7c706ce5869944a5ac5443 # Parent 98607350f7d1953ebeb0058d64d8d9e26c3e2f22 Before chaning put/join scheme for ditributed select. diff -r 98607350f7d1 -r b18c24dcc5d2 rep/EditorList.java --- a/rep/EditorList.java Fri Oct 17 22:11:34 2008 +0900 +++ b/rep/EditorList.java Sat Oct 18 19:01:40 2008 +0900 @@ -2,111 +2,43 @@ import java.util.LinkedList; -import rep.channel.REPSocketChannel; - -public class EditorList { - - private int numberOfEditor; - private LinkedList editorList = new LinkedList(); +public class EditorList extends LinkedList { - public void sendJoinAck(REPCommand repCmd) { - Forwarder editor = null; - for(Forwarder editor2 : editorList){ - error(String.valueOf(editor2.getEID()), String.valueOf(repCmd.eid)); - if(editor2.getEID() == repCmd.eid){ - editor = editor2; - break; - } - } - error(editor); - editor.getChannel().write(repCmd); + /** + * + */ + private static final long serialVersionUID = 1L; + private int eid_root=0; + private LinkedList waiting= new LinkedList(); + + + public void addWaitingEditor(Editor fw) { + waiting.add(fw); } - public void sendJoinAck(REPSocketChannel channel, REPCommand repCmd) { - REPCommand command = repCmd; - command.setCMD(REP.SMCMD_JOIN_ACK); - - channel.write(command); - } - - public int addEditor(SessionManager manager,REPSocketChannel channel, REPCommand repCmd) { - numberOfEditor++; - editorList.add(new Editor(manager,numberOfEditor, channel)); - return numberOfEditor; - } - - public void addEditor(SessionManager manager,REPSocketChannel channel) { - editorList.add(new Editor(manager,0, channel)); - } - - public void setEID(REPCommand repCmd) { - for(Forwarder editor : editorList){ - if(editor.getEID() == 0){ - editor.setEID(repCmd.eid); - break; - } + public void assignSessionManagerIDtoWaitingSM(int eid) { + // 待っていたEditorにEditor IDを登録し,Session Manager List + // に登録する。この後、EditorのPUT/JOINに従って、ACKを送り、EID + // を確定する。 + Editor waiter; + if ((waiter=waiting.poll())!=null) { + waiter.setEID(eid); + add(waiter); + return; } - } - - private void error(Object obj) { - if(obj == null){ - SessionManager.logger.writeLog("null!"); - } - } - private void error(String str1, String str2){ - if(str1.equals(str2)){ - return; - }else{ - SessionManager.logger.writeLog("Not equals! str1:str2"); - } + assert false; } - public void sendPutAck(REPSocketChannel channel, REPCommand repCmd) { - channel.write(repCmd); - } - - public void send(REPSocketChannel channel, REPCommand command){ - channel.write(command); - } - - - public void setHost(String myHost) { - for(Editor editor : editorList) { - editor.setHost(myHost); - } + public int newEid() { + return ++eid_root; } - public Forwarder getEditor(String hostport) { - for(Editor editor : editorList){ - String[] splited = hostport.split(":"); - SessionManager.logger.writeLog( - splited[0] + "," + editor.getHost()); - if(splited[0].equals(editor.getHost())){ - return editor; - } - } - return null; + public boolean waiting(Editor editor) { + return waiting.contains(editor); } - public int addEditor(Editor editor) { - numberOfEditor++; - editorList.add(editor); - return numberOfEditor; - } - - - public Forwarder getEditor(REPSocketChannel channel) { - Forwarder editor1 = null; - for(Forwarder editor: editorList){ - if(channel == editor.getChannel()){ - editor1 = editor; - } - } - return editor1; - } - } diff -r 98607350f7d1 -r b18c24dcc5d2 rep/EditorPlus.java --- a/rep/EditorPlus.java Fri Oct 17 22:11:34 2008 +0900 +++ b/rep/EditorPlus.java Sat Oct 18 19:01:40 2008 +0900 @@ -4,7 +4,7 @@ public class EditorPlus { - public int eid; // unique in a session, eid==0 master + public int eid; // globally unique public int sid=-1; // globally unique public String host; public String file; diff -r 98607350f7d1 -r b18c24dcc5d2 rep/Session.java --- a/rep/Session.java Fri Oct 17 22:11:34 2008 +0900 +++ b/rep/Session.java Sat Oct 18 19:01:40 2008 +0900 @@ -10,7 +10,6 @@ private String sessionName; private LinkedList editorList = new LinkedList(); private boolean isOwner = false; - private int eidSeed = 0; private Forwarder firstForwarder; public Session(int sid, String name, Forwarder editor) { @@ -65,17 +64,6 @@ return sessionName; } - public int newEid() { - int eid=0; - boolean flag = true; - while(flag) { - eid=eidSeed++; - for(EditorPlus e:editorList) { - if((flag = (eid==e.eid))) break; - } - } - return eid; - } public boolean deleteEditor(REPSocketChannel channel) { boolean flag = false; diff -r 98607350f7d1 -r b18c24dcc5d2 rep/SessionManager.java --- a/rep/SessionManager.java Fri Oct 17 22:11:34 2008 +0900 +++ b/rep/SessionManager.java Sat Oct 18 19:01:40 2008 +0900 @@ -50,7 +50,7 @@ private SessionManagerGUI gui; private REPSelector selector; SessionManagerList smList; - List editorList; + EditorList editorList; // editorList は、sessionList に入っているeditorとは別なeditorのlistらしい。 // private String maxHost; private List waitingCommandInMerge; @@ -111,7 +111,7 @@ sessionList = new LinkedList(); smList = new SessionManagerList(); - editorList = new LinkedList(); + editorList = new EditorList(); waitingCommandInMerge = new LinkedList(); @@ -361,11 +361,10 @@ return; } if (editor.hasSession()) return; - //REPSocketChannel channel = editor.getChannel(); + if (editorList.waiting(editor)) return; - // System.out.println("SessionManager.session.hasOnwer="+session.hasOwner()); if(session.hasOwner()){ - editor.setEID(session.newEid()); + editor.setEID(editorList.newEid()); editor.setSID(sid); session.addForwarder(editor); REPCommand sendCommand = new REPCommand(); diff -r 98607350f7d1 -r b18c24dcc5d2 rep/SessionManagerList.java --- a/rep/SessionManagerList.java Fri Oct 17 22:11:34 2008 +0900 +++ b/rep/SessionManagerList.java Sat Oct 18 19:01:40 2008 +0900 @@ -1,18 +1,18 @@ package rep; import java.util.LinkedList; -import rep.channel.REPSocketChannel; + +public class SessionManagerList extends LinkedList{ -public class SessionManagerList { - - private LinkedList list = new LinkedList(); - private int mySMID; + /** + * + */ + private static final long serialVersionUID = 1L; + private int mySMID=0; + private int smid_root=0; private Forwarder parent=null; private LinkedList waiting= new LinkedList(); - public void add(Forwarder channel) { - list.add(channel); - } public void setMaster(Forwarder f) { this.parent = f; @@ -23,7 +23,7 @@ } public void sendToSlaves(REPCommand repCmd) { - for(Forwarder channel : list){ + for(Forwarder channel : this){ channel.send(repCmd); } } @@ -33,19 +33,13 @@ } public int addNewSessionManager(Forwarder fw,REPCommand receivedCommand) { - list.add(fw); - int sid = list.size(); + add(fw); + int sid = ++smid_root; fw.setSID(sid); fw.setName(receivedCommand.string); return sid; } - public boolean isSessionManagerChannel(REPSocketChannel channel) { - for(Forwarder f : list){ - if (f.channel==channel) return true; - } - return false; - } public void setSessionManagerID(int sid) { mySMID = sid; @@ -67,7 +61,7 @@ Forwarder waiter; if ((waiter=waiting.poll())!=null) { waiter.setSID(sid); - list.add(waiter); + add(waiter); return; } assert false;