Mercurial > hg > FederatedLinda
changeset 56:0143623aa465
(no commit message)
author | axmo |
---|---|
date | Wed, 11 Feb 2009 20:43:55 +0900 |
parents | 865bf7f1bb8d |
children | 48bb577a313f |
files | src/fdl/test/transfer/cluster/ProtocolEngine.java src/fdl/test/transfer/cluster/Server.java src/fdl/test/transfer/cluster/TestGet.java src/fdl/test/transfer/cluster/TestSend.java |
diffstat | 4 files changed, 174 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test/transfer/cluster/ProtocolEngine.java Wed Feb 11 20:43:55 2009 +0900 @@ -0,0 +1,64 @@ +package fdl.test.transfer.cluster; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import fdl.FederatedLinda; +import fdl.PSXLinda; +import fdl.PSXReply; + +public class ProtocolEngine { + static int id = 10; + static FederatedLinda fdl; + static PSXLinda getpsx; + static PSXLinda sendpsx; + static int port = 10000; + private static String getHost = null; + private static String sendHost = null; + + public static void main(String[] args) { + for (int i=0; i<args.length; ++i) { + if("-get".equals(args[i])){ + getHost = args[++i]; + } else if("-send".equals(args[i])){ + sendHost = args[++i]; + } else { + System.err.println("引数指定の誤り:未知の引数が指定されました"); + } + } + fdl = FederatedLinda.init(); + try { + getpsx = fdl.open(getHost,port); + System.out.println("Connect Host1"); + sendpsx = fdl.open(sendHost,port); + System.out.println("Connect Host2"); + // Host1にデータを送信する。 + ByteBuffer send = ByteBuffer.allocate(10); + send.putInt(12); + send.flip(); + getpsx.out(id , send); + getpsx.sync(); + System.out.println("Send Data"); + // psxにデータを用意 + boolean running = true; + ByteBuffer data2 = ByteBuffer.allocate(10); + PSXReply in = getpsx.in(id); + while (running) { + if(in.ready()){ + //psx1にデータを書き出し + data2 = in.getData(); + sendpsx.out(id,data2); + //runningフラグをfalseする + running = false; + sendpsx.sync(); + System.out.println("Transfer Data"); + break; + } + fdl.sync(); + } + + } catch (IOException e) { + e.printStackTrace(); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test/transfer/cluster/Server.java Wed Feb 11 20:43:55 2009 +0900 @@ -0,0 +1,12 @@ +package fdl.test.transfer.cluster; + +import fdl.FDLindaServ; + +public class Server{ + public static void main(String[] args){ + int port = 10000; + String[] args1 = {"-p",Integer.toString(port)}; + FDLindaServ.main(args1); + } + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test/transfer/cluster/TestGet.java Wed Feb 11 20:43:55 2009 +0900 @@ -0,0 +1,48 @@ +package fdl.test.transfer.cluster; + +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/cluster/TestSend.java Wed Feb 11 20:43:55 2009 +0900 @@ -0,0 +1,50 @@ +package fdl.test.transfer.cluster; + +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) { + } + } + } + } + + +}