# HG changeset patch # User pin # Date 1199770748 -32400 # Node ID 75fc44fda58350a1353e48d8a3dfb6a7120f6fee # Parent 6f174e2b75038e1a454141bd8081dd8f9be65d58 *** empty log message *** diff -r 6f174e2b7503 -r 75fc44fda583 src/pathfinder/BlockingQnoSeMa/ChannelSimulator.java --- a/src/pathfinder/BlockingQnoSeMa/ChannelSimulator.java Mon Jan 07 05:41:45 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -package pathfinder.BlockingQnoSeMa; - -import java.util.concurrent.BlockingQueue; - -public class ChannelSimulator

{ - private BlockingQueue

qread; - private BlockingQueue

qwrite; - - public ChannelSimulator(BlockingQueue

_a, BlockingQueue

_b){ - qread = _a; - qwrite = _b; - } - - public P read(){ - try { - return qread.take(); - } catch (InterruptedException e) { - e.printStackTrace(); - return null; - } - } - - public boolean write(P p){ - try { - qwrite.put(p); - return true; - } catch (InterruptedException e) { - e.printStackTrace(); - return false; - } - } - - public BlockingQueue

getReadQ(){ - return qread; - } - public BlockingQueue

getWriteQ(){ - return qwrite; - } - public void setReadQ(BlockingQueue

bq){ - qread = bq; - } - public void setWriteQ(BlockingQueue

bq){ - qwrite = bq; - } - - public boolean readQisEmpty() { - return qread.isEmpty(); - } - public boolean writeQisEmpty() { - return qwrite.isEmpty(); - } -} diff -r 6f174e2b7503 -r 75fc44fda583 src/pathfinder/BlockingQnoSeMa/EditorSimulator.java --- a/src/pathfinder/BlockingQnoSeMa/EditorSimulator.java Mon Jan 07 05:41:45 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,106 +0,0 @@ -package pathfinder.BlockingQnoSeMa; - -import java.util.Queue; - -import remoteeditor.command.REPCommand; -import remoteeditor.network.REP; -import sample.merge.Translater; -import sample.merge.TranslaterImp1; - -public class EditorSimulator extends Thread{ - private int eid; - private int seq; - private boolean isOwner; - private NetworkSimulator ns; - private ChannelSimulator cs; - private Queue CmdList; - private TranslaterImp1 translater; - private Text text; - private boolean running=true; - - public EditorSimulator(int _eid, NetworkSimulator _ns, Queue q, String _name) { - super(_name); - eid = _eid; - ns = _ns; - CmdList = q; - translater = new TranslaterImp1(_eid); - text = new Text(); - cs = ns.connect(); - } - - public void setOwner(boolean f){ - isOwner = f; - } - synchronized public void finish(){ - running = false; - } - - public void run(){ - System.out.println("Editor"+eid+" start."); - - // Send All Command that is included CmdList. - sendAllCommand(); - - // MainLoop, - while(running){ - REPCommand cmd = cs.read(); - REPCommand[] cmds; - - //終了条件 - if (cmd.eid==eid && cmd.cmd==REP.SMCMD_QUIT){ - System.out.println("\tEditor"+eid+" catch QUIT command emited by itself."); - translater.transReceiveCmd(cmd); - running=false; break; - } - System.out.println("\tEditor"+eid+" catch command:>> "+cmd.toString()); - cmds = translater.transReceiveCmd(cmd); - if (cmds==null) continue; - - for (int i=0; i { - /** Established connection */ - private LinkedList> connectedList; - - public NetworkSimulator(){ - connectedList = new LinkedList>(); - } - - /** - * Request to connect. - * Client editor use this method to connect SeMa. - * @param cs - */ - public ChannelSimulator

connect(){ - ChannelSimulator

cs; - if (connectedList.isEmpty()){ - BlockingQueue

q = new LinkedBlockingQueue

(); - cs = new ChannelSimulator

(q, q); - }else{ - BlockingQueue

rq = connectedList.getLast().getWriteQ(); - BlockingQueue

wq = new LinkedBlockingQueue

(); - connectedList.getFirst().setReadQ(wq); - -/* ChannelSimulator

lastcs = connectedList.getLast(); - BlockingQueue

rq = lastcs.getWriteQ(); - - BlockingQueue

wq = new LinkedBlockingQueue

(); - ChannelSimulator

firstcs = connectedList.getFirst(); - firstcs.setReadQ(wq); -*/ - cs = new ChannelSimulator

(rq, wq); - } - - connectedList.addLast(cs); - return cs; - } - - public boolean checkAllCS(){ - for(ChannelSimulator

cs: connectedList){ - if(!cs.readQisEmpty()) return false; - } - return true; - } -} diff -r 6f174e2b7503 -r 75fc44fda583 src/pathfinder/BlockingQnoSeMa/NetworkSimulator_withoutSeMa.java --- a/src/pathfinder/BlockingQnoSeMa/NetworkSimulator_withoutSeMa.java Mon Jan 07 05:41:45 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -package pathfinder.BlockingQnoSeMa; - -import java.util.LinkedList; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; - -public class NetworkSimulator_withoutSeMa

{ - /** Established connection */ - private LinkedList> connectedList; - - public NetworkSimulator_withoutSeMa(){ - connectedList = new LinkedList>(); - } - - /** - * Request to connect. - * Client editor use this method to connect SeMa. - * @param cs - */ - public ChannelSimulator

connect(){ - ChannelSimulator

cs; - if (connectedList.isEmpty()){ - BlockingQueue

q = new LinkedBlockingQueue

(); - cs = new ChannelSimulator

(q, q); - }else{ - BlockingQueue

rq = connectedList.getLast().getWriteQ(); - BlockingQueue

wq = new LinkedBlockingQueue

(); - connectedList.getFirst().setReadQ(wq); - -/* ChannelSimulator

lastcs = connectedList.getLast(); - BlockingQueue

rq = lastcs.getWriteQ(); - - BlockingQueue

wq = new LinkedBlockingQueue

(); - ChannelSimulator

firstcs = connectedList.getFirst(); - firstcs.setReadQ(wq); -*/ - cs = new ChannelSimulator

(rq, wq); - } - - connectedList.addLast(cs); - return cs; - } - - public boolean checkAllCS(){ - for(ChannelSimulator

cs: connectedList){ - if(!cs.readQisEmpty()) return false; - } - return true; - } -} diff -r 6f174e2b7503 -r 75fc44fda583 src/pathfinder/BlockingQnoSeMa/TestMerger.java --- a/src/pathfinder/BlockingQnoSeMa/TestMerger.java Mon Jan 07 05:41:45 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +0,0 @@ -package pathfinder.BlockingQnoSeMa; - -import java.util.LinkedList; -import remoteeditor.command.REPCommand; -import remoteeditor.network.REP; - -public class TestMerger { - static public int cmdNO[] = { REP.REPCMD_INSERT, REP.REPCMD_REPLACE, REP.REPCMD_DELETE }; - private NetworkSimulator ns; - private LinkedList editors; - - public TestMerger(){ - ns = new NetworkSimulator(); - editors = new LinkedList(); - } - - public static void main(String[] args){ - TestMerger tm; - int i = (args.length>0) ? Integer.parseInt(args[0]) : 2; - System.out.println("number of Editor = "+i); - int j = (args.length>1) ? Integer.parseInt(args[1]) : 3; - System.out.println("number of Packet = "+i); - tm = new TestMerger(); - - tm.createEditors(i, j); - tm.startTest(); - - tm.printAllTexts(); - //if (!tm.checkCS()) - // System.out.println("Error!! :some ChannelSimulator still have packet!"); - if (!tm.checkEquality()) - System.out.println("Error!! :all Editor's text is NOT mutch!"); - assert tm.checkEquality(); - } - - private void startTest() { - for (EditorSimulator ee: editors){ - ee.start(); - } - - for (EditorSimulator ee: editors){ - try { - ee.join(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - - private void createEditors(int ne, int np){ - for (int i=0; i cmds = new LinkedList(); - // 各エディタが送信するコマンド列を生成 - - for (int j=0; j strList; - - public Text(){ - this(Text.text0); - } - public Text(String[] _strings){ - strList = new LinkedList(Arrays.asList(_strings)); - } - - synchronized public void insert(int i, String str){ - assert 0