Mercurial > hg > FederatedLinda
changeset 59:a372992d0ac2
cluster plus date
author | axmo |
---|---|
date | Tue, 17 Feb 2009 17:24:37 +0900 |
parents | c33abea8cddc |
children | 673085a02ccb |
files | src/fdl/test/transfer/cluster/FDLServWithSendMeta.java src/fdl/test/transfer/cluster/MetaProtocolEngine.java src/fdl/test/transfer/cluster/ProtocolEngineMain.java |
diffstat | 3 files changed, 47 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/src/fdl/test/transfer/cluster/FDLServWithSendMeta.java Fri Feb 13 22:13:10 2009 +0900 +++ b/src/fdl/test/transfer/cluster/FDLServWithSendMeta.java Tue Feb 17 17:24:37 2009 +0900 @@ -5,6 +5,7 @@ import java.io.FileReader; import java.io.IOException; import java.net.*; +import java.util.Arrays; import fdl.FDLindaServ; import fdl.MetaLinda; @@ -17,11 +18,13 @@ } static String nextHost = null; + private static int localport = 10000; + static int chknum; + @Override public void mainLoop() { - System.out.println("change mainloop"); MetaLinda ml = new MetaLinda(tupleSpace, this); - mpe = new MetaProtocolEngine(ml, nextHost); + mpe = new MetaProtocolEngine(ml, nextHost, chknum); mpe.mainLoop(); } @@ -29,7 +32,7 @@ try { chkhost(); FDLServWithSendMeta serv; - serv = new FDLServWithSendMeta(10000); + serv = new FDLServWithSendMeta(localport); serv.mainLoop(); } catch (IOException e) { e.printStackTrace(); @@ -48,16 +51,23 @@ hostTable[i] = line; i++; } + Arrays.sort(hostTable); localhost = InetAddress.getLocalHost().getHostName(); - System.out.println("ホストは"); for (int j=0; j<hostTable.length; j++) { - System.out.println(hostTable[j]); if(localhost.equals(hostTable[j])){ nextHost = hostTable[++j]; + if(hostTable[j] == null) { + nextHost = hostTable[0]; + } } } - System.out.println("です"); - + + if(localhost.equals(hostTable[0])) { + chknum = 1; + } + + System.out.println("localhost:"+localhost); + System.out.println("nexthost"+nextHost); } catch (FileNotFoundException e) { e.printStackTrace(); @@ -65,5 +75,5 @@ e.printStackTrace(); } } - + }
--- a/src/fdl/test/transfer/cluster/MetaProtocolEngine.java Fri Feb 13 22:13:10 2009 +0900 +++ b/src/fdl/test/transfer/cluster/MetaProtocolEngine.java Tue Feb 17 17:24:37 2009 +0900 @@ -2,6 +2,8 @@ import java.io.IOException; import java.nio.ByteBuffer; +import java.text.SimpleDateFormat; +import java.util.Date; import fdl.MetaEngine; @@ -19,19 +21,27 @@ int port = 10000; private PSXLinda psxsend; private ByteBuffer data = ByteBuffer.allocate(10); + private int chknum; - public MetaProtocolEngine(MetaLinda ml, String host) { + public MetaProtocolEngine(MetaLinda ml, String host, int chknum) { this.host = host; this.fdlmeta = ml; + this.chknum = chknum; } public void mainLoop(){ + psxget = fdlmeta; + if(chknum == 1){ + try { + sendData(); + } catch (IOException e) { + e.printStackTrace(); + } + } boolean connect = true; - System.out.println("MetaEngine Start"); while(connect){ try { initConnect(); - sendData(); transfer(); connect = false; } catch (IOException e) { @@ -57,8 +67,6 @@ } } } - System.out.println("Connect "+port); - psxget = fdlmeta; } private void sendData() throws IOException{ @@ -77,20 +85,22 @@ private void transfer() throws IOException { boolean running = true; PSXReply in = psxget.in(id); - System.out.println("PSXReply "+port); while (running) { if(in.ready()){ data = in.getData(); int i = data.getInt(); data.rewind(); + System.out.println("transfer Data => "+i); //outしたbytebufferの変更をこれ以降やっちゃいけない psxsend.out(id,data); - - System.out.println("IntData0 "+port +i); + SimpleDateFormat DF = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS"); + System.out.println(DF.format(new Date())); + System.out.println("connect to => "+host); psxsend.sync(); - running = false; - break; + running = false; + break; } + fdlmeta.sync(); } }
--- a/src/fdl/test/transfer/cluster/ProtocolEngineMain.java Fri Feb 13 22:13:10 2009 +0900 +++ b/src/fdl/test/transfer/cluster/ProtocolEngineMain.java Tue Feb 17 17:24:37 2009 +0900 @@ -35,12 +35,12 @@ 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); - fdl.sync(1); - System.out.println("Send Data"); +// ByteBuffer send = ByteBuffer.allocate(10); +// send.putInt(12); +// send.flip(); +// getpsx.out(id , send); +// fdl.sync(1); +// System.out.println("Send Data"); // psxにデータを用意 boolean running = true; ByteBuffer data2 = ByteBuffer.allocate(10); @@ -50,6 +50,9 @@ //psx1にデータを書き出し data2 = in.getData(); sendpsx.out(id,data2); + int i = data2.getInt(); + data2.rewind(); + System.out.println("transfer Data => "+i); //runningフラグをfalseする running = false; sendpsx.sync(1);