Author: toad
Date: 2008-06-28 21:24:47 +0000 (Sat, 28 Jun 2008)
New Revision: 20864

Modified:
   branches/db4o/freenet/src/freenet/node/fcp/ClientPut.java
   branches/db4o/freenet/src/freenet/node/fcp/ClientRequest.java
   branches/db4o/freenet/src/freenet/node/fcp/FCPServer.java
Log:
Automatic migration of downloads, uploads, etc.
Tested and working with downloads and completed requests of all kinds.
Not yet tested with uploads.

Modified: branches/db4o/freenet/src/freenet/node/fcp/ClientPut.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/fcp/ClientPut.java   2008-06-28 
21:07:49 UTC (rev 20863)
+++ branches/db4o/freenet/src/freenet/node/fcp/ClientPut.java   2008-06-28 
21:24:47 UTC (rev 20864)
@@ -259,7 +259,7 @@
         * @throws IOException 
         * @throws InsertException 
         */
-       public ClientPut(SimpleFieldSet fs, FCPClient client2, FCPServer 
server) throws PersistenceParseException, IOException, InsertException {
+       public ClientPut(SimpleFieldSet fs, FCPClient client2, FCPServer 
server, ObjectContainer container) throws PersistenceParseException, 
IOException, InsertException {
                super(fs, client2, server);
                logMINOR = Logger.shouldLog(Logger.MINOR, this);
                String mimeType = fs.get("Metadata.ContentType");
@@ -338,8 +338,8 @@
                                client.lowLevelClient,
                                oldProgress, targetFilename, binaryBlob);
                if(persistenceType != PERSIST_CONNECTION) {
-                       FCPMessage msg = persistentTagMessage(null);
-                       client.queueClientRequestMessage(msg, 0, null);
+                       FCPMessage msg = persistentTagMessage(container);
+                       client.queueClientRequestMessage(msg, 0, container);
                }

        }

Modified: branches/db4o/freenet/src/freenet/node/fcp/ClientRequest.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/fcp/ClientRequest.java       
2008-06-28 21:07:49 UTC (rev 20863)
+++ branches/db4o/freenet/src/freenet/node/fcp/ClientRequest.java       
2008-06-28 21:24:47 UTC (rev 20864)
@@ -185,7 +185,7 @@
                                if(!lazyResume) cg.start(container, context);
                                return cg;
                        } else if(type.equals("PUT")) {
-                               ClientPut cp = new ClientPut(fs, client, 
server);
+                               ClientPut cp = new ClientPut(fs, client, 
server, container);
                                client.register(cp, lazyResume, container);
                                if(!lazyResume) cp.start(container, context);
                                return cp;

Modified: branches/db4o/freenet/src/freenet/node/fcp/FCPServer.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/fcp/FCPServer.java   2008-06-28 
21:07:49 UTC (rev 20863)
+++ branches/db4o/freenet/src/freenet/node/fcp/FCPServer.java   2008-06-28 
21:24:47 UTC (rev 20864)
@@ -109,13 +109,16 @@

                logMINOR = Logger.shouldLog(Logger.MINOR, this);

+               persistentRoot = FCPPersistentRoot.create(node.nodeDBHandle, 
container);
+               globalForeverClient = persistentRoot.globalForeverClient;
+               
                if(enabled && enablePersistentDownloads) {
+                       Logger.error(this, "Persistent downloads enabled: 
attempting to migrate old persistent downloads to database...");
+                       Logger.error(this, "Note that we will not write to 
downloads.dat.gz, we will read from it and rename it if migration is 
successful.");
                        loadPersistentRequests(container);
                } 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() {
@@ -289,6 +292,22 @@

        }

+       static class PersistentDownloadsEnabledCallback implements 
BooleanCallback {
+               
+               boolean enabled;
+               
+               public boolean get() {
+                       return enabled;
+               }
+               
+               public void set(boolean set) throws InvalidConfigValueException 
{
+                       // This option will be removed completely soon, so 
there is little
+                       // point in translating it. FIXME remove.
+                       if(set != enabled) throw new 
InvalidConfigValueException("Cannot disable/enable persistent download loading 
support on the fly");
+               }
+               
+       }
+
        static class FCPAllowedHostsFullAccessCallback implements 
StringCallback {

                private final NodeClientCore node;
@@ -308,7 +327,7 @@
                }

        }
-
+       
        static class PersistentDownloadsFileCallback implements StringCallback {

                FCPServer server;
@@ -361,11 +380,13 @@
                fcpConfig.register("allowedHosts", 
NetworkInterface.DEFAULT_BIND_TO, sortOrder++, true, true, 
"FcpServer.allowedHosts", "FcpServer.allowedHostsLong", new 
FCPAllowedHostsCallback(core));
                fcpConfig.register("allowedHostsFullAccess", 
NetworkInterface.DEFAULT_BIND_TO, sortOrder++, true, true, 
"FcpServer.allowedHostsFullAccess", "FcpServer.allowedHostsFullAccessLong", new 
FCPAllowedHostsFullAccessCallback(core));
                PersistentDownloadsFileCallback cb2;
-               fcpConfig.register("persistentDownloadsEnabled", true, 
sortOrder++, true, true, "FcpServer.enablePersistentDownload", 
"FcpServer.enablePersistentDownloadLong", (BooleanCallback) null);
+               PersistentDownloadsEnabledCallback enabledCB = new 
PersistentDownloadsEnabledCallback();
+               fcpConfig.register("persistentDownloadsEnabled", true, 
sortOrder++, true, true, "FcpServer.enablePersistentDownload", 
"FcpServer.enablePersistentDownloadLong", enabledCB);
                fcpConfig.register("persistentDownloadsFile", "downloads.dat", 
sortOrder++, true, false, "FcpServer.filenameToStorePData", 
"FcpServer.filenameToStorePDataLong", cb2 = new 
PersistentDownloadsFileCallback());
                fcpConfig.register("persistentDownloadsInterval", (5*60*1000), 
sortOrder++, true, false, "FcpServer.intervalBetweenWrites", 
"FcpServer.intervalBetweenWritesLong", (IntCallback) null);
                String persistentDownloadsDir = 
fcpConfig.getString("persistentDownloadsFile");
-               boolean persistentDownloadsEnabled = 
fcpConfig.getBoolean("persistentDownloadsEnabled");                
+               boolean persistentDownloadsEnabled = 
fcpConfig.getBoolean("persistentDownloadsEnabled");
+               enabledCB.enabled = persistentDownloadsEnabled;

                AssumeDDADownloadIsAllowedCallback cb4;
                AssumeDDAUploadIsAllowedCallback cb5;
@@ -843,6 +864,24 @@
                        
clients[i].finishStart(node.clientCore.clientContext.jobRunner);
                }

+               if(enablePersistentDownloads) {
+                       boolean movedMain = false;
+                       // Rename
+                       if(persistentDownloadsFile.exists()) {
+                               File target = new 
File(persistentDownloadsFile.getPath()+".old.pre-db4o");
+                               if(persistentDownloadsFile.renameTo(target)) {
+                                       Logger.error(this, "Successfully 
migrated persistent downloads and renamed "+persistentDownloadsFile.getName()+" 
to "+target.getName());
+                                       movedMain = true;
+                               }
+                       }
+                       if(persistentDownloadsTempFile.exists()) {
+                               File target = new 
File(persistentDownloadsFile.getPath()+".old.pre-db4o");
+                               if(persistentDownloadsFile.renameTo(target) && 
!movedMain)
+                                       Logger.error(this, "Successfully 
migrated persistent downloads and renamed "+persistentDownloadsFile.getName()+" 
to "+target.getName());
+                       }
+                       
+               }
+               
                hasFinishedStart = true;
        }



Reply via email to