comparison 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
comparison
equal deleted inserted replaced
355:98607350f7d1 356:b18c24dcc5d2
1 package rep; 1 package rep;
2 2
3 import java.util.LinkedList; 3 import java.util.LinkedList;
4 4
5 import rep.channel.REPSocketChannel; 5 public class EditorList extends LinkedList<Editor> {
6 6
7 public class EditorList { 7 /**
8 *
9 */
10 private static final long serialVersionUID = 1L;
11 private int eid_root=0;
12 private LinkedList<Editor> waiting= new LinkedList<Editor>();
8 13
9 private int numberOfEditor;
10 private LinkedList<Editor> editorList = new LinkedList<Editor>();
11 14
12 public void sendJoinAck(REPCommand repCmd) { 15 public void addWaitingEditor(Editor fw) {
13 Forwarder editor = null; 16 waiting.add(fw);
14 for(Forwarder editor2 : editorList){
15 error(String.valueOf(editor2.getEID()), String.valueOf(repCmd.eid));
16 if(editor2.getEID() == repCmd.eid){
17 editor = editor2;
18 break;
19 }
20 }
21 error(editor);
22 editor.getChannel().write(repCmd);
23 } 17 }
24 18
25 19
26 public void sendJoinAck(REPSocketChannel<REPCommand> channel, REPCommand repCmd) { 20 public void assignSessionManagerIDtoWaitingSM(int eid) {
27 REPCommand command = repCmd; 21 // 待っていたEditorにEditor IDを登録し,Session Manager List
28 command.setCMD(REP.SMCMD_JOIN_ACK); 22 // に登録する。この後、EditorのPUT/JOINに従って、ACKを送り、EID
29 23 // を確定する。
30 channel.write(command); 24 Editor waiter;
31 } 25 if ((waiter=waiting.poll())!=null) {
32 26 waiter.setEID(eid);
33 public int addEditor(SessionManager manager,REPSocketChannel<REPCommand> channel, REPCommand repCmd) { 27 add(waiter);
34 numberOfEditor++; 28 return;
35 editorList.add(new Editor(manager,numberOfEditor, channel));
36 return numberOfEditor;
37 }
38
39 public void addEditor(SessionManager manager,REPSocketChannel<REPCommand> channel) {
40 editorList.add(new Editor(manager,0, channel));
41 }
42
43 public void setEID(REPCommand repCmd) {
44 for(Forwarder editor : editorList){
45 if(editor.getEID() == 0){
46 editor.setEID(repCmd.eid);
47 break;
48 }
49 } 29 }
50 } 30 assert false;
51
52 private void error(Object obj) {
53 if(obj == null){
54 SessionManager.logger.writeLog("null!");
55 }
56 }
57 private void error(String str1, String str2){
58 if(str1.equals(str2)){
59 return;
60 }else{
61 SessionManager.logger.writeLog("Not equals! str1:str2");
62 }
63 } 31 }
64 32
65 33
66 public void sendPutAck(REPSocketChannel<REPCommand> channel, REPCommand repCmd) { 34 public int newEid() {
67 channel.write(repCmd); 35 return ++eid_root;
68 }
69
70 public void send(REPSocketChannel<REPCommand> channel, REPCommand command){
71 channel.write(command);
72 } 36 }
73 37
74 38
75 public void setHost(String myHost) { 39 public boolean waiting(Editor editor) {
76 for(Editor editor : editorList) { 40 return waiting.contains(editor);
77 editor.setHost(myHost);
78 }
79 } 41 }
80 42
81 43
82 public Forwarder getEditor(String hostport) {
83 for(Editor editor : editorList){
84 String[] splited = hostport.split(":");
85 SessionManager.logger.writeLog(
86 splited[0] + "," + editor.getHost());
87 if(splited[0].equals(editor.getHost())){
88 return editor;
89 }
90 }
91 return null;
92 }
93
94
95 public int addEditor(Editor editor) {
96 numberOfEditor++;
97 editorList.add(editor);
98 return numberOfEditor;
99 }
100
101
102 public Forwarder getEditor(REPSocketChannel<REPCommand> channel) {
103 Forwarder editor1 = null;
104 for(Forwarder editor: editorList){
105 if(channel == editor.getChannel()){
106 editor1 = editor;
107 }
108 }
109 return editor1;
110 }
111
112 } 44 }