Author: toad
Date: 2008-05-29 23:16:32 +0000 (Thu, 29 May 2008)
New Revision: 20139

Modified:
   branches/db4o/freenet/src/freenet/client/async/ClientRequestScheduler.java
   
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
Log:
RegisterMeRunner: Better error handling, commit when done (whether successful 
or not).

Modified: 
branches/db4o/freenet/src/freenet/client/async/ClientRequestScheduler.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/ClientRequestScheduler.java  
2008-05-29 23:10:06 UTC (rev 20138)
+++ branches/db4o/freenet/src/freenet/client/async/ClientRequestScheduler.java  
2008-05-29 23:16:32 UTC (rev 20139)
@@ -104,7 +104,7 @@

        public ClientRequestScheduler(boolean forInserts, boolean forSSKs, 
RandomSource random, RequestStarter starter, Node node, NodeClientCore core, 
SubConfig sc, String name) {
                this.selectorContainer = node.db;
-               schedCore = ClientRequestSchedulerCore.create(node, forInserts, 
forSSKs, selectorContainer, COOLDOWN_PERIOD, core.clientDatabaseExecutor);
+               schedCore = ClientRequestSchedulerCore.create(node, forInserts, 
forSSKs, selectorContainer, COOLDOWN_PERIOD, core.clientDatabaseExecutor, this);
                schedTransient = new ClientRequestSchedulerNonPersistent(this);
                persistentCooldownQueue = schedCore.persistentCooldownQueue;
                this.databaseExecutor = core.clientDatabaseExecutor;

Modified: 
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
===================================================================
--- 
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java  
    2008-05-29 23:10:06 UTC (rev 20138)
+++ 
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java  
    2008-05-29 23:16:32 UTC (rev 20139)
@@ -41,6 +41,7 @@
        final PersistentCooldownQueue persistentCooldownQueue;
        private transient RandomSource random;
        private transient PrioritizedSerialExecutor databaseExecutor;
+       private transient ClientRequestScheduler sched;

        /**
         * Fetch a ClientRequestSchedulerCore from the database, or create a 
new one.
@@ -51,7 +52,7 @@
         * @param executor 
         * @return
         */
-       public static ClientRequestSchedulerCore create(Node node, final 
boolean forInserts, final boolean forSSKs, ObjectContainer selectorContainer, 
long cooldownTime, PrioritizedSerialExecutor databaseExecutor) {
+       public static ClientRequestSchedulerCore create(Node node, final 
boolean forInserts, final boolean forSSKs, ObjectContainer selectorContainer, 
long cooldownTime, PrioritizedSerialExecutor databaseExecutor, 
ClientRequestScheduler sched) {
                final long nodeDBHandle = node.nodeDBHandle;
                ObjectSet results = selectorContainer.query(new Predicate() {
                        public boolean match(ClientRequestSchedulerCore core) {
@@ -68,7 +69,7 @@
                        core = new ClientRequestSchedulerCore(node, forInserts, 
forSSKs, selectorContainer, cooldownTime);
                }
                logMINOR = Logger.shouldLog(Logger.MINOR, 
ClientRequestSchedulerCore.class);
-               core.onStarted(selectorContainer, cooldownTime, node.random, 
databaseExecutor);
+               core.onStarted(selectorContainer, cooldownTime, node.random, 
databaseExecutor, sched);
                return core;
        }

@@ -83,7 +84,7 @@
                }
        }

-       private void onStarted(ObjectContainer container, long cooldownTime, 
RandomSource random, PrioritizedSerialExecutor databaseExecutor) {
+       private void onStarted(ObjectContainer container, long cooldownTime, 
RandomSource random, PrioritizedSerialExecutor databaseExecutor, 
ClientRequestScheduler sched) {
                ((Db4oMap)pendingKeys).activationDepth(1);
                ((Db4oMap)allRequestsByClientRequest).activationDepth(1);
                ((Db4oList)recentSuccesses).activationDepth(1);
@@ -94,6 +95,7 @@
                this.random = random;
                this.databaseExecutor = databaseExecutor;
                databaseExecutor.execute(registerMeRunner, 
NativeThread.NORM_PRIORITY, "Register request");
+               this.sched = sched;
        }

        // We pass in the schedTransient to the next two methods so that we can 
select between either of them.
@@ -344,7 +346,14 @@
                                }
                                container.delete(reg);
                                // Don't need to activate, fields should exist? 
FIXME
-                               innerRegister(reg.getter, random);
+                               try {
+                                       innerRegister(reg.getter, random);
+                               } catch (Throwable t) {
+                                       Logger.error(this, "Caught "+t+" 
running RegisterMeRunner", t);
+                                       // Cancel the request, and commit so it 
isn't tried again.
+                                       reg.getter.internalError(null, t, 
sched);
+                               }
+                               container.commit();
                        }
                }



Reply via email to