[freenet-cvs] r13106 - trunk/freenet/src/freenet/client/async

toad at freenetproject.org toad at freenetproject.org
Wed May 2 18:10:00 UTC 2007


Author: toad
Date: 2007-05-02 18:10:00 +0000 (Wed, 02 May 2007)
New Revision: 13106

Modified:
   trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java
   trunk/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java
Log:
Remove the sub-segment when we are done with it, not before.

Modified: trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java	2007-05-02 18:09:18 UTC (rev 13105)
+++ trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java	2007-05-02 18:10:00 UTC (rev 13106)
@@ -140,7 +140,7 @@
 		return fatallyFailedBlocks;
 	}
 
-	public void onSuccess(Bucket data, int blockNo, boolean dontNotify) {
+	public void onSuccess(Bucket data, int blockNo, boolean dontNotify, SplitFileFetcherSubSegment seg) {
 		boolean decodeNow = false;
 		logMINOR = Logger.shouldLog(Logger.MINOR, this);
 		synchronized(this) {
@@ -175,6 +175,7 @@
 			}
 		}
 		parentFetcher.parent.completedBlock(dontNotify);
+		seg.possiblyRemoveFromParent();
 		if(decodeNow) {
 			decode();
 		}
@@ -271,9 +272,10 @@
 	}
 	
 	/** This is after any retries and therefore is either out-of-retries or fatal */
-	public synchronized void onFatalFailure(FetchException e, int blockNo) {
+	public synchronized void onFatalFailure(FetchException e, int blockNo, SplitFileFetcherSubSegment seg) {
 		logMINOR = Logger.shouldLog(Logger.MINOR, this);
 		if(logMINOR) Logger.minor(this, "Permanently failed block: "+blockNo+" on "+this+" : "+e, e);
+		boolean allFailed;
 		synchronized(this) {
 			if(isFinishing()) return; // this failure is now irrelevant, and cleanup will occur on the decoder thread
 			if(blockNo < dataKeys.length) {
@@ -298,14 +300,15 @@
 				failedBlocks++;
 				parentFetcher.parent.failedBlock();
 			}
-			if(failedBlocks + fatallyFailedBlocks <= (dataKeys.length + checkKeys.length - minFetched))
-				return;
+			allFailed = failedBlocks + fatallyFailedBlocks <= (dataKeys.length + checkKeys.length - minFetched);
 		}
-		fail(new FetchException(FetchException.SPLITFILE_ERROR, errors));
+		if(allFailed)
+			fail(new FetchException(FetchException.SPLITFILE_ERROR, errors));
+		seg.possiblyRemoveFromParent();
 	}
 	
 	/** A request has failed non-fatally, so the block may be retried */
-	public void onNonFatalFailure(FetchException e, int blockNo) {
+	public void onNonFatalFailure(FetchException e, int blockNo, SplitFileFetcherSubSegment seg) {
 		int tries;
 		int maxTries = blockFetchContext.maxNonSplitfileRetries;
 		synchronized(this) {
@@ -313,13 +316,13 @@
 			if(blockNo < dataKeys.length) {
 				tries = ++dataRetries[blockNo];
 				if(tries > maxTries && maxTries >= 0) {
-					onFatalFailure(e, blockNo);
+					onFatalFailure(e, blockNo, seg);
 					return;
 				}
 			} else {
 				tries = ++checkRetries[blockNo-dataKeys.length];
 				if(tries > maxTries && maxTries >= 0) {
-					onFatalFailure(e, blockNo);
+					onFatalFailure(e, blockNo, seg);
 					return;
 				}
 			}

Modified: trunk/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java	2007-05-02 18:09:18 UTC (rev 13105)
+++ trunk/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java	2007-05-02 18:10:00 UTC (rev 13106)
@@ -135,9 +135,9 @@
 		}
 		segment.errors.inc(e.getMode());
 		if(e.isFatal() || forceFatal) {
-			segment.onFatalFailure(e, token);
+			segment.onFatalFailure(e, token, this);
 		} else {
-			segment.onNonFatalFailure(e, token);
+			segment.onNonFatalFailure(e, token, this);
 		}
 	}
 	
@@ -170,7 +170,7 @@
 			onFailure(new FetchException(FetchException.CANCELLED), blockNo);
 			return;
 		}
-		segment.onSuccess(data, blockNo, fromStore);
+		segment.onSuccess(data, blockNo, fromStore, this);
 	}
 
 	/** Convert a ClientKeyBlock to a Bucket. If an error occurs, report it via onFailure
@@ -252,5 +252,10 @@
 	public String toString() {
 		return super.toString()+":"+retryCount+"/"+segment;
 	}
+
+	public synchronized void possiblyRemoveFromParent() {
+		if(blockNums.isEmpty())
+			segment.removeSeg(this);
+	}
 	
 }




More information about the cvs mailing list