Author: toad
Date: 2008-04-29 17:15:53 +0000 (Tue, 29 Apr 2008)
New Revision: 19614

Modified:
   trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
   trunk/freenet/src/freenet/client/async/USKCallback.java
   trunk/freenet/src/freenet/client/async/USKFetcher.java
   trunk/freenet/src/freenet/client/async/USKInserter.java
   trunk/freenet/src/freenet/client/async/USKRetriever.java
   trunk/freenet/src/freenet/client/async/USKRetrieverCallback.java
   trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java
   trunk/freenet/src/freenet/node/PeerNode.java
   trunk/freenet/src/freenet/node/fcp/SubscribeUSK.java
   trunk/freenet/src/freenet/node/updater/NodeUpdater.java
   trunk/plugins/XMLSpider/XMLSpider.java
Log:
Add callbacks to determine what priority to run USK fetches at.
Bookmark polling, polling a site we've just visited, run at low priority.
ARK fetches run fairly high. Etc.

Modified: trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SingleFileFetcher.java       
2008-04-29 16:45:25 UTC (rev 19613)
+++ trunk/freenet/src/freenet/client/async/SingleFileFetcher.java       
2008-04-29 17:15:53 UTC (rev 19614)
@@ -795,6 +795,14 @@
                        cb.onFailure(new 
FetchException(FetchException.CANCELLED, (String)null), null);
                }

+               public short getPollingPriorityNormal() {
+                       return parent.getPriorityClass();
+               }
+
+               public short getPollingPriorityProgress() {
+                       return parent.getPriorityClass();
+               }
+
        }

 }

Modified: trunk/freenet/src/freenet/client/async/USKCallback.java
===================================================================
--- trunk/freenet/src/freenet/client/async/USKCallback.java     2008-04-29 
16:45:25 UTC (rev 19613)
+++ trunk/freenet/src/freenet/client/async/USKCallback.java     2008-04-29 
17:15:53 UTC (rev 19614)
@@ -16,4 +16,14 @@
         * @param key The key. */
        void onFoundEdition(long l, USK key);

+       /**
+        * Priority at which the polling should run normally.
+        */
+       short getPollingPriorityNormal();
+       
+       /**
+        * Priority at which the polling should run when starting, or 
immediately after making some progress.
+        */
+       short getPollingPriorityProgress();
+       
 }

Modified: trunk/freenet/src/freenet/client/async/USKFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/USKFetcher.java      2008-04-29 
16:45:25 UTC (rev 19613)
+++ trunk/freenet/src/freenet/client/async/USKFetcher.java      2008-04-29 
17:15:53 UTC (rev 19614)
@@ -165,9 +165,9 @@
                        if(backgroundPoll) {
                                if(minFailures == origMinFailures && 
minFailures != maxMinFailures) {
                                        // Either just started, or just 
advanced, either way boost the priority.
-                                       return 
RequestStarter.UPDATE_PRIORITY_CLASS;
+                                       return progressPollPriority;
                                } else {
-                                       return 
RequestStarter.PREFETCH_PRIORITY_CLASS;
+                                       return normalPollPriority;
                                }
                        } else
                                return parent.getPriorityClass();
@@ -201,6 +201,11 @@
        final boolean keepLastData;

        private boolean started;
+       
+       private static short DEFAULT_NORMAL_POLL_PRIORITY = 
RequestStarter.PREFETCH_PRIORITY_CLASS;
+       private short normalPollPriority = DEFAULT_NORMAL_POLL_PRIORITY;
+       private static short DEFAULT_PROGRESS_POLL_PRIORITY = 
RequestStarter.UPDATE_PRIORITY_CLASS;
+       private short progressPollPriority = DEFAULT_PROGRESS_POLL_PRIORITY;

        USKFetcher(USK origUSK, USKManager manager, FetchContext ctx, 
ClientRequester requester, int minFailures, boolean pollForever, boolean 
keepLastData) {
                this(origUSK, manager, ctx, requester, minFailures, 
pollForever, DEFAULT_MAX_MIN_FAILURES, keepLastData);
@@ -492,20 +497,52 @@
         */
        final HashSet subscribers;

-       public synchronized void addSubscriber(USKCallback cb) {
-               subscribers.add(cb);
+       public void addSubscriber(USKCallback cb) {
+               synchronized(this) {
+                       subscribers.add(cb);
+               }
+               updatePriorities();
        }

+       private void updatePriorities() {
+               // FIXME should this be synchronized? IMHO it doesn't matter 
that much if we get the priority
+               // wrong for a few requests... also, we avoid any possible 
deadlock this way if the callbacks
+               // take locks...
+               short normalPrio = RequestStarter.MINIMUM_PRIORITY_CLASS;
+               short progressPrio = RequestStarter.MINIMUM_PRIORITY_CLASS;
+               USKCallback[] callbacks;
+               synchronized(this) {
+                       callbacks = (USKCallback[]) subscribers.toArray(new 
USKCallback[subscribers.size()]);
+               }
+               if(callbacks.length == 0) {
+                       normalPollPriority = DEFAULT_NORMAL_POLL_PRIORITY;
+                       progressPollPriority = DEFAULT_PROGRESS_POLL_PRIORITY;
+                       return;
+               }
+               
+               for(int i=0;i<callbacks.length;i++) {
+                       USKCallback cb = callbacks[i];
+                       short prio = cb.getPollingPriorityNormal();
+                       if(prio < normalPrio) normalPrio = prio;
+                       prio = cb.getPollingPriorityProgress();
+                       if(prio < progressPrio) progressPrio = prio;
+               }
+               normalPollPriority = normalPrio;
+               progressPollPriority = progressPrio;
+       }
+
        public synchronized boolean hasSubscribers() {
                return !subscribers.isEmpty();
        }

        public void removeSubscriber(USKCallback cb) {
+               boolean kill = false;
                synchronized(this) {
                        subscribers.remove(cb);
-                       if(!(subscribers.isEmpty() && killOnLoseSubscribers)) 
return;
+                       if(!(subscribers.isEmpty() && killOnLoseSubscribers)) 
kill = true;
                }
-               cancel();
+               updatePriorities();
+               if(kill) cancel();
        }

        public synchronized boolean hasLastData() {

Modified: trunk/freenet/src/freenet/client/async/USKInserter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/USKInserter.java     2008-04-29 
16:45:25 UTC (rev 19613)
+++ trunk/freenet/src/freenet/client/async/USKInserter.java     2008-04-29 
17:15:53 UTC (rev 19614)
@@ -242,4 +242,12 @@
                // Ignore
        }

+       public short getPollingPriorityNormal() {
+               return parent.getPriorityClass();
+       }
+
+       public short getPollingPriorityProgress() {
+               return parent.getPriorityClass();
+       }
+
 }

Modified: trunk/freenet/src/freenet/client/async/USKRetriever.java
===================================================================
--- trunk/freenet/src/freenet/client/async/USKRetriever.java    2008-04-29 
16:45:25 UTC (rev 19613)
+++ trunk/freenet/src/freenet/client/async/USKRetriever.java    2008-04-29 
17:15:53 UTC (rev 19614)
@@ -94,4 +94,12 @@
                // Ignore
        }

+       public short getPollingPriorityNormal() {
+               return cb.getPollingPriorityNormal();
+       }
+
+       public short getPollingPriorityProgress() {
+               return cb.getPollingPriorityProgress();
+       }
+
 }

Modified: trunk/freenet/src/freenet/client/async/USKRetrieverCallback.java
===================================================================
--- trunk/freenet/src/freenet/client/async/USKRetrieverCallback.java    
2008-04-29 16:45:25 UTC (rev 19613)
+++ trunk/freenet/src/freenet/client/async/USKRetrieverCallback.java    
2008-04-29 17:15:53 UTC (rev 19614)
@@ -17,4 +17,14 @@
         */
        void onFound(long edition, FetchResult data);

+       /**
+        * Priority at which the polling should run normally.
+        */
+       short getPollingPriorityNormal();
+
+       /**
+        * Priority at which the polling should run when starting, or 
immediately after making some progress.
+        */
+       short getPollingPriorityProgress();
+
 }

Modified: trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java        
2008-04-29 16:45:25 UTC (rev 19613)
+++ trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java        
2008-04-29 17:15:53 UTC (rev 19614)
@@ -16,6 +16,7 @@
 import freenet.l10n.L10n;
 import freenet.node.FSParseException;
 import freenet.node.NodeClientCore;
+import freenet.node.RequestStarter;
 import freenet.support.Logger;
 import freenet.support.SimpleFieldSet;
 import freenet.support.io.Closer;
@@ -108,6 +109,14 @@
                        }
                        storeBookmarks();
                }
+
+               public short getPollingPriorityNormal() {
+                       return RequestStarter.PREFETCH_PRIORITY_CLASS;
+               }
+
+               public short getPollingPriorityProgress() {
+                       return RequestStarter.UPDATE_PRIORITY_CLASS;
+               }
        }

        public String l10n(String key) {

Modified: trunk/freenet/src/freenet/node/PeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNode.java        2008-04-29 16:45:25 UTC 
(rev 19613)
+++ trunk/freenet/src/freenet/node/PeerNode.java        2008-04-29 17:15:53 UTC 
(rev 19614)
@@ -2006,6 +2006,16 @@
                        arkFetcher = null;
                }
        }
+       
+
+       public short getPollingPriorityNormal() {
+               return RequestStarter.IMMEDIATE_SPLITFILE_PRIORITY_CLASS;
+       }
+
+       public short getPollingPriorityProgress() {
+               return RequestStarter.INTERACTIVE_PRIORITY_CLASS;
+       }
+       
        boolean sentInitialMessages;

        void maybeSendInitialMessages() {

Modified: trunk/freenet/src/freenet/node/fcp/SubscribeUSK.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/SubscribeUSK.java        2008-04-29 
16:45:25 UTC (rev 19613)
+++ trunk/freenet/src/freenet/node/fcp/SubscribeUSK.java        2008-04-29 
17:15:53 UTC (rev 19614)
@@ -6,9 +6,11 @@
 import freenet.client.async.USKCallback;
 import freenet.keys.USK;
 import freenet.node.NodeClientCore;
+import freenet.node.RequestStarter;

 public class SubscribeUSK implements USKCallback {

+       // FIXME allow client to specify priorities
        final FCPConnectionHandler handler;
        final String identifier;
        final NodeClientCore core;
@@ -31,4 +33,12 @@
                handler.outputHandler.queue(msg);
        }

+       public short getPollingPriorityNormal() {
+               return RequestStarter.BULK_SPLITFILE_PRIORITY_CLASS;
+       }
+
+       public short getPollingPriorityProgress() {
+               return RequestStarter.UPDATE_PRIORITY_CLASS;
+       }
+
 }

Modified: trunk/freenet/src/freenet/node/updater/NodeUpdater.java
===================================================================
--- trunk/freenet/src/freenet/node/updater/NodeUpdater.java     2008-04-29 
16:45:25 UTC (rev 19613)
+++ trunk/freenet/src/freenet/node/updater/NodeUpdater.java     2008-04-29 
17:15:53 UTC (rev 19614)
@@ -341,4 +341,12 @@
        public File getBlobFile() {
                return getBlobFile(getFetchedVersion());
        }
+
+       public short getPollingPriorityNormal() {
+               return RequestStarter.UPDATE_PRIORITY_CLASS;
+       }
+
+       public short getPollingPriorityProgress() {
+               return RequestStarter.IMMEDIATE_SPLITFILE_PRIORITY_CLASS;
+       }
 }

Modified: trunk/plugins/XMLSpider/XMLSpider.java
===================================================================
--- trunk/plugins/XMLSpider/XMLSpider.java      2008-04-29 16:45:25 UTC (rev 
19613)
+++ trunk/plugins/XMLSpider/XMLSpider.java      2008-04-29 17:15:53 UTC (rev 
19614)
@@ -1335,4 +1335,12 @@
                queueURI(uri);
        }

+       public short getPollingPriorityNormal() {
+               return (short) Math.min(RequestStarter.MINIMUM_PRIORITY_CLASS, 
PRIORITY_CLASS + 1);
+       }
+
+       public short getPollingPriorityProgress() {
+               return PRIORITY_CLASS;
+       }
+
 }


Reply via email to