Mercurial > hg > FederatedLinda
changeset 58:c33abea8cddc
can doing on cluster
author | axmo |
---|---|
date | Fri, 13 Feb 2009 22:13:10 +0900 |
parents | 48bb577a313f |
children | a372992d0ac2 |
files | src/fdl/test/transfer/cluster/FDLServWithSend.java src/fdl/test/transfer/cluster/FDLServWithSendMeta.java src/fdl/test/transfer/cluster/HostCheck.java src/fdl/test/transfer/cluster/MetaProtocolEngine.java src/fdl/test/transfer/cluster/ProtocolEngine.java src/fdl/test/transfer/cluster/ProtocolEngineMain.java src/fdl/test/transfer/cluster/Server.java src/fdl/test/transfer/cluster/ServerMain.java |
diffstat | 8 files changed, 208 insertions(+), 136 deletions(-) [+] |
line wrap: on
line diff
--- a/src/fdl/test/transfer/cluster/FDLServWithSend.java Thu Feb 12 14:42:27 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -package fdl.test.transfer.cluster; - -import java.io.IOException; - -import fdl.FDLindaServ; -import fdl.MetaLinda; - - -public class FDLServWithSend extends FDLindaServ { - public FDLServWithSend(int port) throws IOException { - super(port); - } - - private static String host = "localhost"; - - @Override public void mainLoop() { - System.out.println("change mainloop"); - MetaLinda ml = new MetaLinda(tupleSpace, this); - mpe = new MetaProtocolEngine(ml, host); - mpe.mainLoop(); - } - - public static void main(String[] args){ - for (int i=0; i<args.length; ++i) { - if("-send".equals(args[i])){ - host = args[++i]; - } else { - System.err.println("引数指定の誤り:未知の引数が指定されました"); - } - } - try { - FDLServWithSend serv; - serv = new FDLServWithSend(10000); - serv.mainLoop(); - } catch (IOException e) { - e.printStackTrace(); - } - } - -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test/transfer/cluster/FDLServWithSendMeta.java Fri Feb 13 22:13:10 2009 +0900 @@ -0,0 +1,69 @@ +package fdl.test.transfer.cluster; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.net.*; + +import fdl.FDLindaServ; +import fdl.MetaLinda; + + +public class FDLServWithSendMeta extends FDLindaServ { + + public FDLServWithSendMeta(int port) throws IOException { + super(port); + } + + static String nextHost = null; + + @Override public void mainLoop() { + System.out.println("change mainloop"); + MetaLinda ml = new MetaLinda(tupleSpace, this); + mpe = new MetaProtocolEngine(ml, nextHost); + mpe.mainLoop(); + } + + public static void main(String[] args){ + try { + chkhost(); + FDLServWithSendMeta serv; + serv = new FDLServWithSendMeta(10000); + serv.mainLoop(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private static void chkhost() throws UnknownHostException{ + String localhost = null; + BufferedReader br = null; + String hostTable[] = new String[10]; + try { + br = new BufferedReader(new FileReader("nodelist")); + int i = 0; + while (br.ready()) { + String line = br.readLine(); + hostTable[i] = line; + i++; + } + 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]; + } + } + System.out.println("です"); + + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e){ + e.printStackTrace(); + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fdl/test/transfer/cluster/HostCheck.java Fri Feb 13 22:13:10 2009 +0900 @@ -0,0 +1,38 @@ +package fdl.test.transfer.cluster; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +//import java.net.*; + +public class HostCheck { + public static void main(String[] args) { +// String localhost = null; + BufferedReader br = null; + String hostTable[] = new String[10]; + try { + br = new BufferedReader(new FileReader("nodelist")); + int i = 0; + while (br.ready()) { + String line = br.readLine(); + hostTable[i] = line; + i++; + } + System.out.println("ホストは"); + for (int j=0; j<hostTable.length; j++){ + System.out.println(hostTable[j]); + } + System.out.println("です"); +// localhost = InetAddress.getLocalHost().getHostName(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e){ + e.printStackTrace(); + } +// if (localhost == hostTable[0]){ + ProtocolEngine pe = new ProtocolEngine(hostTable[0], hostTable[1]); + pe.start(); +// } + } +} \ No newline at end of file
--- a/src/fdl/test/transfer/cluster/MetaProtocolEngine.java Thu Feb 12 14:42:27 2009 +0900 +++ b/src/fdl/test/transfer/cluster/MetaProtocolEngine.java Fri Feb 13 22:13:10 2009 +0900 @@ -13,16 +13,16 @@ public class MetaProtocolEngine implements MetaEngine { private int id = 10; - private PSXLinda psx; - MetaLinda fdl1; + private PSXLinda psxget; + MetaLinda fdlmeta; String host; - int port1 = 10000; - private PSXLinda psx1; - private ByteBuffer data2 = ByteBuffer.allocate(10); + int port = 10000; + private PSXLinda psxsend; + private ByteBuffer data = ByteBuffer.allocate(10); public MetaProtocolEngine(MetaLinda ml, String host) { this.host = host; - this.fdl1 = ml; + this.fdlmeta = ml; } public void mainLoop(){ @@ -47,7 +47,7 @@ boolean connectpsx = true; while(connectpsx){ try { - psx = fdl1.open(host,port1); + psxsend = fdlmeta.open(host,port); connectpsx = false; } catch (IOException e) { try { @@ -57,8 +57,8 @@ } } } - System.out.println("Connect "+port1); - psx1 = fdl1; + System.out.println("Connect "+port); + psxget = fdlmeta; } private void sendData() throws IOException{ @@ -67,27 +67,27 @@ send.putInt(12); send.flip(); while(connectSend){ - psx.out(id, send); - psx.sync(1); - System.out.println("Send Data 10001"); + psxget.out(id, send); + psxget.sync(1); + System.out.println("Send Data"); connectSend = false; } } private void transfer() throws IOException { boolean running = true; - PSXReply in = psx.in(id); - System.out.println("PSXReply "+port1); + PSXReply in = psxget.in(id); + System.out.println("PSXReply "+port); while (running) { if(in.ready()){ - data2 = in.getData(); - int i = data2.getInt(); - data2.rewind(); + data = in.getData(); + int i = data.getInt(); + data.rewind(); //outしたbytebufferの変更をこれ以降やっちゃいけない - psx1.out(id,data2); + psxsend.out(id,data); - System.out.println("IntData0 "+port1 +i); - fdl1.sync(); + System.out.println("IntData0 "+port +i); + psxsend.sync(); running = false; break; }
--- a/src/fdl/test/transfer/cluster/ProtocolEngine.java Thu Feb 12 14:42:27 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -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); - fdl.sync(1); - 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(1); - 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/ProtocolEngineMain.java Fri Feb 13 22:13:10 2009 +0900 @@ -0,0 +1,69 @@ +package fdl.test.transfer.cluster; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.text.SimpleDateFormat; +import java.util.*; + +import fdl.FederatedLinda; +import fdl.PSXLinda; +import fdl.PSXReply; + +public class ProtocolEngineMain { + 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); + fdl.sync(1); + 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(1); + System.out.println("Transfer Data"); + break; + } + SimpleDateFormat DF = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS"); + System.out.println(DF.format(new Date())); + fdl.sync(); + } + + } catch (IOException e) { + e.printStackTrace(); + } + } + +}
--- a/src/fdl/test/transfer/cluster/Server.java Thu Feb 12 14:42:27 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -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/ServerMain.java Fri Feb 13 22:13:10 2009 +0900 @@ -0,0 +1,12 @@ +package fdl.test.transfer.cluster; + +import fdl.FDLindaServ; + +public class ServerMain{ + public static void main(String[] args){ + int port = 10000; + String[] args1 = {"-p",Integer.toString(port)}; + FDLindaServ.main(args1); + } + +} \ No newline at end of file