Author: toad
Date: 2008-07-04 13:00:10 +0000 (Fri, 04 Jul 2008)
New Revision: 20967
Modified:
branches/db4o/freenet/src/freenet/client/async/ClientRequestScheduler.java
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
branches/db4o/freenet/src/freenet/client/async/OfferedKeysList.java
branches/db4o/freenet/src/freenet/client/async/SingleBlockInserter.java
branches/db4o/freenet/src/freenet/node/RequestScheduler.java
branches/db4o/freenet/src/freenet/node/SendableGet.java
branches/db4o/freenet/src/freenet/node/SendableInsert.java
branches/db4o/freenet/src/freenet/node/SendableRequest.java
branches/db4o/freenet/src/freenet/node/SimpleSendableInsert.java
Log:
Run callbacks for non-persistent requests inline rather than on the database
thread.
Add ,boolean persistent to call* and internalError to enable this.
Modified:
branches/db4o/freenet/src/freenet/client/async/ClientRequestScheduler.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/ClientRequestScheduler.java
2008-07-04 12:49:09 UTC (rev 20966)
+++ branches/db4o/freenet/src/freenet/client/async/ClientRequestScheduler.java
2008-07-04 13:00:10 UTC (rev 20967)
@@ -797,7 +797,11 @@
schedCore.removeFetchingKey(key, req);
}
- public void callFailure(final SendableGet get, final
LowLevelGetException e, final Object keyNum, int prio, final ChosenRequest req)
{
+ public void callFailure(final SendableGet get, final
LowLevelGetException e, final Object keyNum, int prio, final ChosenRequest req,
boolean persistent) {
+ if(!persistent) {
+ get.onFailure(e, keyNum, null, clientContext);
+ return;
+ }
jobRunner.queue(new DBJob() {
public void run(ObjectContainer container,
ClientContext context) {
@@ -813,7 +817,11 @@
}, NativeThread.NORM_PRIORITY, false);
}
- public void callFailure(final SendableInsert put, final
LowLevelPutException e, final Object keyNum, int prio, final ChosenRequest req)
{
+ public void callFailure(final SendableInsert put, final
LowLevelPutException e, final Object keyNum, int prio, final ChosenRequest req,
boolean persistent) {
+ if(!persistent) {
+ put.onFailure(e, keyNum, null, clientContext);
+ return;
+ }
jobRunner.queue(new DBJob() {
public void run(ObjectContainer container,
ClientContext context) {
@@ -829,7 +837,11 @@
}, NativeThread.NORM_PRIORITY, false);
}
- public void callSuccess(final SendableInsert put, final Object keyNum,
int prio, final ChosenRequest req) {
+ public void callSuccess(final SendableInsert put, final Object keyNum,
int prio, final ChosenRequest req, boolean persistent) {
+ if(!persistent) {
+ put.onSuccess(keyNum, null, clientContext);
+ return;
+ }
jobRunner.queue(new DBJob() {
public void run(ObjectContainer container,
ClientContext context) {
Modified:
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
===================================================================
---
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
2008-07-04 12:49:09 UTC (rev 20966)
+++
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
2008-07-04 13:00:10 UTC (rev 20967)
@@ -543,7 +543,7 @@
} 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, context);
+ reg.getter.internalError(null, t,
sched, container, context, true);
}
if(System.currentTimeMillis() > deadline) break;
}
Modified: branches/db4o/freenet/src/freenet/client/async/OfferedKeysList.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/OfferedKeysList.java
2008-07-04 12:49:09 UTC (rev 20966)
+++ branches/db4o/freenet/src/freenet/client/async/OfferedKeysList.java
2008-07-04 13:00:10 UTC (rev 20967)
@@ -138,7 +138,7 @@
return 0; // All keys have equal chance even if they've been
tried before.
}
- public void internalError(Object keyNum, Throwable t, RequestScheduler
sched, ObjectContainer container, ClientContext context) {
+ public void internalError(Object keyNum, Throwable t, RequestScheduler
sched, ObjectContainer container, ClientContext context, boolean persistent) {
Logger.error(this, "Internal error: "+t, t);
}
Modified:
branches/db4o/freenet/src/freenet/client/async/SingleBlockInserter.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/SingleBlockInserter.java
2008-07-04 12:49:09 UTC (rev 20966)
+++ branches/db4o/freenet/src/freenet/client/async/SingleBlockInserter.java
2008-07-04 13:00:10 UTC (rev 20967)
@@ -353,12 +353,12 @@
return false;
}
} catch (LowLevelPutException e) {
- sched.callFailure((SendableInsert) this, e, req.token,
NativeThread.NORM_PRIORITY, req);
+ sched.callFailure((SendableInsert) this, e, req.token,
NativeThread.NORM_PRIORITY, req, req.isPersistent());
if(logMINOR) Logger.minor(this, "Request failed:
"+this+" for "+e);
return true;
}
if(logMINOR) Logger.minor(this, "Request succeeded: "+this);
- sched.callSuccess(this, req.token, NativeThread.NORM_PRIORITY,
req);
+ sched.callSuccess(this, req.token, NativeThread.NORM_PRIORITY,
req, req.isPersistent());
return true;
}
Modified: branches/db4o/freenet/src/freenet/node/RequestScheduler.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/RequestScheduler.java
2008-07-04 12:49:09 UTC (rev 20966)
+++ branches/db4o/freenet/src/freenet/node/RequestScheduler.java
2008-07-04 13:00:10 UTC (rev 20967)
@@ -58,15 +58,15 @@
/** Call onFailure() on the database thread, then delete the
PersistentChosenRequest. For a non-persistent request,
* just call onFailure() immediately. */
- public void callFailure(final SendableGet get, final
LowLevelGetException e, final Object keyNum, int prio, ChosenRequest req);
+ public void callFailure(final SendableGet get, final
LowLevelGetException e, final Object keyNum, int prio, ChosenRequest req,
boolean persistent);
/** Call onFailure() on the database thread, then delete the
PersistentChosenRequest. For a non-persistent request,
* just call onFailure() immediately. */
- public void callFailure(final SendableInsert put, final
LowLevelPutException e, final Object keyNum, int prio, ChosenRequest req);
+ public void callFailure(final SendableInsert put, final
LowLevelPutException e, final Object keyNum, int prio, ChosenRequest req,
boolean persistent);
/** Call onSuccess() on the database thread, then delete the
PersistentChosenRequest. For a non-persistent request,
* just call onFailure() immediately. */
- public void callSuccess(final SendableInsert put, final Object keyNum,
int prio, ChosenRequest req);
+ public void callSuccess(final SendableInsert put, final Object keyNum,
int prio, ChosenRequest req, boolean persistent);
public FECQueue getFECQueue();
Modified: branches/db4o/freenet/src/freenet/node/SendableGet.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/SendableGet.java 2008-07-04
12:49:09 UTC (rev 20966)
+++ branches/db4o/freenet/src/freenet/node/SendableGet.java 2008-07-04
13:00:10 UTC (rev 20967)
@@ -75,25 +75,25 @@
if((!req.isPersistent()) && isCancelled(null)) {
if(logMINOR) Logger.minor(this, "Cancelled: "+this);
// callbacks must initially run at HIGH_PRIORITY so
they are executed before we remove the key from the currently running list
- sched.callFailure(this, new
LowLevelGetException(LowLevelGetException.CANCELLED), keyNum,
NativeThread.HIGH_PRIORITY, req);
+ sched.callFailure(this, new
LowLevelGetException(LowLevelGetException.CANCELLED), keyNum,
NativeThread.HIGH_PRIORITY, req, req.isPersistent());
return false;
}
try {
try {
core.realGetKey(key, req.localRequestOnly,
req.cacheLocalRequests, req.ignoreStore);
} catch (final LowLevelGetException e) {
- sched.callFailure(this, e, keyNum,
NativeThread.HIGH_PRIORITY, req);
+ sched.callFailure(this, e, keyNum,
NativeThread.HIGH_PRIORITY, req, req.isPersistent());
return true;
} catch (Throwable t) {
Logger.error(this, "Caught "+t, t);
- sched.callFailure(this, new
LowLevelGetException(LowLevelGetException.INTERNAL_ERROR), keyNum,
NativeThread.HIGH_PRIORITY, req);
+ sched.callFailure(this, new
LowLevelGetException(LowLevelGetException.INTERNAL_ERROR), keyNum,
NativeThread.HIGH_PRIORITY, req, req.isPersistent());
return true;
}
// Don't call onSuccess(), it will be called for us by
backdoor coalescing.
sched.succeeded(this, req);
} catch (Throwable t) {
Logger.error(this, "Caught "+t, t);
- sched.callFailure(this, new
LowLevelGetException(LowLevelGetException.INTERNAL_ERROR), keyNum,
NativeThread.HIGH_PRIORITY, req);
+ sched.callFailure(this, new
LowLevelGetException(LowLevelGetException.INTERNAL_ERROR), keyNum,
NativeThread.HIGH_PRIORITY, req, req.isPersistent());
return true;
}
return true;
@@ -143,8 +143,8 @@
getScheduler(context).removePendingKey(this, false, key,
container);
}
- public void internalError(final Object keyNum, final Throwable t, final
RequestScheduler sched, ObjectContainer container, ClientContext context) {
- sched.callFailure(this, new
LowLevelGetException(LowLevelGetException.INTERNAL_ERROR, t.getMessage(), t),
keyNum, NativeThread.MAX_PRIORITY, null);
+ public void internalError(final Object keyNum, final Throwable t, final
RequestScheduler sched, ObjectContainer container, ClientContext context,
boolean persistent) {
+ sched.callFailure(this, new
LowLevelGetException(LowLevelGetException.INTERNAL_ERROR, t.getMessage(), t),
keyNum, NativeThread.MAX_PRIORITY, null, persistent);
}
/**
Modified: branches/db4o/freenet/src/freenet/node/SendableInsert.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/SendableInsert.java 2008-07-04
12:49:09 UTC (rev 20966)
+++ branches/db4o/freenet/src/freenet/node/SendableInsert.java 2008-07-04
13:00:10 UTC (rev 20967)
@@ -25,7 +25,7 @@
/** Called when we don't! */
public abstract void onFailure(LowLevelPutException e, Object keyNum,
ObjectContainer container, ClientContext context);
- public void internalError(Object keyNum, Throwable t, RequestScheduler
sched, ObjectContainer container, ClientContext context) {
+ public void internalError(Object keyNum, Throwable t, RequestScheduler
sched, ObjectContainer container, ClientContext context, boolean persistent) {
onFailure(new
LowLevelPutException(LowLevelPutException.INTERNAL_ERROR, t.getMessage(), t),
keyNum, container, context);
}
Modified: branches/db4o/freenet/src/freenet/node/SendableRequest.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/SendableRequest.java 2008-07-04
12:49:09 UTC (rev 20966)
+++ branches/db4o/freenet/src/freenet/node/SendableRequest.java 2008-07-04
13:00:10 UTC (rev 20967)
@@ -110,6 +110,6 @@
}
/** Requeue after an internal error */
- public abstract void internalError(Object keyNum, Throwable t,
RequestScheduler sched, ObjectContainer container, ClientContext context);
+ public abstract void internalError(Object keyNum, Throwable t,
RequestScheduler sched, ObjectContainer container, ClientContext context,
boolean persistent);
}
Modified: branches/db4o/freenet/src/freenet/node/SimpleSendableInsert.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/SimpleSendableInsert.java
2008-07-04 12:49:09 UTC (rev 20966)
+++ branches/db4o/freenet/src/freenet/node/SimpleSendableInsert.java
2008-07-04 13:00:10 UTC (rev 20967)
@@ -77,14 +77,14 @@
if(logMINOR) Logger.minor(this, "Starting request:
"+this);
core.realPut(block, shouldCache());
} catch (LowLevelPutException e) {
- sched.callFailure(this, e, req.token,
NativeThread.NORM_PRIORITY, req);
+ sched.callFailure(this, e, req.token,
NativeThread.NORM_PRIORITY, req, false);
if(logMINOR) Logger.minor(this, "Request failed:
"+this+" for "+e);
return true;
} finally {
finished = true;
}
if(logMINOR) Logger.minor(this, "Request succeeded: "+this);
- sched.callSuccess(this, req.token, NativeThread.NORM_PRIORITY,
req);
+ sched.callSuccess(this, req.token, NativeThread.NORM_PRIORITY,
req, false);
return true;
}