Author: toad
Date: 2008-06-13 12:43:42 +0000 (Fri, 13 Jun 2008)
New Revision: 20298

Modified:
   branches/db4o/freenet/src/freenet/client/async/ChosenRequest.java
   
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
   branches/db4o/freenet/src/freenet/client/async/PersistentChosenRequest.java
   branches/db4o/freenet/src/freenet/node/RequestStarter.java
   branches/db4o/freenet/src/freenet/node/SendableGet.java
   branches/db4o/freenet/src/freenet/node/SendableRequest.java
Log:
Pass in the ClientKey via ChosenRequest (only for SendableGet's).
Hence we don't need to look it up on the requestor thread.

Modified: branches/db4o/freenet/src/freenet/client/async/ChosenRequest.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/ChosenRequest.java   
2008-06-13 12:35:28 UTC (rev 20297)
+++ branches/db4o/freenet/src/freenet/client/async/ChosenRequest.java   
2008-06-13 12:43:42 UTC (rev 20298)
@@ -3,6 +3,7 @@
  * http://www.gnu.org/ for further details of the GPL. */
 package freenet.client.async;

+import freenet.keys.ClientKey;
 import freenet.keys.Key;
 import freenet.node.SendableRequest;

@@ -19,11 +20,14 @@
        public final Object token;
        /** The key to be fetched, null if not a BaseSendableGet */
        public final Key key;
+       /** The client-layer key to be fetched, null if not a SendableGet */
+       public final ClientKey ckey;

-       ChosenRequest(SendableRequest req, Object tok, Key key) {
+       ChosenRequest(SendableRequest req, Object tok, Key key, ClientKey ckey) 
{
                request = req;
                token = tok;
                this.key = key;
+               this.ckey = ckey;
        }

 }

Modified: 
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
===================================================================
--- 
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java  
    2008-06-13 12:35:28 UTC (rev 20297)
+++ 
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java  
    2008-06-13 12:43:42 UTC (rev 20298)
@@ -184,16 +184,23 @@
                        return null;
                } else {
                        Key key;
-                       if(isInsertScheduler)
+                       ClientKey ckey;
+                       if(isInsertScheduler) {
                                key = null;
-                       else
+                               ckey = null;
+                       } else {
                                key = ((BaseSendableGet)req).getNodeKey(token, 
persistent() ? container : null);
+                               if(req instanceof SendableGet)
+                                       ckey = 
((SendableGet)req).getClientKey(token, persistent() ? container : null);
+                               else
+                                       ckey = null;
+                       }
                        ChosenRequest ret;
                        if(req.persistent()) {
-                               ret = new PersistentChosenRequest(this, req, 
token, key);
+                               ret = new PersistentChosenRequest(this, req, 
token, key, ckey);
                                container.set(ret);
                        } else {
-                               ret = new ChosenRequest(req, token, key);
+                               ret = new ChosenRequest(req, token, key, ckey);
                        }
                        if(key != null)
                                keysFetching.add(key);

Modified: 
branches/db4o/freenet/src/freenet/client/async/PersistentChosenRequest.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/PersistentChosenRequest.java 
2008-06-13 12:35:28 UTC (rev 20297)
+++ branches/db4o/freenet/src/freenet/client/async/PersistentChosenRequest.java 
2008-06-13 12:43:42 UTC (rev 20298)
@@ -3,6 +3,7 @@
  * http://www.gnu.org/ for further details of the GPL. */
 package freenet.client.async;

+import freenet.keys.ClientKey;
 import freenet.keys.Key;
 import freenet.node.SendableRequest;

@@ -21,8 +22,8 @@

        ClientRequestSchedulerCore core;

-       PersistentChosenRequest(ClientRequestSchedulerCore core, 
SendableRequest req, Object tok, Key key) {
-               super(req, tok, key);
+       PersistentChosenRequest(ClientRequestSchedulerCore core, 
SendableRequest req, Object tok, Key key, ClientKey ckey) {
+               super(req, tok, key, ckey);
                this.core = core;
        }
 }

Modified: branches/db4o/freenet/src/freenet/node/RequestStarter.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/RequestStarter.java  2008-06-13 
12:35:28 UTC (rev 20297)
+++ branches/db4o/freenet/src/freenet/node/RequestStarter.java  2008-06-13 
12:43:42 UTC (rev 20298)
@@ -7,6 +7,7 @@
 import java.util.LinkedList;

 import freenet.client.async.ChosenRequest;
+import freenet.keys.ClientKey;
 import freenet.keys.Key;
 import freenet.support.Logger;
 import freenet.support.OOMHandler;
@@ -215,7 +216,7 @@

        private boolean startRequest(ChosenRequest req, boolean logMINOR) {
                if(sched.fetchingKeys().hasKey(req.key)) return false;
-               core.getExecutor().execute(new SenderThread(req.request, 
req.token, req.key), "RequestStarter$SenderThread for "+req);
+               core.getExecutor().execute(new SenderThread(req.request, 
req.token, req.key, req.ckey), "RequestStarter$SenderThread for "+req);
                return true;
        }

@@ -237,17 +238,19 @@
                private final SendableRequest req;
                private final Object keyNum;
                private final Key key;
+               private final ClientKey ckey;

-               public SenderThread(SendableRequest req, Object keyNum, Key 
key) {
+               public SenderThread(SendableRequest req, Object keyNum, Key 
key, ClientKey ckey) {
                        this.req = req;
                        this.keyNum = keyNum;
                        this.key = key;
+                       this.ckey = ckey;
                }

                public void run() {
                        try {
                    freenet.support.Logger.OSThread.logPID(this);
-                       if(!req.send(core, sched, keyNum)) {
+                       if(!req.send(core, sched, keyNum, ckey)) {
                                if(!req.isCancelled())
                                        Logger.error(this, "run() not able to 
send a request on "+req);
                                else

Modified: branches/db4o/freenet/src/freenet/node/SendableGet.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/SendableGet.java     2008-06-13 
12:35:28 UTC (rev 20297)
+++ branches/db4o/freenet/src/freenet/node/SendableGet.java     2008-06-13 
12:43:42 UTC (rev 20298)
@@ -60,8 +60,7 @@
        /** Do the request, blocking. Called by RequestStarter. 
         * @return True if a request was executed. False if caller should try 
to find another request, and remove
         * this one from the queue. */
-       public boolean send(NodeClientCore core, final RequestScheduler sched, 
final Object keyNum) {
-               ClientKey key = getKey(keyNum, container);
+       public boolean send(NodeClientCore core, final RequestScheduler sched, 
final Object keyNum, ClientKey key) {
                if(key == null) {
                        Logger.error(this, "Key is null in send(): keyNum = 
"+keyNum+" for "+this);
                        return false;
@@ -152,4 +151,11 @@
         */
        public abstract void requeueAfterCooldown(Key key, long time, 
ObjectContainer container, ClientContext context);

+       /**
+        * Get the ClientKey for a specific token, so that we don't need to 
look it up on the request sender thread.
+        * @param token The token indicating this specific key.
+        * @param container The database if needed.
+        */
+       public abstract ClientKey getClientKey(Object token, ObjectContainer 
container);
+
 }

Modified: branches/db4o/freenet/src/freenet/node/SendableRequest.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/SendableRequest.java 2008-06-13 
12:35:28 UTC (rev 20297)
+++ branches/db4o/freenet/src/freenet/node/SendableRequest.java 2008-06-13 
12:43:42 UTC (rev 20298)
@@ -4,6 +4,7 @@

 import freenet.client.async.ClientContext;
 import freenet.client.async.ClientRequester;
+import freenet.keys.ClientKey;
 import freenet.support.Logger;
 import freenet.support.RandomGrabArray;
 import freenet.support.RandomGrabArrayItem;
@@ -44,9 +45,10 @@
         * @param sched The scheduler this request has just been grabbed from.
         * @param keyNum The key number that was fed into getKeyObject().
         * @param key The key returned from grabKey().
+        * @param ckey The client key for decoding, if available (mandatory for 
SendableGet, null otherwise).
         * @return True if a request was sent, false otherwise (in which case 
the request will
         * be removed if it hasn't already been). */
-       public abstract boolean send(NodeClientCore node, RequestScheduler 
sched, Object keyNum);
+       public abstract boolean send(NodeClientCore node, RequestScheduler 
sched, Object keyNum, ClientKey ckey);

        /** If true, the request has been cancelled, or has completed, either 
way it need not
         * be registered any more. isEmpty() on the other hand means there are 
no queued blocks.


Reply via email to