Author: toad
Date: 2008-06-14 14:23:39 +0000 (Sat, 14 Jun 2008)
New Revision: 20345
Added:
branches/db4o/freenet/src/freenet/node/fcp/FCPPersistentRoot.java
Modified:
branches/db4o/freenet/src/freenet/node/fcp/FCPClient.java
branches/db4o/freenet/src/freenet/node/fcp/FCPConnectionHandler.java
branches/db4o/freenet/src/freenet/node/fcp/FCPServer.java
Log:
Add FCPPersistentRoot.
This contains initially the globalForeverClient and registerForeverClient().
Also some fixes.
Modified: branches/db4o/freenet/src/freenet/node/fcp/FCPClient.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/fcp/FCPClient.java 2008-06-14
14:16:32 UTC (rev 20344)
+++ branches/db4o/freenet/src/freenet/node/fcp/FCPClient.java 2008-06-14
14:23:39 UTC (rev 20345)
@@ -15,7 +15,7 @@
*/
public class FCPClient {
- public FCPClient(String name2, FCPConnectionHandler handler, boolean
isGlobalQueue, RequestCompletionCallback cb, short persistenceType) {
+ public FCPClient(String name2, FCPConnectionHandler handler, boolean
isGlobalQueue, RequestCompletionCallback cb, short persistenceType,
FCPPersistentRoot root) {
this.name = name2;
if(name == null) throw new NullPointerException();
this.currentConnection = handler;
@@ -38,8 +38,14 @@
}
};
completionCallback = cb;
+ if(persistenceType == ClientRequest.PERSIST_FOREVER)
+ this.root = root;
+ else
+ this.root = null;
}
+ /** The persistent root object, null if persistenceType is
PERSIST_REBOOT */
+ final FCPPersistentRoot root;
/** The client's Name sent in the ClientHello message */
final String name;
/** The current connection handler, if any. */
Modified: branches/db4o/freenet/src/freenet/node/fcp/FCPConnectionHandler.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/fcp/FCPConnectionHandler.java
2008-06-14 14:16:32 UTC (rev 20344)
+++ branches/db4o/freenet/src/freenet/node/fcp/FCPConnectionHandler.java
2008-06-14 14:23:39 UTC (rev 20345)
@@ -499,7 +499,7 @@
(rebootOnly ? getRebootClient() : getForeverClient());
ClientRequest req = client.getRequest(identifier);
if(req != null) {
- client.removeByIdentifier(identifier, true);
+ client.removeByIdentifier(identifier, true, server);
}
return req;
}
Added: branches/db4o/freenet/src/freenet/node/fcp/FCPPersistentRoot.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/fcp/FCPPersistentRoot.java
(rev 0)
+++ branches/db4o/freenet/src/freenet/node/fcp/FCPPersistentRoot.java
2008-06-14 14:23:39 UTC (rev 20345)
@@ -0,0 +1,55 @@
+/* This code is part of Freenet. It is distributed under the GNU General
+ * Public License, version 2 (or at your option any later version). See
+ * http://www.gnu.org/ for further details of the GPL. */
+package freenet.node.fcp;
+
+import com.db4o.ObjectContainer;
+import com.db4o.ObjectSet;
+import com.db4o.query.Predicate;
+
+import freenet.node.NodeClientCore;
+
+/**
+ * Persistent root object for FCP.
+ * @author toad
+ */
+public class FCPPersistentRoot {
+
+ final long nodeDBHandle;
+ final FCPClient globalForeverClient;
+
+ public FCPPersistentRoot(long nodeDBHandle) {
+ this.nodeDBHandle = nodeDBHandle;
+ globalForeverClient = new FCPClient("Global Queue", null, true,
null, ClientRequest.PERSIST_REBOOT, this);
+ }
+
+ public static FCPPersistentRoot create(final long nodeDBHandle,
ObjectContainer container) {
+ ObjectSet set = container.query(new Predicate() {
+ public boolean match(FCPPersistentRoot root) {
+ return root.nodeDBHandle == nodeDBHandle;
+ }
+ });
+ if(set.hasNext()) {
+ return (FCPPersistentRoot) set.next();
+ }
+ FCPPersistentRoot root = new FCPPersistentRoot(nodeDBHandle);
+ container.set(root);
+ return root;
+ }
+
+ public FCPClient registerForeverClient(final String name,
NodeClientCore core, FCPConnectionHandler handler, FCPServer server,
ObjectContainer container) {
+ ObjectSet set = container.query(new Predicate() {
+ public boolean match(FCPClient client) {
+ if(client.root != FCPPersistentRoot.this)
return false;
+ return client.name.equals(name);
+ }
+ });
+ if(!set.hasNext()) {
+ return (FCPClient) set.next();
+ }
+ FCPClient client = new FCPClient(name, handler, false, null,
ClientRequest.PERSIST_FOREVER, this);
+ container.set(client);
+ return client;
+ }
+
+}
Modified: branches/db4o/freenet/src/freenet/node/fcp/FCPServer.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/fcp/FCPServer.java 2008-06-14
14:16:32 UTC (rev 20344)
+++ branches/db4o/freenet/src/freenet/node/fcp/FCPServer.java 2008-06-14
14:23:39 UTC (rev 20345)
@@ -23,6 +23,8 @@
import org.tanukisoftware.wrapper.WrapperManager;
+import com.db4o.ObjectContainer;
+
import freenet.client.DefaultMIMETypes;
import freenet.client.FetchContext;
import freenet.client.HighLevelSimpleClient;
@@ -56,6 +58,7 @@
*/
public class FCPServer implements Runnable {
+ final FCPPersistentRoot persistentRoot;
private static boolean logMINOR;
public final static int DEFAULT_FCP_PORT = 9481;
NetworkInterface networkInterface;
@@ -98,7 +101,7 @@
persister = null;
}
- public FCPServer(String ipToBindTo, String allowedHosts, String
allowedHostsFullAccess, int port, Node node, NodeClientCore core, boolean
persistentDownloadsEnabled, String persistentDownloadsDir, long
persistenceInterval, boolean isEnabled, boolean assumeDDADownloadAllowed,
boolean assumeDDAUploadAllowed) throws IOException, InvalidConfigValueException
{
+ public FCPServer(String ipToBindTo, String allowedHosts, String
allowedHostsFullAccess, int port, Node node, NodeClientCore core, boolean
persistentDownloadsEnabled, String persistentDownloadsDir, long
persistenceInterval, boolean isEnabled, boolean assumeDDADownloadAllowed,
boolean assumeDDAUploadAllowed, ObjectContainer container) throws IOException,
InvalidConfigValueException {
this.bindTo = ipToBindTo;
this.allowedHosts=allowedHosts;
this.allowedHostsFullAccess = new
AllowedHosts(allowedHostsFullAccess);
@@ -119,7 +122,7 @@
defaultFetchContext = client.getFetchContext();
defaultInsertContext = client.getInsertContext(false);
- globalRebootClient = new FCPClient("Global Queue", null, true,
null, ClientRequest.PERSIST_REBOOT);
+ globalRebootClient = new FCPClient("Global Queue", null, true,
null, ClientRequest.PERSIST_REBOOT, null);
logMINOR = Logger.shouldLog(Logger.MINOR, this);
@@ -128,6 +131,8 @@
} else {
Logger.error(this, "Not loading persistent requests:
enabled="+enabled+" enable persistent downloads="+enablePersistentDownloads);
}
+ persistentRoot = FCPPersistentRoot.create(node.nodeDBHandle,
container);
+ globalForeverClient = persistentRoot.globalForeverClient;
}
private void maybeGetNetworkInterface() {
@@ -511,13 +516,13 @@
return enablePersistentDownloads;
}
- public FCPClient registerClient(String name, NodeClientCore core,
FCPConnectionHandler handler) {
+ public FCPClient registerRebootClient(String name, NodeClientCore core,
FCPConnectionHandler handler) {
FCPClient oldClient;
synchronized(this) {
oldClient = (FCPClient) clientsByName.get(name);
if(oldClient == null) {
// Create new client
- FCPClient client = new FCPClient(name, this,
handler, false, null);
+ FCPClient client = new FCPClient(name, handler,
false, null, ClientRequest.PERSIST_REBOOT);
clientsByName.put(name, client);
return client;
} else {
@@ -539,6 +544,10 @@
oldClient.queuePendingMessagesOnConnectionRestart(handler.outputHandler);
return oldClient;
}
+
+ public FCPClient registerForeverClient(String name, NodeClientCore
core, FCPConnectionHandler handler) {
+ return persistentRoot.registerForeverClient(name, core,
handler, this);
+ }
public void unregisterClient(FCPClient client) {
synchronized(this) {