[freenet-cvs] r14952 - trunk/freenet/src/freenet/node/fcp

nextgens at freenetproject.org nextgens at freenetproject.org
Mon Sep 3 23:18:43 UTC 2007


Author: nextgens
Date: 2007-09-03 23:18:43 +0000 (Mon, 03 Sep 2007)
New Revision: 14952

Modified:
   trunk/freenet/src/freenet/node/fcp/AllDataMessage.java
   trunk/freenet/src/freenet/node/fcp/ClientGet.java
   trunk/freenet/src/freenet/node/fcp/ClientPutBase.java
   trunk/freenet/src/freenet/node/fcp/ClientRequest.java
   trunk/freenet/src/freenet/node/fcp/PutSuccessfulMessage.java
Log:
Improve the client layer: add both a start and a stop timestamp to requests; Export it on some FCP messages... maybe I forgot places where it would have been usefull (I didn't have the spec handy)

Modified: trunk/freenet/src/freenet/node/fcp/AllDataMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/AllDataMessage.java	2007-09-03 23:17:04 UTC (rev 14951)
+++ trunk/freenet/src/freenet/node/fcp/AllDataMessage.java	2007-09-03 23:18:43 UTC (rev 14952)
@@ -17,12 +17,15 @@
 	final long dataLength;
 	final boolean global;
 	final String identifier;
+	final String startupTime, completionTime;
 	
-	public AllDataMessage(Bucket bucket, String identifier, boolean global) {
+	public AllDataMessage(Bucket bucket, String identifier, boolean global, long startupTime, long completionTime) {
 		this.bucket = bucket;
 		this.dataLength = bucket.size();
 		this.identifier = identifier;
 		this.global = global;
+		this.startupTime = String.valueOf(startupTime);
+		this.completionTime = String.valueOf(completionTime);
 	}
 
 	long dataLength() {
@@ -34,6 +37,8 @@
 		fs.putSingle("DataLength", Long.toString(dataLength));
 		fs.putSingle("Identifier", identifier);
 		if(global) fs.putSingle("Global", "true");
+		fs.putSingle("StartuptTime", startupTime);
+		fs.putSingle("CompletionTime", completionTime);
 		return fs;
 	}
 

Modified: trunk/freenet/src/freenet/node/fcp/ClientGet.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientGet.java	2007-09-03 23:17:04 UTC (rev 14951)
+++ trunk/freenet/src/freenet/node/fcp/ClientGet.java	2007-09-03 23:18:43 UTC (rev 14952)
@@ -310,7 +310,7 @@
 		
 		if(finished){
 			if(succeeded) 
-				allDataPending = new AllDataMessage(returnBucket, identifier, global);
+				allDataPending = new AllDataMessage(returnBucket, identifier, global, startupTime, completionTime);
 			else
 				started = true;
 		}
@@ -384,7 +384,9 @@
 			if(returnType == ClientGetMessage.RETURN_TYPE_DIRECT) {
 				// Send all the data at once
 				// FIXME there should be other options
-				adm = new AllDataMessage(returnBucket, identifier, global);
+				// FIXME: CompletionTime is set on finish() : we need to give it current time here
+				// but it means we won't always return the same value to clients... Does it matter ?
+				adm = new AllDataMessage(returnBucket, identifier, global, startupTime, System.currentTimeMillis());
 				if(persistenceType == PERSIST_CONNECTION)
 					adm.setFreeOnSent();
 				dontFree = true;
@@ -594,6 +596,10 @@
 		}
 		fs.putSingle("Global", Boolean.toString(client.isGlobalQueue));
 		fs.put("BinaryBlob", binaryBlob);
+		fs.put("StartupTime", startupTime);
+		if(finished)
+			fs.put("CompletionTime", completionTime);
+
 		return fs;
 	}
 

Modified: trunk/freenet/src/freenet/node/fcp/ClientPutBase.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientPutBase.java	2007-09-03 23:17:04 UTC (rev 14951)
+++ trunk/freenet/src/freenet/node/fcp/ClientPutBase.java	2007-09-03 23:18:43 UTC (rev 14952)
@@ -221,7 +221,7 @@
 		FCPMessage msg;
 		synchronized (this) {
 			if(succeeded) {
-				msg = new PutSuccessfulMessage(identifier, global, generatedURI);
+				msg = new PutSuccessfulMessage(identifier, global, generatedURI, startupTime, completionTime);
 			} else {
 				msg = putFailedMessage;
 			}
@@ -306,6 +306,10 @@
 			// Should have a putFailedMessage... unless there is a race condition.
 			fs.put("PutFailed", putFailedMessage.getFieldSet(false));
 		fs.putSingle("Global", Boolean.toString(client.isGlobalQueue));
+		fs.put("StartupTime", startupTime);
+		if(finished)
+			fs.put("CompletionTime", completionTime);
+		
 		return fs;
 	}
 	

Modified: trunk/freenet/src/freenet/node/fcp/ClientRequest.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientRequest.java	2007-09-03 23:17:04 UTC (rev 14951)
+++ trunk/freenet/src/freenet/node/fcp/ClientRequest.java	2007-09-03 23:18:43 UTC (rev 14952)
@@ -37,6 +37,10 @@
 	protected String clientToken;
 	/** Is the request on the global queue? */
 	protected final boolean global;
+	/** Timestamp : startup time */
+	protected final long startupTime;
+	/** Timestamp : completion time */
+	protected long completionTime = Long.MAX_VALUE;
 
 	public ClientRequest(FreenetURI uri2, String identifier2, int verbosity2, FCPConnectionHandler handler, 
 			FCPClient client, short priorityClass2, short persistenceType2, String clientToken2, boolean global) {
@@ -56,6 +60,7 @@
 		else
 			origHandler = null;
 		this.client = client;
+		this.startupTime = System.currentTimeMillis();
 	}
 	
 	public ClientRequest(FreenetURI uri2, String identifier2, int verbosity2, FCPConnectionHandler handler, 
@@ -80,6 +85,7 @@
 		} else {
 			client = handler.getClient();
 		}
+		this.startupTime = System.currentTimeMillis();
 	}
 
 	public ClientRequest(SimpleFieldSet fs, FCPClient client2) throws MalformedURLException {
@@ -98,6 +104,11 @@
 		clientToken = fs.get("ClientToken");
 		finished = Fields.stringToBool(fs.get("Finished"), false);
 		global = Fields.stringToBool(fs.get("Global"), false);
+		final String stime = fs.get("StartupTime");
+		this.startupTime = stime == null ? System.currentTimeMillis() : Fields.parseLong(stime);
+		final String ctime = fs.get("CompletionTime");
+		if(ctime != null)
+			completionTime = Fields.parseLong(ctime);
 	}
 
 	/** Lost connection */
@@ -229,6 +240,7 @@
 
 	/** Request completed. But we may have to stick around until we are acked. */
 	protected void finish() {
+		completionTime = System.currentTimeMillis();
 		if(persistenceType == ClientRequest.PERSIST_CONNECTION)
 			origHandler.finishedClientRequest(this);
 		else

Modified: trunk/freenet/src/freenet/node/fcp/PutSuccessfulMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/PutSuccessfulMessage.java	2007-09-03 23:17:04 UTC (rev 14951)
+++ trunk/freenet/src/freenet/node/fcp/PutSuccessfulMessage.java	2007-09-03 23:18:43 UTC (rev 14952)
@@ -12,11 +12,14 @@
 	public final String identifier;
 	public final boolean global;
 	public final FreenetURI uri;
+	public final String startupTime, completionTime;
 	
-	public PutSuccessfulMessage(String identifier, boolean global, FreenetURI uri) {
+	public PutSuccessfulMessage(String identifier, boolean global, FreenetURI uri, long startupTime, long completionTime) {
 		this.identifier = identifier;
 		this.global = global;
 		this.uri = uri;
+		this.startupTime = String.valueOf(startupTime);
+		this.completionTime = String.valueOf(completionTime);
 	}
 
 	public SimpleFieldSet getFieldSet() {
@@ -26,6 +29,8 @@
 		// FIXME debug and remove!
 		if(uri != null)
 			fs.putSingle("URI", uri.toString());
+		fs.putSingle("StartuptTime", startupTime);
+		fs.putSingle("CompletionTime", completionTime);
 		return fs;
 	}
 




More information about the cvs mailing list