Author: toad
Date: 2008-05-20 12:49:52 +0000 (Tue, 20 May 2008)
New Revision: 19965

Modified:
   branches/db4o/freenet/.classpath
   branches/db4o/freenet/src/freenet/node/Node.java
Log:
Create a database.

Modified: branches/db4o/freenet/.classpath
===================================================================
--- branches/db4o/freenet/.classpath    2008-05-20 12:16:34 UTC (rev 19964)
+++ branches/db4o/freenet/.classpath    2008-05-20 12:49:52 UTC (rev 19965)
@@ -5,5 +5,6 @@
        <classpathentry exported="true" kind="lib" path="lib/freenet-ext.jar"/>
        <classpathentry kind="con" 
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
        <classpathentry kind="lib" path="/usr/share/java/junit.jar"/>
+       <classpathentry kind="lib" path="lib/db4o-6.4.38.10595-java1.2.jar"/>
        <classpathentry kind="output" path="bin"/>
 </classpath>

Modified: branches/db4o/freenet/src/freenet/node/Node.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/Node.java    2008-05-20 12:16:34 UTC 
(rev 19964)
+++ branches/db4o/freenet/src/freenet/node/Node.java    2008-05-20 12:49:52 UTC 
(rev 19965)
@@ -27,6 +27,8 @@
 import org.spaceroots.mantissa.random.MersenneTwister;
 import org.tanukisoftware.wrapper.WrapperManager;

+import com.db4o.Db4o;
+import com.db4o.ObjectContainer;
 import com.sleepycat.je.DatabaseException;
 import com.sleepycat.je.Environment;
 import com.sleepycat.je.EnvironmentConfig;
@@ -218,6 +220,12 @@
                }
        }

+       /** db4o database for node and client layer.
+        * Other databases can be created for the datastore (since its usage 
+        * patterns and content are completely different), or for plugins (for 
+        * security reasons). */
+       final ObjectContainer db;
+       
        /** Stats */
        public final NodeStats nodeStats;
        public final NetworkIDManager netid;
@@ -698,6 +706,16 @@
                        throw new 
NodeInitException(NodeInitException.EXIT_BAD_NODE_DIR, msg);
                }

+               /* FIXME: this may throw if e.g. we ran out of disk space last 
time. 
+                * We need to back it up and auto-recover. */
+               /* For now, just a single transaction. 
+                * Switch to client-server mode later if we need it. 
+                * Clients have local caching, and need an explicit refresh on 
local 
+                * objects to get updates... so if we use client-server mode, 
we will 
+                * need to be careful. */
+               db = Db4o.openFile(new File(nodeDir, "node.db4o").toString());
+               System.err.println("Opened database");
+               
                // Boot ID
                bootID = random.nextLong();
                // Fixed length file containing boot ID. Accessed with random 
access file. So hopefully it will always be
@@ -895,6 +913,12 @@
                        }
                });

+               shutdownHook.addLateJob(new Thread() {
+                       public void run() {
+                               db.close();
+                       }
+               });
+               
                // Bandwidth limit

                nodeConfig.register("outputBandwidthLimit", "15K", sortOrder++, 
false, true, "Node.outBWLimit", "Node.outBWLimitLong", new IntCallback() {


Reply via email to