Author: toad
Date: 2009-04-18 14:15:17 +0000 (Sat, 18 Apr 2009)
New Revision: 26973

Modified:
   trunk/freenet/src/freenet/client/async/USKFetcher.java
   trunk/freenet/src/freenet/client/async/USKManager.java
   trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java
   trunk/freenet/src/freenet/node/fcp/SubscribeUSK.java
   trunk/freenet/src/freenet/node/updater/NodeUpdater.java
Log:
Remove last parameter from unsubscribe, and fix unsubscribe


Modified: trunk/freenet/src/freenet/client/async/USKFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/USKFetcher.java      2009-04-18 
14:07:54 UTC (rev 26972)
+++ trunk/freenet/src/freenet/client/async/USKFetcher.java      2009-04-18 
14:15:17 UTC (rev 26973)
@@ -308,7 +308,7 @@
                        }
                        schedule(end-now, null, context);
                } else {
-                       uskManager.unsubscribe(origUSK, this, false);
+                       uskManager.unsubscribe(origUSK, this);
                        long ed = uskManager.lookupLatestSlot(origUSK);
                        USKFetcherCallback[] cb;
                        synchronized(this) {
@@ -540,7 +540,7 @@
        }
 
        public void cancel(ObjectContainer container, ClientContext context) {
-               uskManager.unsubscribe(origUSK, this, false);
+               uskManager.unsubscribe(origUSK, this);
                assert(container == null);
                USKAttempt[] attempts;
                synchronized(this) {
@@ -608,6 +608,10 @@
                return !subscribers.isEmpty();
        }
        
+       public synchronized boolean hasCallbacks() {
+               return !callbacks.isEmpty();
+       }
+       
        public void removeSubscriber(USKCallback cb, ClientContext context) {
                synchronized(this) {
                        subscribers.remove(cb);
@@ -615,6 +619,12 @@
                updatePriorities();
        }
 
+       public void removeCallback(USKCallback cb) {
+               synchronized(this) {
+                       subscribers.remove(cb);
+               }
+       }
+
        public synchronized boolean hasLastData() {
                return this.lastRequestData != null;
        }

Modified: trunk/freenet/src/freenet/client/async/USKManager.java
===================================================================
--- trunk/freenet/src/freenet/client/async/USKManager.java      2009-04-18 
14:07:54 UTC (rev 26972)
+++ trunk/freenet/src/freenet/client/async/USKManager.java      2009-04-18 
14:15:17 UTC (rev 26973)
@@ -325,8 +325,9 @@
                }
        }
        
-       public void unsubscribe(USK origUSK, USKCallback cb, boolean 
runBackgroundFetch) {
+       public void unsubscribe(USK origUSK, USKCallback cb) {
                USKFetcher toCancel = null;
+               USKFetcher toCancelAlt = null;
                synchronized(this) {
                        USK clear = origUSK.clearCopy();
                        USKCallback[] callbacks = 
subscribersByClearUSK.get(clear);
@@ -349,23 +350,41 @@
                                subscribersByClearUSK.remove(clear);
                                fetchersByUSK.remove(origUSK);
                        }
-                       if(runBackgroundFetch) {
-                               USKFetcher f = 
backgroundFetchersByClearUSK.get(clear);
-                               if(f == null) {
-                                       if(newCallbacks.length == 0)
-                                               Logger.minor(this, 
"Unsubscribing "+cb+" for "+origUSK+" but not already subscribed. No 
callbacks.", new Exception("debug"));
-                                       else
-                                               Logger.error(this, 
"Unsubscribing "+cb+" for "+origUSK+" but not already subscribed, remaining 
"+newCallbacks.length+" callbacks", new Exception("error"));
-                               } else {
-                                       f.removeSubscriber(cb, context);
-                                       if(!f.hasSubscribers()) {
-                                                       toCancel = f;
-                                                       
backgroundFetchersByClearUSK.remove(clear);
+                       USKFetcher f = backgroundFetchersByClearUSK.get(clear);
+                       if(f == null) {
+                               if(newCallbacks.length == 0)
+                                       Logger.minor(this, "Unsubscribing 
"+cb+" for "+origUSK+" but not already subscribed. No callbacks.", new 
Exception("debug"));
+                               else
+                                       Logger.error(this, "Unsubscribing 
"+cb+" for "+origUSK+" but not already subscribed, remaining 
"+newCallbacks.length+" callbacks", new Exception("error"));
+                       } else {
+                               f.removeSubscriber(cb, context);
+                               if(!f.hasSubscribers()) {
+                                               toCancel = f;
+                                               
backgroundFetchersByClearUSK.remove(clear);
+                               }
+                       }
+                       f = temporaryBackgroundFetchersLRU.get(clear);
+                       if(f == null) {
+                               if(newCallbacks.length == 0)
+                                       Logger.minor(this, "Unsubscribing 
"+cb+" for "+origUSK+" but not already subscribed. No callbacks.", new 
Exception("debug"));
+                               else
+                                       Logger.error(this, "Unsubscribing 
"+cb+" for "+origUSK+" but not already subscribed, remaining 
"+newCallbacks.length+" callbacks", new Exception("error"));
+                       } else {
+                               f.removeCallback(cb);
+                               if(f.isFinished() || !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);
                                }
                        }
+                       
                }
                if(toCancel != null) toCancel.cancel(null, context);
+               if(toCancelAlt != null) toCancelAlt.cancel(null, context);
        }
        
        /**
@@ -385,7 +404,7 @@
        }
        
        public void unsubscribeContent(USK origUSK, USKRetriever ret, boolean 
runBackgroundFetch) {
-               unsubscribe(origUSK, ret, runBackgroundFetch);
+               unsubscribe(origUSK, ret);
        }
        
        // REMOVE: DO NOT Synchronize! ... debugging only.

Modified: trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java        
2009-04-18 14:07:54 UTC (rev 26972)
+++ trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java        
2009-04-18 14:15:17 UTC (rev 26973)
@@ -212,7 +212,7 @@
                        if(((BookmarkItem) bookmark).getKeyType().equals("USK"))
                                try {
                                        USK u = ((BookmarkItem) 
bookmark).getUSK();
-                                       this.node.uskManager.unsubscribe(u, 
this.uskCB, true);
+                                       this.node.uskManager.unsubscribe(u, 
this.uskCB);
                                } catch(MalformedURLException mue) {
                                }
 

Modified: trunk/freenet/src/freenet/node/fcp/SubscribeUSK.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/SubscribeUSK.java        2009-04-18 
14:07:54 UTC (rev 26972)
+++ trunk/freenet/src/freenet/node/fcp/SubscribeUSK.java        2009-04-18 
14:15:17 UTC (rev 26973)
@@ -32,7 +32,7 @@
 
        public void onFoundEdition(long l, USK key, ObjectContainer container, 
ClientContext context, boolean wasMetadata, short codec, byte[] data, boolean 
newKnownGood, boolean newSlotToo) {
                if(handler.isClosed()) {
-                       core.uskManager.unsubscribe(key, this, !dontPoll);
+                       core.uskManager.unsubscribe(key, this);
                        return;
                }
                //if(newKnownGood && !newSlotToo) return;

Modified: trunk/freenet/src/freenet/node/updater/NodeUpdater.java
===================================================================
--- trunk/freenet/src/freenet/node/updater/NodeUpdater.java     2009-04-18 
14:07:54 UTC (rev 26972)
+++ trunk/freenet/src/freenet/node/updater/NodeUpdater.java     2009-04-18 
14:15:17 UTC (rev 26973)
@@ -407,7 +407,7 @@
                        synchronized(this) {
                                isRunning = false;
                                USK myUsk = 
USK.create(URI.setSuggestedEdition(currentVersion));
-                               core.uskManager.unsubscribe(myUsk, this, true);
+                               core.uskManager.unsubscribe(myUsk, this);
                                c = cg;
                                cg = null;
                        }

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to