Mercurial > hg > FederatedLinda
changeset 53:629b6cfbd37f
metaprotocol ring
line wrap: on
line diff
--- a/src/fdl/FDLindaServ.java Fri Jan 09 16:09:08 2009 +0900 +++ b/src/fdl/FDLindaServ.java Mon Jan 19 17:49:14 2009 +0900 @@ -12,6 +12,8 @@ import java.util.Iterator; import java.util.logging.Level; +import fdl.test.metaTransfer.Ring.MetaProtocolEngine; + /** * @author kono * @@ -25,6 +27,7 @@ private ServerSocketChannel ssChannel; public TupleSpace tupleSpace; public MetaEngine me; + public MetaProtocolEngine mpe; public static void main(final String[] args) { final String usages = "usage: FDLindaServ [-p port]"; @@ -50,10 +53,10 @@ } } - private void mainLoop() { + public void mainLoop() { MetaLinda ml = new MetaLinda(tupleSpace, this); - // me = new NullMetaEngine(ml); - me = new MetaLogEngine(ml); + me = new NullMetaEngine(ml); + //me = new MetaLogEngine(ml); me.mainLoop(); }
--- a/src/fdl/test/TestMetaLinda.java Fri Jan 09 16:09:08 2009 +0900 +++ b/src/fdl/test/TestMetaLinda.java Mon Jan 19 17:49:14 2009 +0900 @@ -27,8 +27,8 @@ * * @author Shinji Kono * - * @param host The host to connect to - * @param port The port to connect to at the host + * @param localhost The host to connect to + * @param Port The port to connect to at the host */
--- a/src/fdl/test/TestPSXLinda.java Fri Jan 09 16:09:08 2009 +0900 +++ b/src/fdl/test/TestPSXLinda.java Mon Jan 19 17:49:14 2009 +0900 @@ -28,8 +28,8 @@ * * @author Shinji Kono * - * @param host The host to connect to - * @param port The port to connect to at the host + * @param localhost The host to connect to + * @param Port The port to connect to at the host */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test/metaTransfer/FDLServWithSend.java Mon Jan 19 17:49:14 2009 +0900 @@ -0,0 +1,22 @@ +package fdl.test.metaTransfer; + +import java.io.IOException; + +import fdl.FDLindaServ; +import fdl.MetaLinda; + +public class FDLServWithSend extends FDLindaServ { + int port1; + public FDLServWithSend(int port,int port1) throws IOException { + super(port); + this.port1 = port1; + } + + @Override public void mainLoop() { + System.out.println("change mainloop"); + MetaLinda ml = new MetaLinda(tupleSpace, this); + mpe = new MetaProtocolEngine(ml,"MetaEngine", port1); + mpe.mainLoop(); + } + +}
--- a/src/fdl/test/metaTransfer/MetaProtocolEngine.java Fri Jan 09 16:09:08 2009 +0900 +++ b/src/fdl/test/metaTransfer/MetaProtocolEngine.java Mon Jan 19 17:49:14 2009 +0900 @@ -1,69 +1,97 @@ package fdl.test.metaTransfer; +import static org.junit.Assert.assertEquals; + import java.io.IOException; import java.nio.ByteBuffer; + import fdl.MetaEngine; -import fdl.MetaReply; + import fdl.MetaLinda; - +import fdl.PSXLinda; +import fdl.PSXReply; public class MetaProtocolEngine implements MetaEngine { - private MetaLinda fdlmeta; - private ByteBuffer data; private int id = 10; private boolean running = true; - //ここからsend用宣言 - private MetaLinda sendpsx; - private String sendhost = "127.0.0.1"; - private int port; - - public MetaProtocolEngine(MetaLinda fdlmeta, int port) { - this.fdlmeta = fdlmeta; - this.port = port; + private PSXLinda psx; + private String name; + MetaLinda fdl1; + String host = "127.0.0.1"; + int port1; + private PSXLinda psx1; + private ByteBuffer data2 = ByteBuffer.allocate(10); + private int count = 1; + + + public MetaProtocolEngine(MetaLinda ml, String string, int port1) { + this.name = string; + this.port1 = port1; + this.fdl1 = ml; } - - public void metaOpen(int sendport) throws IOException { - try{ - sendpsx.open(sendhost ,sendport); - }catch (IOException e) { + + public void mainLoop(){ + boolean connect = true; + System.out.println("MetaEngine Start"); + while(connect){ + try { + initConnect(); + transfer(); + connect = false; + } catch (IOException e) { try { Thread.sleep(40); } catch (InterruptedException e1) { } } - } - - //meta部分のデータ取得 - public void metaTrans() { - MetaReply in = (MetaReply) fdlmeta.in(id); - while (running) { - if(in.ready()) { - data = in.getData(); - sendpsx.out(id, data); - fdlmeta.sync(); - sendpsx.sync(); - running = false; - break; - } } } - - public void mainLoop() { - System.out.println("MetaProtocolEngine Start"); - if( port == 10001 ){ + private void initConnect(){ + System.out.println(name); + boolean connectpsx = true; + while(connectpsx){ try { - metaOpen(10002); - System.out.println("Connect to Next"); - metaTrans(); - System.out.println("MetaProtocolEngine Connect"); + psx = fdl1.open(host,port1); + connectpsx = false; } catch (IOException e) { - e.printStackTrace(); + try { + Thread.sleep(40); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } } } - + System.out.println("Connect "+port1); + psx1 = fdl1; } + private void transfer() throws IOException { + PSXReply in = psx.in(id); + System.out.println("PSXReply "+port1); + while (running) { + if(in.ready()){ + data2 = in.getData(); + int i = data2.getInt(); + data2.rewind(); + //outしたbytebufferの変更をこれ以降やっちゃいけない + psx1.out(id,data2); + + System.out.println("IntData0 "+port1 +i); + fdl1.sync(); + if (count++>3) { + running = false; + break; + } + System.out.println("IntData1 "+port1 +i); + } + fdl1.sync(); + } + assertEquals(4,count); + } + + } +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test/metaTransfer/MetaProtocolEngine_not.java Mon Jan 19 17:49:14 2009 +0900 @@ -0,0 +1,74 @@ +package fdl.test.metaTransfer; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import fdl.FederatedLinda; +import fdl.MetaEngine; +//import fdl.MetaReply; +import fdl.MetaLinda; +import fdl.PSXLinda; +import fdl.PSXReply; + + +public class MetaProtocolEngine_not implements MetaEngine { + private FederatedLinda fdlmeta; + private ByteBuffer data = ByteBuffer.allocate(1024); + private int id = 10; + private boolean running = true; + + //ここからsend用宣言 + private PSXLinda sendpsx,getpsx; + private String host = "127.0.0.1"; + private int port; + + public MetaProtocolEngine_not(MetaLinda fdlmeta, int port) { + this.port = port; + } + + public void metaOpen(int sendport){ + try{ + sendpsx = fdlmeta.open(host, sendport); + }catch (IOException e) { + e.printStackTrace(); + } + } + + //meta部分のデータ取得 + public void metaTrans() { + try { + getpsx = fdlmeta.open(host, 10001); + } catch (IOException e) { + e.printStackTrace(); + } + PSXReply in = getpsx.in(id); + while (running) { + System.out.println(in); + System.out.println(in.ready()); + if(in.ready()) { + data = in.getData(); + sendpsx.out(id, data); + running = false; + break; + } + } + } + + + public void mainLoop() { + System.out.println("MetaProtocolEngine Start"); + fdlmeta = FederatedLinda.init(); + if( port == 10002 ) { + metaOpen(10003); + metaTrans(); + try { + fdlmeta.sync(); + } catch (IOException e) { + e.printStackTrace(); + } + System.out.println("MetaProtocolEngine Connect"); + } + + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test/metaTransfer/Ring/FDLServWithSend.java Mon Jan 19 17:49:14 2009 +0900 @@ -0,0 +1,22 @@ +package fdl.test.metaTransfer.Ring; + +import java.io.IOException; + +import fdl.FDLindaServ; +import fdl.MetaLinda; + +public class FDLServWithSend extends FDLindaServ { + int port1; + public FDLServWithSend(int port,int port1) throws IOException { + super(port); + this.port1 = port1; + } + + @Override public void mainLoop() { + System.out.println("change mainloop"); + MetaLinda ml = new MetaLinda(tupleSpace, this); + mpe = new MetaProtocolEngine(ml,"MetaEngine", port1); + mpe.mainLoop(); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test/metaTransfer/Ring/MetaProtocolEngine.java Mon Jan 19 17:49:14 2009 +0900 @@ -0,0 +1,97 @@ +package fdl.test.metaTransfer.Ring; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.nio.ByteBuffer; + + +import fdl.MetaEngine; + +import fdl.MetaLinda; +import fdl.PSXLinda; +import fdl.PSXReply; + +public class MetaProtocolEngine implements MetaEngine { + private int id = 10; + private boolean running = true; + + private PSXLinda psx; + private String name; + MetaLinda fdl1; + String host = "127.0.0.1"; + int port1; + private PSXLinda psx1; + private ByteBuffer data2 = ByteBuffer.allocate(10); + private int count = 1; + + + public MetaProtocolEngine(MetaLinda ml, String string, int port1) { + this.name = string; + this.port1 = port1; + this.fdl1 = ml; + } + + public void mainLoop(){ + boolean connect = true; + System.out.println("MetaEngine Start"); + while(connect){ + try { + initConnect(); + transfer(); + connect = false; + } catch (IOException e) { + try { + Thread.sleep(40); + } catch (InterruptedException e1) { + } + } + } + } + + private void initConnect(){ + System.out.println(name); + boolean connectpsx = true; + while(connectpsx){ + try { + psx = fdl1.open(host,port1); + connectpsx = false; + } catch (IOException e) { + try { + Thread.sleep(40); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } + } + } + System.out.println("Connect "+port1); + psx1 = fdl1; + } + + private void transfer() throws IOException { + PSXReply in = psx.in(id); + System.out.println("PSXReply "+port1); + while (running) { + if(in.ready()){ + data2 = in.getData(); + int i = data2.getInt(); + data2.rewind(); + //outしたbytebufferの変更をこれ以降やっちゃいけない + psx1.out(id,data2); + + System.out.println("IntData0 "+port1 +i); + fdl1.sync(1); + if (count++>3) { + running = false; + break; + } + System.out.println("IntData1 "+port1 +i); + } + fdl1.sync(1); + } + assertEquals(4,count); + } + + +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test/metaTransfer/Ring/Server.java Mon Jan 19 17:49:14 2009 +0900 @@ -0,0 +1,31 @@ +package fdl.test.metaTransfer.Ring; + +import java.io.IOException; + +//import fdl.FDLindaServ; + +public class Server extends Thread { + int port1; + int port2; + private String name; + + public Server(String string, int i, int t) { + port1 = i; + port2 = t; + name = string; + } + + public void run(){ +// String[] args = {"-p",Integer.toString(port1)}; + System.out.println(name); +// FDLindaServ.main(args); + try { + FDLServWithSend send = new FDLServWithSend(port1,port2); + send.mainLoop(); + } catch (IOException e) { + e.printStackTrace(); + }; + + } + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test/metaTransfer/Ring/TestSend.java Mon Jan 19 17:49:14 2009 +0900 @@ -0,0 +1,47 @@ +package fdl.test.metaTransfer.Ring; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import fdl.FederatedLinda; +import fdl.PSXLinda; + +public class TestSend extends Thread { + PSXLinda psxsend; + FederatedLinda fdlsend; + + public void run(){ + int id = 10; + int port = 10001; + boolean connect = true; + String host = "127.0.0.1"; + ByteBuffer send = ByteBuffer.allocate(1024); + send.putInt(12); + send.flip(); + while(connect){ + try { + sendData(id, port, host, send); + connect = false; + } catch(IOException e) { + try { + Thread.sleep(40); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } + } + + } + } + + private void sendData(int id, int port, String host, ByteBuffer send) throws IOException { + fdlsend = FederatedLinda.init(); + + psxsend = fdlsend.open(host,port); + System.out.println("Connect Host1"); + psxsend.out(id, send); + fdlsend.sync(1); + System.out.println("Send Data"); + + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test/metaTransfer/Ring/TestTransfer.java Mon Jan 19 17:49:14 2009 +0900 @@ -0,0 +1,30 @@ +package fdl.test.metaTransfer.Ring; + +import static org.junit.Assert.*; + +import java.io.IOException; + +import org.junit.Test; + +public class TestTransfer { + @Test + public void testTransfer() throws IOException { + int port1 = 10001; + int port2 = 10002; + + Server server1 = new Server("Server1",port1, port2); + server1.start(); + + Server server2 = new Server("Server2",port2, port1); + server2.start(); + + try { + server2.join(); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + assertEquals(1,1); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test/metaTransfer/Ring/TestTransferRing.java Mon Jan 19 17:49:14 2009 +0900 @@ -0,0 +1,34 @@ +package fdl.test.metaTransfer.Ring; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class TestTransferRing { + Server[] servers; + final int serverCount = 3; + final int startPort = 10001; + @Test + public void testTransfer() { + int port = startPort; + + servers = new Server[serverCount]; + + for (int i = 0; i < serverCount; i++) { + servers[i] = new Server("Server"+(i+1),port+i,netporot(port+i)); + servers[i].start(); + } + + + + assertEquals(1,1); + } + private int netporot(int i) { + i++; + if(i >= startPort+serverCount) { + return startPort; + } + return i; + } +} +
--- a/src/fdl/test/metaTransfer/Server.java Fri Jan 09 16:09:08 2009 +0900 +++ b/src/fdl/test/metaTransfer/Server.java Mon Jan 19 17:49:14 2009 +0900 @@ -5,7 +5,7 @@ public class Server extends Thread { int port; private String name; - + public Server(String string, int i) { port = i; name = string;
--- a/src/fdl/test/metaTransfer/TestSend.java Fri Jan 09 16:09:08 2009 +0900 +++ b/src/fdl/test/metaTransfer/TestSend.java Mon Jan 19 17:49:14 2009 +0900 @@ -13,21 +13,35 @@ public void run(){ int id = 10; int port = 10001; + boolean connect = true; String host = "127.0.0.1"; ByteBuffer send = ByteBuffer.allocate(1024); send.putInt(12); send.flip(); + while(connect){ + try { + sendData(id, port, host, send); + connect = false; + } catch(IOException e) { + try { + Thread.sleep(40); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } + } + + } + } + + private void sendData(int id, int port, String host, ByteBuffer send) throws IOException { fdlsend = FederatedLinda.init(); - try{ + psxsend = fdlsend.open(host,port); System.out.println("Connect Host1"); psxsend.out(id, send); fdlsend.sync(1); System.out.println("Send Data"); - }catch (IOException e) { - System.out.println("例外:" + e); - } - + } }
--- a/src/fdl/test/metaTransfer/TestTransfer.java Fri Jan 09 16:09:08 2009 +0900 +++ b/src/fdl/test/metaTransfer/TestTransfer.java Mon Jan 19 17:49:14 2009 +0900 @@ -1,29 +1,27 @@ package fdl.test.metaTransfer; import static org.junit.Assert.*; + +import java.io.IOException; + import org.junit.Test; public class TestTransfer { @Test - public void testTransfer() { + public void testTransfer() throws IOException { int port1 = 10001; int port2 = 10002; + +// Server server1 = new Server("Server1",port1); +// server1.start(); +// Server server2 = new Server("Server2",port2); server2.start(); - Server server1 = new Server("Server1",port1); - server1.start(); - try { - server1.join(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - TestSend send = new TestSend(); - send.start(); - try { - send.join(); - } catch (InterruptedException e) { - e.printStackTrace(); - } + + + FDLServWithSend send = new FDLServWithSend(port1, port2); + send.mainLoop(); + assertEquals(1,1); } }
--- a/src/fdl/test/transfer/ProtocolEngine.java Fri Jan 09 16:09:08 2009 +0900 +++ b/src/fdl/test/transfer/ProtocolEngine.java Mon Jan 19 17:49:14 2009 +0900 @@ -17,7 +17,7 @@ int port2 = 10002; private int id = 10; private PSXLinda psx1; - private boolean running; + private boolean running = true; private ByteBuffer data2 = ByteBuffer.allocate(10); public ProtocolEngine(String string, int port1, int port2) { @@ -49,13 +49,14 @@ send.putInt(12); send.flip(); psx2.out(id, send); - psx2.sync(); + psx2.sync(1); } private void transfer(PSXLinda psx2, PSXLinda psx12) throws IOException { PSXReply in = psx2.in(id); while (running) { + System.out.println(in.ready()); if(in.ready()){ //psx1にデータを書き出し data2 = in.getData();
--- a/src/fdl/test/transfer/TestTransfer.java Fri Jan 09 16:09:08 2009 +0900 +++ b/src/fdl/test/transfer/TestTransfer.java Mon Jan 19 17:49:14 2009 +0900 @@ -3,7 +3,6 @@ import static org.junit.Assert.*; import org.junit.Test; - public class TestTransfer { @Test public void testTransfer() {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test/transfer/two/ProtocolEngine.java Mon Jan 19 17:49:14 2009 +0900 @@ -0,0 +1,73 @@ +package fdl.test.transfer.two; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import fdl.FederatedLinda; +import fdl.PSXLinda; +import fdl.PSXReply; + + +public class ProtocolEngine extends Thread{ + private PSXLinda psx; + private String name; + FederatedLinda fdl1; + String host = "127.0.0.1"; + int port1 = 10001; + int port2 = 10002; + private int id = 10; + private PSXLinda psx1; + private boolean running; + private ByteBuffer data2 = ByteBuffer.allocate(10); + + public ProtocolEngine(String string, int port1, int port2) { + this.name = string; + this.port1 = port1; + this.port2 = port2; + } + + public void run(){ + fdl1 = FederatedLinda.init(); + try { + System.out.println(name); + psx = fdl1.open(host,port1); + System.out.println("Connect Host1"); + psx1 = fdl1.open(host,port2); + System.out.println("Connect Host2"); + // Host1にデータを送信する。 + testSend(psx); + // psxにデータを用意 + transfer(psx,psx1); + + } catch (IOException e) { + e.printStackTrace(); + } + } + + private void testSend(PSXLinda psx2) throws IOException { + ByteBuffer send = ByteBuffer.allocate(10); + send.putInt(12); + send.flip(); + psx2.out(id, send); + psx2.sync(); + } + + + private void transfer(PSXLinda psx2, PSXLinda psx12) throws IOException { + PSXReply in = psx2.in(id); + while (running) { + if(in.ready()){ + //psx1にデータを書き出し + data2 = in.getData(); + psx12.out(id,data2); + //runningフラグをfalseする + running = false; + fdl1.sync(0); + break; + } + fdl1.sync(); + } + + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test/transfer/two/Server.java Mon Jan 19 17:49:14 2009 +0900 @@ -0,0 +1,20 @@ +package fdl.test.transfer.two; + +import fdl.FDLindaServ; + +public class Server extends Thread { + int port; + private String name; + + public Server(String string, int i) { + port = i; + name = string; + } + + public void run(){ + String[] args = {"-p",Integer.toString(port)}; + System.out.println(name); + FDLindaServ.main(args); + } + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test/transfer/two/TestGet.java Mon Jan 19 17:49:14 2009 +0900 @@ -0,0 +1,48 @@ +package fdl.test.transfer.two; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import fdl.FederatedLinda; +import fdl.PSXLinda; +import fdl.PSXReply; + + +public class TestGet extends Thread { + private PSXLinda psxget; + private FederatedLinda fdlget; + private int port; + String host = "127.0.0.1"; + private ByteBuffer data = ByteBuffer.allocate(1024); + + public TestGet(int port1) { + this.port = port1; + } + + public void run(){ + int id = 10; + int i; + fdlget = FederatedLinda.init(); + try { + System.out.println("TestGet Start"); + psxget = fdlget.open(host, port); + System.out.println("Host1 connected"); + //getにidのタプルを取り出す + PSXReply dataGet = psxget.in(id); + System.out.println("dataget"); + System.out.println(dataGet.ready()); + if(dataGet.ready()){ + System.out.println(dataGet); + data = dataGet.getData(); + fdlget.sync(1); + i = data.getInt(); + System.out.println(i); + } + } catch (IOException e) { + try { + Thread.sleep(10); + } catch (InterruptedException e1) { + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test/transfer/two/TestSend.java Mon Jan 19 17:49:14 2009 +0900 @@ -0,0 +1,50 @@ +package fdl.test.transfer.two; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import fdl.FederatedLinda; +import fdl.PSXLinda; + +public class TestSend extends Thread { + PSXLinda psxsend; + FederatedLinda fdlsend; + private int port; + + public TestSend(int port1) { + this.port = port1; + } + + public void run(){ + int id = 10; + int i; + String host = "127.0.0.1"; + ByteBuffer send = ByteBuffer.allocate(1024); + send.putInt(12); + send.flip(); + i = send.getInt(); + send.rewind(); + fdlsend = FederatedLinda.init(); + boolean connect = true; + while(connect) { + try{ + System.out.println("TestSend Start"); + psxsend = fdlsend.open(host,port); + System.out.println("Set Data = " +i); + System.out.println("Connect Host1"); + psxsend.out(id, send); + System.out.println("regist Que"); + fdlsend.sync(1); + System.out.println("Send Data"); + connect = false; + }catch (IOException e) { + try { + Thread.sleep(40); + } catch (InterruptedException e1) { + } + } + } + } + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test/transfer/two/TestTransfer.java Mon Jan 19 17:49:14 2009 +0900 @@ -0,0 +1,20 @@ +package fdl.test.transfer.two; + +import static org.junit.Assert.*; +import org.junit.Test; + +public class TestTransfer { + @Test + public void testTransfer() throws InterruptedException { + int port = 10001; + Server server = new Server("Server1",port); + server.start(); + server.join(); + TestSend send = new TestSend(port); + send.start(); + + send.join(); + + assertEquals(1,1); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test2/CountTest.java Mon Jan 19 17:49:14 2009 +0900 @@ -0,0 +1,42 @@ +package fdl.test2; + +class CountA implements Runnable { + + public void run() { + for (int i=0; i <= 5; i++) { + System.out.println("A: " + i); + } + } +} + +class CountB implements Runnable { + + public void run() { + for (int i=5; i >= 0; i--) { + System.out.println(" B: " + i); + } + } +} + +class CountTest { + public static void main(String[] args) { + // ランナブルクラスのインスタンス化 + CountA runA = new CountA(); + CountB runB = new CountB(); + System.out.println("Runnable Class のインスタンス化終了"); + + // スレッドのインスタンス化 + Thread threadA = new Thread(runA); + Thread threadB = new Thread(runB); + System.out.println("Thread へ受け渡し終了"); + + // スレッドの開始 + threadA.start(); + threadB.start(); + System.out.println("Thread の start() 終了"); + System.out.println("適時自動的に run() が実行される"); + + + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test2/Server.java Mon Jan 19 17:49:14 2009 +0900 @@ -0,0 +1,33 @@ +package fdl.test2; + +import java.net.*; +import java.io.*; +import java.util.*; + +public class Server extends Thread{ + static int Port = 10007; + + public void run(){ + try { + ServerSocket server = new ServerSocket(Port); + Socket sock =null; + System.out.println("Server Start"); + sock = server.accept(); + System.out.println("Connect"); + PrintWriter ps = new PrintWriter(sock.getOutputStream()); + Date d = new Date(); + ps.print(d + "\r\n"); + ps.flush(); + sock.close(); // クライアントからの接続を切断 + System.out.println("Connection Closed"); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public static void main(String[] args) { + Server sv = new Server(); + sv.start(); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test2/TestRead.java Mon Jan 19 17:49:14 2009 +0900 @@ -0,0 +1,23 @@ +package fdl.test2; + +import java.io.*; + +public class TestRead { + + public static void main(String[] args) { + try { + File inputFile = new File(args[0]); + FileReader in = new FileReader(inputFile); + BufferedReader br = new BufferedReader(in); + String line; + while ((line = br.readLine()) != null) { + System.out.println(line); + } + br.close(); + in.close(); + } catch (IOException e) { + System.out.println(e); + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test2/TestRing.java Mon Jan 19 17:49:14 2009 +0900 @@ -0,0 +1,50 @@ +package fdl.test2; + +import java.io.*; +import java.io.IOException; +import java.nio.ByteBuffer; + +import fdl.FederatedLinda; +import fdl.PSXLinda; +import fdl.PSXReply; + +public class TestRing { + static int id; + public static void main(String args[]){ + + try{ + FederatedLinda fdl; + PSXLinda psx; + String host = "127.0.0.1"; + PSXReply r; + + FileReader in = new FileReader("nodelist"); + BufferedReader br = new BufferedReader(in); + String line; + + while ((line = br.readLine()) != null) { + int i1 = Integer.parseInt(line); + fdl = FederatedLinda.init(); + psx = fdl.open(host,i1); + r = psx.in(65535); + fdl.sync(1); + + ByteBuffer data = ByteBuffer.allocate(10); + data.putInt(10); + data.flip(); + + psx.out(1,data); + while(!r.ready()){ + psx.sync(); + } + } + br.close(); + in.close(); + + + }catch (IOException e) { + System.err.println("Communication failure."); + } + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test2/client.java Mon Jan 19 17:49:14 2009 +0900 @@ -0,0 +1,24 @@ +package fdl.test2; + +import java.io.*; +import java.net.*; + +public class client { + public static void main(String arg[]) throws IOException{ + String www = arg[0]; + int port = 10007; + Socket sock; + BufferedReader dis; +// PrintWriter ps; + sock = new Socket(www,port); + dis = new BufferedReader(new InputStreamReader(sock.getInputStream())); +// ps = new PrintWriter(sock.getOutputStream(),true); +// ps.println("Get"+arg[1]); +// String s = null; +// while((s = dis.readLine()) != null){ + System.out.println(dis); +// } + sock.close(); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test2/nodelist Mon Jan 19 17:49:14 2009 +0900 @@ -0,0 +1,2 @@ +10000 +10001
--- a/src/fdl/test2/testSend.java Fri Jan 09 16:09:08 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -package fdl.test2; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.LinkedList; - -import fdl.FederatedLinda; -import fdl.PSX; -import fdl.PSXCallback; -import fdl.PSXLinda; - -public class testSend { - -}