r26978 - trunk/freenet/src/freenet/client/async

[email protected] Sat, 18 Apr 2009 15:24:17 +0000
Newsgroups gmane.network.freenet.cvs
Message-ID <[email protected]>
Author: toad
Date: 2009-04-18 15:24:17 +0000 (Sat, 18 Apr 2009)
New Revision: 26978

Modified:
   trunk/freenet/src/freenet/client/async/USKFetcher.java
   trunk/freenet/src/freenet/client/async/USKManager.java
Log:
Call onFinished() when USKFetcher is finished, related bugfixes


Modified: trunk/freenet/src/freenet/client/async/USKFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/USKFetcher.java	2009-04-18 15:23:45 UTC (rev 26977)
+++ trunk/freenet/src/freenet/client/async/USKFetcher.java	2009-04-18 15:24:17 UTC (rev 26978)
@@ -309,6 +309,7 @@
 			schedule(end-now, null, context);
 		} else {
 			uskManager.unsubscribe(origUSK, this);
+			uskManager.onFinished(this);
 			long ed = uskManager.lookupLatestSlot(origUSK);
 			USKFetcherCallback[] cb;
 			synchronized(this) {
@@ -543,13 +544,13 @@
 		uskManager.unsubscribe(origUSK, this);
 		assert(container == null);
 		USKAttempt[] attempts;
+		uskManager.onFinished(this);
 		synchronized(this) {
 			cancelled = true;
 			attempts = runningAttempts.toArray(new USKAttempt[runningAttempts.size()]);
 		}
 		for(int i=0;i<attempts.length;i++)
 			attempts[i].cancel(container, context);
-		uskManager.onCancelled(this);
 	}
 
 	/** Set of interested USKCallbacks. Note that we don't actually

Modified: trunk/freenet/src/freenet/client/async/USKManager.java
===================================================================
--- trunk/freenet/src/freenet/client/async/USKManager.java	2009-04-18 15:23:45 UTC (rev 26977)
+++ trunk/freenet/src/freenet/client/async/USKManager.java	2009-04-18 15:24:17 UTC (rev 26978)
@@ -147,6 +147,7 @@
 			if(prefetchContent) {
 				final long min = lookupKnownGood(usk);
 				f.addCallback(new USKFetcherCallback() {
+					
 					public void onCancelled(ObjectContainer container, ClientContext context) {
 						// Ok
 					}
@@ -363,14 +364,14 @@
 			f = temporaryBackgroundFetchersLRU.get(clear);
 			if(f != null) {
 				f.removeCallback(cb);
-				if(f.isFinished() || !f.hasCallbacks()) {
+				if(!f.hasCallbacks()) {
 					if(toCancel != null) {
 						toCancelAlt = f;
 						Logger.error(this, "Subscribed in both backgroundFetchers and temporaryBackgroundFetchers???: "+cb+" for "+origUSK);
 					} else {
 						toCancel = f;
 					}
-						backgroundFetchersByClearUSK.remove(clear);
+						temporaryBackgroundFetchersLRU.removeKey(clear);
 				}
 			}
 			
@@ -427,14 +428,21 @@
 		return temporaryBackgroundFetchersLRU.size();
 	}
 
-	public void onCancelled(USKFetcher fetcher) {
-		USK clear = fetcher.getOriginalUSK().clearCopy();
+	public void onFinished(USKFetcher fetcher) {
+		USK orig = fetcher.getOriginalUSK();
+		USK clear = orig.clearCopy();
 		synchronized(this) {
 			if(backgroundFetchersByClearUSK.get(clear) == fetcher) {
 				backgroundFetchersByClearUSK.remove(clear);
 				// This shouldn't happen, it's a sanity check: the only way we get cancelled is from USKManager, which removes us before calling cancel().
 				Logger.error(this, "onCancelled for "+fetcher+" - was still registered, how did this happen??", new Exception("debug"));
 			}
+			if(temporaryBackgroundFetchersLRU.get(clear) == fetcher) {
+				temporaryBackgroundFetchersLRU.removeKey(clear);
+			}
+			if(fetchersByUSK.get(orig) == fetcher) {
+				fetchersByUSK.remove(clear);
+			}
 		}
 	}