annotate rep/handler/Editor.java @ 398:7de83b6a34e7

not yet fixed....
author one
date Sun, 23 Nov 2008 18:38:52 +0900
parents 149c9a53fc37
children 19705f4b8015
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
1 package rep.handler;
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
2
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
3 import java.io.IOException;
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
4 import java.util.LinkedList;
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
5 import java.util.List;
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
6
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
7 import rep.PacketSet;
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
8 import rep.REP;
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
9 import rep.REPCommand;
384
bcdf5476b8e4 restructured-version
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 383
diff changeset
10 import rep.ServerMainLoop;
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
11 import rep.SessionManager;
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
12 import rep.channel.REPSelectionKey;
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
13 import rep.channel.REPSocketChannel;
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
14 import rep.optimizers.*;
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
15
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
16 public class Editor extends Forwarder {
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
17
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
18 private Translator translator;
387
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
19 // REPCommands we are going to send to the next editor
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
20 private List<REPCommand> sentList = new LinkedList<REPCommand>();
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
21 private REPCommand quit2=null;
387
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
22 private boolean merging;
395
a2efdec5cbfc insert_ack/delete_ack protocol all written.
one
parents: 394
diff changeset
23 private REPCommand preMergeCommand;
391
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 387
diff changeset
24 public static boolean noMergeMode=false;
385
1fca50ce3508 first-working-version
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 384
diff changeset
25 static final boolean doOptimize = true;
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
26
385
1fca50ce3508 first-working-version
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 384
diff changeset
27 public Editor(SessionManager manager,int editorNo){
387
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
28 // no translator case
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
29 super(manager, null);
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
30 }
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
31
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
32 public Editor(int editorNo, SessionManager manager,REPSocketChannel<REPCommand> channel){
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
33 super(editorNo,manager,channel);
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
34 eid = editorNo;
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
35 REPCommandOptimizer optimizer;
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
36 if (doOptimize) optimizer = new DeleteInsertOptimizer(); //タカノがつくったおぷてぃまいざ
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
37 else optimizer = new NullOptimizer(); //なにもしないけどOptimizer.
383
6d48db302b07 r20081022
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 382
diff changeset
38 translator = new Translator(eid,optimizer);
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
39 }
387
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
40
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
41
397
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
42 public void translate(REPCommand command){
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
43 switch(command.cmd) {
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
44 case REPCMD_INSERT_ACK:
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
45 case REPCMD_DELETE_ACK:
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
46 if (command.eid==eid) {
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
47 // Second Phase が終わって同期が終了。
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
48 return;
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
49 }
398
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
50 if (waitingRequired(command)) return;
397
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
51 checkReturnedCommand(command);
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
52 return;
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
53 }
391
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 387
diff changeset
54 if (command.eid == eid){
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
55 //エディタからの新たな編集コマンド
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
56 if (next==this) return; // singleton case
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
57 translator.transSendCmd(command);
397
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
58 sendEditorCommand(command);
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
59 return;
391
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 387
diff changeset
60 } else if (command.eid == REP.MERGE_EID.id){
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
61 //マージコマンドが返ってきた
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
62 if(translator.checkMergeConflict(command)){
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
63 //マージ中にエディタからの割り込みがあった場合
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
64 translator.getMergeAgain(this);
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
65 }
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
66 checkEndMerge();
391
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 387
diff changeset
67 } else if (command.eid == next.getEID()){
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
68 // 次のEditorで一周するコマンドが来た
397
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
69 // この方法、あんまり良くない...
391
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 387
diff changeset
70 if (next==this) return; // singleton case
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
71 // これは、distributed case では、うまくいかないので、送り先のforwarder で処理する。
397
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
72 if (next.isDirect()) {
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
73 REPCommand keep;
398
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
74 if (waitingRequired(command)) return;
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
75 keep = new REPCommand(command);
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
76 sentList.add(keep);
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
77 ServerMainLoop.logger.writeLog("Editor eid:"+eid+" sentList = "+sentList);
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
78 ((Editor) next).checkReturnedCommand(command);
397
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
79 } else
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
80 next.send(command);
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
81 } else {
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
82 //他のエディタからの編集コマンド
398
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
83 if (waitingRequired(command)) return;
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
84 translator.transReceiveCmd(next,command);
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
85 if(command.cmd==REP.REPCMD_DELETE) {
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
86 // delete のundo用の文字列は、外に出す意味はない
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
87 command.string=null;
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
88 }
398
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
89 sendEditorCommand(command);
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
90 }
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
91 return;
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
92 }
398
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
93
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
94 private boolean waitingRequired(REPCommand command) {
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
95 if (manager.hasWaitingCommand(channel)) {
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
96 // We cannot do this operation before watingCommandQueue.
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
97 manager.addWaitingCommand(new PacketSet(channel, this, command));
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
98 return true;
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
99 } else if (isMerging()) {
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
100 manager.addWaitingCommand(new PacketSet(getChannel(), this, new REPCommand(command)));
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
101 return true;
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
102 }
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
103 ServerMainLoop.logger.writeLog("Editor eid:"+eid+" no waiting");
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
104 return false;
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
105 }
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
106
397
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
107 private void sendEditorCommand(REPCommand command) {
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
108 REPCommand keep = new REPCommand(command);
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
109 sentList.add(keep);
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
110 ServerMainLoop.logger.writeLog("Editor eid:"+eid+" sentList = "+sentList);
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
111 assert(sentList.size()<limit);
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
112 next.send(command);
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
113 }
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
114
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
115 boolean merge(REPCommand command) {
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
116 //マージして送信
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
117 return translator.catchOwnCommand(this);
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
118 }
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
119
391
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 387
diff changeset
120 /**
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 387
diff changeset
121 * 一周して来たcommandの処理。
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 387
diff changeset
122 * @param command
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 387
diff changeset
123 */
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
124 void checkReturnedCommand(REPCommand command) {
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
125 REPCommand prev = sentList.remove(0);
398
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
126 ServerMainLoop.logger.writeLog("Editor eid="+eid+" remove sentList:"+(prev==null?"null":prev));
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
127 if (prev==null || prev.seq != command.seq || prev.eid!=command.eid) {
398
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
128 String err = "Editor eid="+eid+" checkReturnedCommand() : command = " + command + " prev="+
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
129 (prev==null?"null":prev)+" sentList=";
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
130 err += sentList;
384
bcdf5476b8e4 restructured-version
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 383
diff changeset
131 ServerMainLoop.logger.writeLog(err);
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
132 assert(false);
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
133 }
395
a2efdec5cbfc insert_ack/delete_ack protocol all written.
one
parents: 394
diff changeset
134 startMerge(command);
a2efdec5cbfc insert_ack/delete_ack protocol all written.
one
parents: 394
diff changeset
135 return;
a2efdec5cbfc insert_ack/delete_ack protocol all written.
one
parents: 394
diff changeset
136 }
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
137
395
a2efdec5cbfc insert_ack/delete_ack protocol all written.
one
parents: 394
diff changeset
138 private void startMerge(REPCommand command) {
397
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
139 preMergeCommand = new REPCommand(command);
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
140 preMergeCommand.string = "";
391
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 387
diff changeset
141 // merge は必須だが、EditorのCommand実装をテストするには邪魔なので、off に出来るようにする。
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 387
diff changeset
142 if (noMergeMode) {
396
dc616339b00a half done. returned command conflict.
one
parents: 395
diff changeset
143 endMerge();
391
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 387
diff changeset
144 return;
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 387
diff changeset
145 }
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
146 // START_MERGE を送る
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
147 // 送らないで良い場合もある?
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
148 REPCommand cmd = new REPCommand(REP.SMCMD_START_MERGE,command.sid,REP.SM_EID.id,seq(),0,"");
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
149 send(cmd);
387
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
150 merging = true;
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
151 // Session Manager 側で、このeditorへの他のeditorからの
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
152 // 入力を止めて、merge にそなえる。merge は、eidtor 側から
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
153 // ACKが来てから始まる。
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
154 translator.startMerge(cmd);
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
155 }
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
156
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
157 @Override
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
158 public void setQuit2(REPCommand cmd) {
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
159 quit2 = cmd;
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
160 checkQuit();
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
161 // do not send quit2 until we received all pending
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
162 // command
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
163 }
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
164
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
165 @Override
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
166 public void setEID(int eid) {
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
167 this.eid = eid;
387
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
168 if (translator!=null)
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
169 translator.setEid(eid);
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
170 }
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
171
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
172 public String toString(){
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
173 return ("Editor eid="+eid+" sid="+sid+" " + host + ":" + file);
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
174 }
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
175
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
176 public boolean isMerging() {
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
177 return translator.isMerging();
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
178 }
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
179
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
180
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
181
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
182 void checkEndMerge() {
387
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
183 if (merging) {
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
184 if(translator.isMerging()) return;
396
dc616339b00a half done. returned command conflict.
one
parents: 395
diff changeset
185 endMerge();
387
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
186 merging = false;
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
187 }
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
188 if (quit2!=null) checkQuit();
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
189 }
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
190
396
dc616339b00a half done. returned command conflict.
one
parents: 395
diff changeset
191 private void endMerge() {
dc616339b00a half done. returned command conflict.
one
parents: 395
diff changeset
192 REPCommand mergeEnd = new REPCommand(REP.SMCMD_END_MERGE,sid,eid,seq(),0,"");
dc616339b00a half done. returned command conflict.
one
parents: 395
diff changeset
193 send(mergeEnd);
397
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
194 if (preMergeCommand.eid==eid) {
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
195 // First Phase End, send ACK
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
196 REPCommand keep = new REPCommand(preMergeCommand);
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
197 switch(keep.cmd) {
398
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
198 case REPCMD_INSERT: keep.cmd = REP.REPCMD_INSERT_ACK;break;
7de83b6a34e7 not yet fixed....
one
parents: 397
diff changeset
199 case REPCMD_DELETE: keep.cmd = REP.REPCMD_DELETE_ACK;break;
397
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
200 }
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
201 sentList.add(keep);
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
202 ServerMainLoop.logger.writeLog("Editor eid:"+eid+" sentList = "+sentList);
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
203 assert(sentList.size()<limit);
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
204 next.send(keep);
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
205 } else {
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
206 next.send(preMergeCommand);
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
207 }
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
208 preMergeCommand = null;
396
dc616339b00a half done. returned command conflict.
one
parents: 395
diff changeset
209 }
dc616339b00a half done. returned command conflict.
one
parents: 395
diff changeset
210
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
211 private boolean checkQuit() {
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
212 if (sentList.size()==0&&!isMerging()) {
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
213 send(quit2);
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
214 quit2 = null;
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
215 return true;
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
216 }
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
217 return false;
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
218 }
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
219
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
220 @Override
387
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
221 public boolean manage(REPCommand command) {
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
222
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
223
387
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
224 switch(command.cmd){
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
225 // Editor Command
396
dc616339b00a half done. returned command conflict.
one
parents: 395
diff changeset
226
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
227 case REPCMD_DELETE:
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
228 case REPCMD_INSERT:
396
dc616339b00a half done. returned command conflict.
one
parents: 395
diff changeset
229 case REPCMD_DELETE_ACK:
dc616339b00a half done. returned command conflict.
one
parents: 395
diff changeset
230 case REPCMD_INSERT_ACK:
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
231 case REPCMD_NOP:
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
232 {
387
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
233 translate(command);
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
234 break;
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
235 }
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
236
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
237 case SMCMD_START_MERGE_ACK:
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
238 {
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
239 // マージの処理と次のエディタへコマンドを送信する処理
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
240 translator.mergeAck();
387
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
241 if (!merge(command)) {
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
242 // nothing to do, send END_MERGE
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
243 checkEndMerge();
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
244 }
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
245 break;
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
246 }
386
bba62c4ac323 sync-option
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 385
diff changeset
247
bba62c4ac323 sync-option
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 385
diff changeset
248 case SMCMD_SYNC:
bba62c4ac323 sync-option
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 385
diff changeset
249 if (isMaster())
387
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
250 send(command);
386
bba62c4ac323 sync-option
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 385
diff changeset
251 else
387
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
252 next.send(command);
386
bba62c4ac323 sync-option
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 385
diff changeset
253
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
254 case SMCMD_QUIT:
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
255 {
387
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
256 next.send(command);
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
257 break;
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
258 }
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
259 case SMCMD_QUIT_2:
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
260 {
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
261 // QUIT_2 is returned.
387
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
262 if (command.eid!=eid) {
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
263 // stop this editor unless this is the start, starter will stopped
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
264 // by QUIT_2_ACK
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
265 manager.remove(this);
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
266 }
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
267 // don't send quit_2 directly to the editor until all pending
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
268 // merge is processed.
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
269 // this does not work in distributed case.
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
270 if (next.isDirect())
387
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
271 next.setQuit2(command);
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
272 else
387
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
273 next.send(command);
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
274 break;
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
275 }
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
276 case SMCMD_QUIT_2_ACK:
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
277 {
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
278 manager.remove(this);
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
279 break;
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
280 }
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
281 default:
396
dc616339b00a half done. returned command conflict.
one
parents: 395
diff changeset
282 assert false;
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
283 return false;
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
284 }
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
285 return true;
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
286 }
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
287
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
288
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
289 @Override
387
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
290 public void handle(REPCommand command, REPSelectionKey<REPCommand> key) throws IOException {
391
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 387
diff changeset
291 ServerMainLoop.logger.writeLog("Manager "+manager.getId()+"read : command = " + command
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 387
diff changeset
292 +" from "+manager.editorList.editorByChannel(channel));
387
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
293 if (command.cmd==REP.SMCMD_JOIN||command.cmd==REP.SMCMD_PUT) {
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
294 assert false;
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
295 // 若干問題があるらしい
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
296 next = new Forwarder(manager,next.channel);
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
297 REPNode first = new FirstConnector(manager,channel);
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
298 first.handle(command, key);
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
299 key.attach(new Dispatcher(manager,channel));
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
300 return;
6f356d160e58 IPv6 any address
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 386
diff changeset
301 }
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
302 if (manager.sessionManage(this, command)) return;
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
303 manage(command);
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
304 }
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
305
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
306 @Override
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
307 public void cancel(REPSocketChannel<REPCommand> socketChannel) {
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
308 manager.remove(socketChannel);
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
309 }
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
310
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
311 public boolean isMaster() {
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
312 return mode==REP.SMCMD_PUT;
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
313 }
386
bba62c4ac323 sync-option
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 385
diff changeset
314
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
315
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
316 /* Handle special case first, usually these cases
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
317 * are handled in the next Editor in a session manager, but
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
318 * it is forwarded here.
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
319 */
385
1fca50ce3508 first-working-version
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 384
diff changeset
320 public void forwardedCommandManage(REPCommand command) {
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
321 if (command.cmd==REP.SMCMD_QUIT_2) {
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
322 // we have to wait next editor's finishing before sending this.
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
323 // this is odd, but the editor itself does not know it's merging
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
324 // state. Only this session manager knows it.
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
325 setQuit2(command);
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
326 } else if (command.eid==eid) {
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
327 // if we handle in editor.manage(), this editor cannot distinguish this
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
328 // and user input command from the editor.
397
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
329 REPCommand keep;
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
330 switch(command.cmd) {
397
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
331 case REPCMD_DELETE_ACK:
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
332 case REPCMD_INSERT_ACK:
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
333 checkReturnedCommand(command);
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
334 return ;
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
335 case REPCMD_INSERT:
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
336 keep = new REPCommand(command);
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
337 keep.cmd = REP.REPCMD_INSERT_ACK;
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
338 sentList.add(keep);
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
339 checkReturnedCommand(command);
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
340 return;
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
341 case REPCMD_DELETE:
397
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
342 keep = new REPCommand(command);
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
343 keep.cmd = REP.REPCMD_DELETE_ACK;
149c9a53fc37 half done ACK protocol
one
parents: 396
diff changeset
344 sentList.add(keep);
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
345 checkReturnedCommand(command);
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
346 return;
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
347 }
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
348 }
385
1fca50ce3508 first-working-version
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 384
diff changeset
349 send(command);
1fca50ce3508 first-working-version
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 384
diff changeset
350 }
1fca50ce3508 first-working-version
one@firefly.cr.ie.u-ryukyu.ac.jp
parents: 384
diff changeset
351
382
4b87f89b3afd REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
352 }