# HG changeset patch # User axmo # Date 1231484948 -32400 # Node ID 00d2203fac802b5afa8ce685b68bbb3b38e4722b # Parent 454a5376232f558a0cc3c59e9ddb087ff0110ace MetaProtocolEngine still diff -r 454a5376232f -r 00d2203fac80 src/fdl/test/metaTransfer/MetaProtocolEngine.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test/metaTransfer/MetaProtocolEngine.java Fri Jan 09 16:09:08 2009 +0900 @@ -0,0 +1,69 @@ +package fdl.test.metaTransfer; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import fdl.MetaEngine; +import fdl.MetaReply; +import fdl.MetaLinda; + + +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; + } + + public void metaOpen(int sendport) throws IOException { + try{ + sendpsx.open(sendhost ,sendport); + }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 ){ + try { + metaOpen(10002); + System.out.println("Connect to Next"); + metaTrans(); + System.out.println("MetaProtocolEngine Connect"); + } catch (IOException e) { + e.printStackTrace(); + } + } + + } + +} diff -r 454a5376232f -r 00d2203fac80 src/fdl/test/metaTransfer/Server.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test/metaTransfer/Server.java Fri Jan 09 16:09:08 2009 +0900 @@ -0,0 +1,20 @@ +package fdl.test.metaTransfer; + +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 diff -r 454a5376232f -r 00d2203fac80 src/fdl/test/metaTransfer/TestSend.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test/metaTransfer/TestSend.java Fri Jan 09 16:09:08 2009 +0900 @@ -0,0 +1,33 @@ +package fdl.test.metaTransfer; + +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; + String host = "127.0.0.1"; + ByteBuffer send = ByteBuffer.allocate(1024); + send.putInt(12); + send.flip(); + 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); + } + + } + +} diff -r 454a5376232f -r 00d2203fac80 src/fdl/test/metaTransfer/TestTransfer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test/metaTransfer/TestTransfer.java Fri Jan 09 16:09:08 2009 +0900 @@ -0,0 +1,29 @@ +package fdl.test.metaTransfer; + +import static org.junit.Assert.*; +import org.junit.Test; + +public class TestTransfer { + @Test + public void testTransfer() { + int port1 = 10001; + int port2 = 10002; + 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(); + } + assertEquals(1,1); + } +}