# HG changeset patch # User pin # Date 1217916579 -32400 # Node ID 1768e68ba98e6fa5aa4c45a657f1e582df1a5635 # Parent e33871f4b39a627405da9ed7ad652d4600626732 *** empty log message *** diff -r e33871f4b39a -r 1768e68ba98e bin/remoteeditor/network/REP.class Binary file bin/remoteeditor/network/REP.class has changed diff -r e33871f4b39a -r 1768e68ba98e src/pathfinder/mergetest/EditorSimulatorWithoutMerger.java --- a/src/pathfinder/mergetest/EditorSimulatorWithoutMerger.java Mon Aug 04 20:34:09 2008 +0900 +++ b/src/pathfinder/mergetest/EditorSimulatorWithoutMerger.java Tue Aug 05 15:09:39 2008 +0900 @@ -23,20 +23,20 @@ /* received Command */ ns.writeLog("\tEditor"+eid+" catch command from "+cmd.eid+" NO."+cmd.seq, 3); - //if (cmd.eid != -2 && eid == 0) ns.writeLog("\tEditor"+eid+" catch command from "+cmd.eid+" :"+cmd, 1); + //if (eid == 3) ns.writeLog("\tEditor"+eid+" catch command from "+cmd.eid+" :"+cmd, 1); //System.out.println(eid + ":" + cmd.eid); if (cmd.eid==eid){ - text.edit(cmd); + //text.edit(cmd); cs.write(new REPCommand(cmd)); /* 終了条件 */ - if (cmd.cmd==REP.SMCMD_QUIT){ - ns.writeLog("\tEditor"+eid+" catch QUIT command emited by itself.", 3); - running=false; break; - } +// if (cmd.cmd==REP.SMCMD_QUIT){ +// ns.writeLog("\tEditor"+eid+" catch QUIT command emited by itself.", 3); +// running=false; break; +// } } else if (cmd.eid==-1){ /* 制御プロセスからの指令 */ ns.writeLog("\tEditor"+eid+" send command.", 2); @@ -48,6 +48,14 @@ }else if(cmd.eid == -2){ // Merged Commands. text.edit(cmd); + + /* 終了条件 */ + if (cmd.cmd==REP.SMCMD_QUIT){ + ns.writeLog("\tEditor"+eid+" catch QUIT command emited by itself.", 3); + running=false; break; + }else{ + cs.write(new REPCommand(cmd)); + } } else { ns.writeLog("\t\tEditor"+eid+" edit text and pass Cmd. " + " : " + cmd, 3); diff -r e33871f4b39a -r 1768e68ba98e src/pathfinder/mergetest/SelectionKeySimulator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pathfinder/mergetest/SelectionKeySimulator.java Tue Aug 05 15:09:39 2008 +0900 @@ -0,0 +1,28 @@ +package pathfinder.mergetest; + +public class SelectionKeySimulator
{ + + public static final int OP_READ = 0; + private ChannelSimulator
channel; + + public SelectionKeySimulator(ChannelSimulator
cs) { + // TODO Auto-generated constructor stub + channel = cs; + } + + public boolean isAcceptable() { + // TODO Auto-generated method stub + return false; + } + + public boolean isReadable() { + // TODO Auto-generated method stub + return true; + } + + public ChannelSimulator
channel() { + // TODO Auto-generated method stub + return channel; + } + +} diff -r e33871f4b39a -r 1768e68ba98e src/pathfinder/mergetest/SelectorSimulator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pathfinder/mergetest/SelectorSimulator.java Tue Aug 05 15:09:39 2008 +0900 @@ -0,0 +1,56 @@ +package pathfinder.mergetest; + +import java.util.ArrayList; +import java.util.Set; + +public class SelectorSimulator
{
+
+ private ArrayList ns;
+ private ArrayList _ns) {
+ // TODO Auto-generated constructor stub
+ ns = _ns;
+ keyList = new ArrayList key : keyList){
+ ChannelSimulator channel = key.channel();
+ if(channel.readQisEmpty()){
+ empty = true;
+ }else{
+ empty = false;
+ //selectedKeys = key;
+ selectedKeys.add(key);
+ break;
+ }
+ }
+
+ try {
+ if(empty) ns.wait();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ return selectedKeys.size();
+ }
+
+ public SelectionKeySimulator register(ChannelSimulator cs){
+ SelectionKeySimulator key = new SelectionKeySimulator (cs);
+ keyList.add(new SelectionKeySimulator (cs));
+ return key;
+ }
+
+ public ArrayList selector;
+ private List _ns) {
super(_ns);
@@ -28,7 +27,9 @@
super(_ns, max_client, max_packet);
editorList = new ArrayList (_ns);
+ //quitCommand = new REPCommand();
}
protected void checkAccept(){
@@ -37,175 +38,137 @@
csList.add(cs);
editorList.add(new TranslaterImp1(editorList.size()));
mergedList.add(new ArrayList cs, int key) {
+ selector.register(cs);
+ }
- //int i=0;
- int count=0;
- P packet = null;
- //REPCommand[] cmds;
+ public void run(){
ns.writeLog("SessionManager start.", 1);
/* Main Loop */
- ChannelSimulator cs = null; // = csList.get(i);
- try {
- Thread.sleep(4000);
- } catch (InterruptedException e1) {
- e1.printStackTrace();
+ //Selectorを用いた実装
+ //while(running && (MAX_PACKET==0 || count channel = key.channel();
+ selector.register(channel);
+ channel = null;
+
+ }else if(key.isReadable()){
+ ChannelSimulator channel = key.channel();
+ P packet = channel.read();
+ REPCommand command = unpack(packet);
+
+ manage(channel, command);
+ }
+ }
}
- while(running && (MAX_PACKET==0 || count nextChannel = csList.get(neid);
+ REPCommand[] cmds;
+
+ translate(eid, neid, command);
+
+ }
- for(int i = 0; i < csList.size(); i++){
- cs = csList.get(i);
- if((packet=cs.poll())!=null) {
- ns.writeLog("SeMa pass packet to "+i+":>> "+packet.toString(), 3);
- eid = i;
- break;
+ private void translate(int eid, int neid, REPCommand command) {
+ // TODO Auto-generated method stub
+ ChannelSimulator channel = csList.get(eid);
+ ChannelSimulator nextChannel = csList.get(neid);
+ if(command.eid == eid){
+ if(checkOwnCommand(command)){
+ //エディタからの編集コマンドが他の全てのエディタを通って戻ってきた場合
+ if(command.cmd == REP.SMCMD_QUIT){
+ //QUITコマンドの場合
+ REPCommand tmp = new REPCommand(command);
+ tmp.eid = -2;
+ quitCommand = tmp;
+ //channel.write(pack(tmp));
+ }else{
+ //エディタからの編集コマンドが戻ってきた場合、マージしてエディタへ反映
+ REPCommand[] cmds = editorList.get(eid).catchOwnCommand(command);
+ for(REPCommand cmd : cmds){
+ REPCommand tmp2 = new REPCommand(cmd);
+ tmp2.eid = -2;
+ mergedList.get(eid).add(cmd); //マージして送信したコマンドを覚えておくためのリスト
+ channel.write(pack(tmp2));
}
}
- if(cs == null) {
- try { ns.wait(); } catch (InterruptedException e) { e.printStackTrace(); }
- //continue;
- result = false;
+ }else{
+ if(command.cmd == REP.SMCMD_QUIT){
+ //エディタからのQUITコマンド
+ sentList.get(eid).add(command);
+ nextChannel.write(pack(command));
+ }else{
+ //エディタからの新たな編集コマンド
+ if(mergedList.get(eid).size() > 0){
+ //マージの際にユーザから割り込みがあった場合
+ }
+ sentList.get(eid).add(command);
+ editorList.get(eid).transSendCmd(command);
+ nextChannel.write(pack(command));
}
- if(packet == null) result = false;
}
- if(!result) continue;
- if(!running) break;
-
- int neid = (eid+1)%csList.size();
-
- REPCommand[] cmds3 = receivePacket(eid, packet);
- if(cmds3 != null) sendPacket(neid, cmds3);
-
-
-/* // Merge
- REPCommand command = unpack(packet);
- REPCommand[] cmds;
-
- //int neid = (eid+1)%csList.size();
- cs = csList.get(neid);
-
- if(neid == command.eid){
-
- // コマンドが一周して戻ってきた場合
- cmds = editorList.get(neid).catchOwnCommand(command);
- for (int j=0; j