Author: j16sdiz
Date: 2008-12-23 08:38:46 +0000 (Tue, 23 Dec 2008)
New Revision: 24762

Modified:
   trunk/plugins/XMLSpider/XMLSpider.java
Log:
storing config in db4o

Modified: trunk/plugins/XMLSpider/XMLSpider.java
===================================================================
--- trunk/plugins/XMLSpider/XMLSpider.java      2008-12-23 08:22:31 UTC (rev 
24761)
+++ trunk/plugins/XMLSpider/XMLSpider.java      2008-12-23 08:38:46 UTC (rev 
24762)
@@ -73,12 +73,18 @@
  *  
  */
 public class XMLSpider implements FredPlugin, FredPluginHTTP, 
FredPluginThreadless, FredPluginVersioned, FredPluginL10n, USKCallback {
-       private Config config = new Config(true);
+       private Config config;
 
        public Config getConfig() {
-               return config;
+               // always return a clone, never allow changing directly
+               return config.clone();
        }
 
+       // Set config asynchronously
+       public void setConfig(Config config) {
+               callbackExecutor.execute(new SetConfigCallback(config));
+       }
+       
        public synchronized long getNextPageId() {
                long x = maxPageId.incrementAndGet();
                db.store(maxPageId);
@@ -333,7 +339,24 @@
                        }
                }
        }
+               
+       // Set config asynchronously 
+       protected class SetConfigCallback implements Runnable {
+               private Config config;
 
+               SetConfigCallback(Config config) {
+                       this.config = config;
+               }
+
+               public void run() {
+                       synchronized (this) {
+                               XMLSpider.this.config.setValue(config);
+                               db.store(XMLSpider.this.config);
+                               db.commit();
+                       }
+               }
+       }
+
        protected static class CallbackPrioritizer implements 
Comparator<Runnable> {
                public int compare(Runnable o1, Runnable o2) {
                        if (o1.getClass() == o2.getClass())
@@ -349,6 +372,8 @@
                                return 1;
                        else if (r instanceof OnSuccessCallback)
                                return 2;
+                       else if (r instanceof SetConfigCallback)
+                               return 3;
 
                        return -1;
                }
@@ -540,6 +565,22 @@
                        }
                }
                
+               // Load Config
+               {
+                       Query query = db.query();
+                       query.constrain(Config.class);
+                       @SuppressWarnings("unchecked")
+                       ObjectSet<Config> set = query.execute();
+
+                       if (set.hasNext())
+                               config = set.next();
+                       else {
+                               config = new Config(true);
+                               db.store(config);
+                               db.commit();
+                       }
+               }       
+               
                indexWriter = new IndexWriter(this);
                webInterface = new WebInterface(this);
 
@@ -750,8 +791,8 @@
                cfg.objectClass(MaxPageId.class).callConstructor(true);
                cfg.objectClass(Config.class).callConstructor(true);
 
-               cfg.activationDepth(1);
-               cfg.updateDepth(1);
+               cfg.activationDepth(3);
+               cfg.updateDepth(3);
                // cfg.automaticShutDown(false);
                cfg.queries().evaluationMode(QueryEvaluationMode.LAZY);
                cfg.diagnostic().addListener(new DiagnosticToConsole());

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to