Author: toad
Date: 2008-06-17 18:53:42 +0000 (Tue, 17 Jun 2008)
New Revision: 20415
Modified:
branches/db4o/freenet/src/freenet/clients/http/QueueToadlet.java
branches/db4o/freenet/src/freenet/node/fcp/FCPServer.java
Log:
Run queue page generation on the database thread.
Now FCP is almost done, and everything except for USKs compiles.
Modified: branches/db4o/freenet/src/freenet/clients/http/QueueToadlet.java
===================================================================
--- branches/db4o/freenet/src/freenet/clients/http/QueueToadlet.java
2008-06-17 18:40:29 UTC (rev 20414)
+++ branches/db4o/freenet/src/freenet/clients/http/QueueToadlet.java
2008-06-17 18:53:42 UTC (rev 20415)
@@ -371,7 +371,7 @@
writeHTMLReply(context, 400, "Bad request",
pageNode.generate());
}
- public void handleGet(URI uri, final HTTPRequest request,
ToadletContext ctx)
+ public void handleGet(URI uri, final HTTPRequest request, final
ToadletContext ctx)
throws ToadletContextClosedException, IOException, RedirectException {
// We ensure that we have a FCP server running
@@ -406,8 +406,53 @@
return;
}
- PageMaker pageMaker = ctx.getPageMaker();
+ class OutputWrapper {
+ boolean done;
+ HTMLNode pageNode;
+ }
+ final OutputWrapper ow = new OutputWrapper();
+
+ final PageMaker pageMaker = ctx.getPageMaker();
+
+ core.clientContext.jobRunner.queue(new DBJob() {
+
+ public void run(ObjectContainer container,
ClientContext context) {
+ HTMLNode pageNode = null;
+ try {
+ pageNode = handleGetInner(pageMaker,
container, context, request, ctx);
+ } finally {
+ synchronized(ow) {
+ ow.done = true;
+ ow.notifyAll();
+ }
+ }
+ }
+
+ }, NativeThread.HIGH_PRIORITY, false);
+
+ HTMLNode pageNode;
+ synchronized(ow) {
+ while(true) {
+ if(ow.done) {
+ pageNode = ow.pageNode;
+ break;
+ }
+ try {
+ ow.wait();
+ } catch (InterruptedException e) {
+ // Ignore
+ }
+ }
+ }
+
+ MultiValueTable pageHeaders = new MultiValueTable();
+ writeHTMLReply(ctx, 200, "OK", pageHeaders,
pageNode.generate());
+
+ }
+
+ private HTMLNode handleGetInner(PageMaker pageMaker, ObjectContainer
container, ClientContext context, final HTTPRequest request, ToadletContext
ctx) {
+
// First, get the queued requests, and separate them into
different types.
LinkedList completedDownloadToDisk = new LinkedList();
LinkedList completedDownloadToTemp = new LinkedList();
@@ -422,7 +467,7 @@
LinkedList uncompletedUpload = new LinkedList();
LinkedList uncompletedDirUpload = new LinkedList();
- ClientRequest[] reqs = fcp.getGlobalRequests();
+ ClientRequest[] reqs = fcp.getGlobalRequests(container);
if(Logger.shouldLog(Logger.MINOR, this))
Logger.minor(this, "Request count: "+reqs.length);
@@ -436,8 +481,7 @@
HTMLNode infoboxContent =
pageMaker.getContentNode(infobox);
infoboxContent.addChild("#",
L10n.getString("QueueToadlet.noTaskOnGlobalQueue"));
contentNode.addChild(createInsertBox(pageMaker, ctx,
core.isAdvancedModeEnabled()));
- writeHTMLReply(ctx, 200, "OK", pageNode.generate());
- return;
+ return pageNode;
}
short lowestQueuedPrio = RequestStarter.MINIMUM_PRIORITY_CLASS;
@@ -739,8 +783,7 @@
}
}
- MultiValueTable pageHeaders = new MultiValueTable();
- writeHTMLReply(ctx, 200, "OK", pageHeaders,
pageNode.generate());
+ return pageNode;
}
Modified: branches/db4o/freenet/src/freenet/node/fcp/FCPServer.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/fcp/FCPServer.java 2008-06-17
18:40:29 UTC (rev 20414)
+++ branches/db4o/freenet/src/freenet/node/fcp/FCPServer.java 2008-06-17
18:53:42 UTC (rev 20415)
@@ -562,9 +562,10 @@
}
}
- public ClientRequest[] getGlobalRequests() {
+ public ClientRequest[] getGlobalRequests(ObjectContainer container) {
Vector v = new Vector();
- globalClient.addPersistentRequests(v, false);
+ globalRebootClient.addPersistentRequests(v, false, null);
+ globalForeverClient.addPersistentRequests(v, false, container);
return (ClientRequest[]) v.toArray(new ClientRequest[v.size()]);
}