Mercurial > hg > RemoteEditor > REPSessionManager
diff rep/EditorList.java @ 356:b18c24dcc5d2
Before chaning put/join scheme for ditributed select.
author | kono |
---|---|
date | Sat, 18 Oct 2008 19:01:40 +0900 |
parents | 5ba5b7a9761b |
children | 034acadc0cdc |
line wrap: on
line diff
--- 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<Editor> editorList = new LinkedList<Editor>(); +public class EditorList extends LinkedList<Editor> { - 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<Editor> waiting= new LinkedList<Editor>(); + + + public void addWaitingEditor(Editor fw) { + waiting.add(fw); } - public void sendJoinAck(REPSocketChannel<REPCommand> channel, REPCommand repCmd) { - REPCommand command = repCmd; - command.setCMD(REP.SMCMD_JOIN_ACK); - - channel.write(command); - } - - public int addEditor(SessionManager manager,REPSocketChannel<REPCommand> channel, REPCommand repCmd) { - numberOfEditor++; - editorList.add(new Editor(manager,numberOfEditor, channel)); - return numberOfEditor; - } - - public void addEditor(SessionManager manager,REPSocketChannel<REPCommand> 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<REPCommand> channel, REPCommand repCmd) { - channel.write(repCmd); - } - - public void send(REPSocketChannel<REPCommand> 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<REPCommand> channel) { - Forwarder editor1 = null; - for(Forwarder editor: editorList){ - if(channel == editor.getChannel()){ - editor1 = editor; - } - } - return editor1; - } - }