changeset 60:673085a02ccb

OutPut Result Time
author axmo
date Tue, 17 Feb 2009 23:28:58 +0900
parents a372992d0ac2
children def989051b0c
files src/fdl/test/transfer/cluster/FDLServWithSendMeta.java src/fdl/test/transfer/cluster/MetaProtocolEngine.java
diffstat 2 files changed, 73 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/fdl/test/transfer/cluster/FDLServWithSendMeta.java	Tue Feb 17 17:24:37 2009 +0900
+++ b/src/fdl/test/transfer/cluster/FDLServWithSendMeta.java	Tue Feb 17 23:28:58 2009 +0900
@@ -5,7 +5,6 @@
 import java.io.FileReader;
 import java.io.IOException;
 import java.net.*;
-import java.util.Arrays;
 
 import fdl.FDLindaServ;
 import fdl.MetaLinda;
@@ -20,15 +19,25 @@
 	static String nextHost = null;
 	private static int localport = 10000;
 	static int chknum;
+	private static String bufstring;
+	private static int bufsize;
 	
 	
 	@Override public void mainLoop() {
 		MetaLinda ml = new MetaLinda(tupleSpace, this);
-		mpe = new MetaProtocolEngine(ml, nextHost, chknum);
+		mpe = new MetaProtocolEngine(ml, nextHost, chknum, bufsize);
 		mpe.mainLoop();
 	}
 	
 	public static void main(String[] args){
+		for (int k=0; k<args.length; ++k) {
+			if("-bufsize".equals(args[k])){
+				bufstring = args[++k];
+			} else {
+	        System.err.println("引数指定の誤り:未知の引数が指定されました");
+            }
+		}
+		bufsize = Integer.parseInt(bufstring);
 		try {
 			chkhost();
 			FDLServWithSendMeta serv;
@@ -51,7 +60,6 @@
 				hostTable[i] = line;
 				i++;
 			}
-			Arrays.sort(hostTable);
 			localhost = InetAddress.getLocalHost().getHostName();
 			for (int j=0; j<hostTable.length; j++) {
 				if(localhost.equals(hostTable[j])){
@@ -67,7 +75,7 @@
 			}
 				
 			System.out.println("localhost:"+localhost);
-			System.out.println("nexthost"+nextHost);
+			System.out.println("nexthost:"+nextHost);
 		
 		} catch (FileNotFoundException e) {
 			e.printStackTrace();
--- a/src/fdl/test/transfer/cluster/MetaProtocolEngine.java	Tue Feb 17 17:24:37 2009 +0900
+++ b/src/fdl/test/transfer/cluster/MetaProtocolEngine.java	Tue Feb 17 23:28:58 2009 +0900
@@ -1,13 +1,13 @@
 package fdl.test.transfer.cluster;
 
-import java.io.IOException;
+import java.io.*;
+import java.net.InetAddress;
 import java.nio.ByteBuffer;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
 
 import fdl.MetaEngine;
-
 import fdl.MetaLinda;
 import fdl.PSXLinda;
 import fdl.PSXReply;
@@ -20,13 +20,22 @@
 	String host;
 	int port = 10000;
 	private PSXLinda psxsend;
-	private ByteBuffer data = ByteBuffer.allocate(10);
 	private int chknum;
 	
-	public MetaProtocolEngine(MetaLinda ml, String host, int chknum) {
+	SimpleDateFormat DF = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");
+
+	private int bufsize;
+
+	private String time;
+	private String start;
+
+	private String transfer;
+	
+	public MetaProtocolEngine(MetaLinda ml, String host, int chknum, int bufsize) {
 		this.host = host;
 		this.fdlmeta = ml;
 		this.chknum = chknum;
+		this.bufsize = bufsize;
 	}
 
 	public void mainLoop(){
@@ -34,6 +43,8 @@
 		if(chknum == 1){
 			try {
 				sendData();
+				start = DF.format(new Date());
+				System.out.println("Start Time => "+start);
 			} catch (IOException e) {
 				e.printStackTrace();
 			}
@@ -43,6 +54,8 @@
 		try {
 			initConnect();
 			transfer();
+			dataChk();
+			write();
 			connect = false;
 		} catch (IOException e) {
 			try {
@@ -71,8 +84,9 @@
 	
 	private void sendData() throws IOException{
 		boolean connectSend = true;
-		ByteBuffer send = ByteBuffer.allocate(1024);
-		send.putInt(12);
+		ByteBuffer send = ByteBuffer.allocate(bufsize);
+		int localhost = InetAddress.getLocalHost().hashCode();
+		send.putInt(localhost);
 		send.flip();
 		while(connectSend){
 		psxget.out(id, send);
@@ -82,7 +96,8 @@
 		}
 	}
 
-	private void transfer() throws IOException {
+	public void transfer() throws IOException {
+		ByteBuffer data = ByteBuffer.allocate(bufsize);
 		boolean running = true;
 		PSXReply in = psxget.in(id);
 		while (running) {
@@ -93,17 +108,52 @@
 				System.out.println("transfer Data => "+i);
 				//outしたbytebufferの変更をこれ以降やっちゃいけない
 				psxsend.out(id,data);
-				SimpleDateFormat DF = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");
-				System.out.println(DF.format(new Date()));
+				transfer = DF.format(new Date());
+				System.out.println("transfer Time => "+transfer);
 				System.out.println("connect to => "+host);
-				psxsend.sync();
+				psxsend.sync(1);
 				running = false;
 				break;
 			}
 			fdlmeta.sync();
 		}
 	}
-
 	
+	public void dataChk() throws IOException{
+		fdlmeta.sync(1);
+		boolean running2 = true;
+		ByteBuffer data2 = ByteBuffer.allocate(bufsize);
+		PSXReply in2 = psxget.in(id);
+		int localhost2 = InetAddress.getLocalHost().hashCode();
+		while (running2) {
+			psxget.sync(1);
+			if(in2.ready()) {
+			data2 = in2.getData();
+			int i = data2.getInt();
+			if (i == localhost2){
+				time = DF.format(new Date());
+				System.out.println("Around Time => "+time);
+			}
+			running2 = false;
+			break;
+			}
+		}
+	}
+	
+	
+	public void write() throws IOException{
+		File read = new File("resultTime.txt");
+		FileWriter filewrite = new FileWriter(read);
+		if (start != "null"){
+		filewrite.write("ServerStart => "+start+"\r\n");
+		}
+		if (transfer != "null") {
+		filewrite.write("TransferTime => "+transfer+"\r\n");
+		}
+		if (time != "null"){
+		filewrite.write("AroundTime => "+time+"\r\n");
+		}
+		filewrite.close();
+	}
 }