Author: j16sdiz
Date: 2009-01-02 02:29:50 +0000 (Fri, 02 Jan 2009)
New Revision: 24870

Modified:
   trunk/plugins/XMLSpider/IndexWriter.java
   trunk/plugins/XMLSpider/XMLSpider.java
   trunk/plugins/XMLSpider/web/MainPage.java
Log:
proper transaction rollback: always get root from storage

Modified: trunk/plugins/XMLSpider/IndexWriter.java
===================================================================
--- trunk/plugins/XMLSpider/IndexWriter.java    2009-01-02 02:29:38 UTC (rev 
24869)
+++ trunk/plugins/XMLSpider/IndexWriter.java    2009-01-02 02:29:50 UTC (rev 
24870)
@@ -207,8 +207,8 @@
        private void makeSubIndices(Config config) throws Exception {
                Logger.normal(this, "Generating index...");
 
-               List<Term> termList = xmlSpider.getDbRoot().getTermList();
-               int termCount = xmlSpider.getDbRoot().getTermCount();
+               List<Term> termList = xmlSpider.getRoot().getTermList();
+               int termCount = xmlSpider.getRoot().getTermCount();
 
                indices = new Vector<String>();
                int prefix = (int) ((Math.log(termCount) - 
Math.log(config.getIndexMaxEntries())) / Math.log(16)) - 1;

Modified: trunk/plugins/XMLSpider/XMLSpider.java
===================================================================
--- trunk/plugins/XMLSpider/XMLSpider.java      2009-01-02 02:29:38 UTC (rev 
24869)
+++ trunk/plugins/XMLSpider/XMLSpider.java      2009-01-02 02:29:50 UTC (rev 
24870)
@@ -72,7 +72,7 @@
 public class XMLSpider implements FredPlugin, FredPluginHTTP, 
FredPluginThreadless, FredPluginVersioned, FredPluginL10n, USKCallback {
        public Config getConfig() {
                // always return a clone, never allow changing directly
-               return root.getConfig().clone();
+               return getRoot().getConfig().clone();
        }
 
        // Set config asynchronously
@@ -108,7 +108,7 @@
         */
        public void queueURI(FreenetURI uri, String comment, boolean force) {
                String sURI = uri.toString();
-               for (String ext : root.getConfig().getBadlistedExtensions())
+               for (String ext : 
getRoot().getConfig().getBadlistedExtensions())
                        if (sURI.endsWith(ext))
                                return; // be smart
 
@@ -125,7 +125,7 @@
                                }
                        }
 
-                       Page page = root.getPageByURI(uri, true, comment);
+                       Page page = getRoot().getPageByURI(uri, true, comment);
                        if (force && page.getStatus() != Status.QUEUED) {
                                page.setStatus(Status.QUEUED);
                                page.setComment(comment);
@@ -151,7 +151,7 @@
                                return;
                        synchronized (runningFetch) {
                                int running = runningFetch.size();
-                               int maxParallelRequests = 
root.getConfig().getMaxParallelRequests();
+                               int maxParallelRequests = 
getRoot().getConfig().getMaxParallelRequests();
 
                                if (running >= maxParallelRequests)
                                        return;
@@ -159,9 +159,9 @@
                                // Prepare to start
                                toStart = new 
ArrayList<ClientGetter>(maxParallelRequests - running);
                                
db.beginThreadTransaction(Storage.COOPERATIVE_TRANSACTION);
-                               root.sharedLockPages(Status.QUEUED);
+                               getRoot().sharedLockPages(Status.QUEUED);
                                try {
-                                       Iterator<Page> it = 
root.getPages(Status.QUEUED);
+                                       Iterator<Page> it = 
getRoot().getPages(Status.QUEUED);
 
                                        while (running + toStart.size() < 
maxParallelRequests && it.hasNext()) {
                                                Page page = it.next();
@@ -180,7 +180,7 @@
                                                }
                                        }
                                } finally {
-                                       root.unlockPages(Status.QUEUED);
+                                       getRoot().unlockPages(Status.QUEUED);
                                        db.endThreadTransaction();
                                }
                        }
@@ -327,8 +327,8 @@
                }
 
                public void run() {
-                       synchronized (root) {
-                               root.getConfig().setValue(config);
+                       synchronized (getRoot()) {
+                               getRoot().getConfig().setValue(config);
                        }
                }
        }
@@ -671,15 +671,14 @@
        }
 
        public short getPollingPriorityNormal() {
-               return (short) Math.min(RequestStarter.MINIMUM_PRIORITY_CLASS, 
root.getConfig().getRequestPriority() + 1);
+               return (short) Math.min(RequestStarter.MINIMUM_PRIORITY_CLASS, 
getRoot().getConfig().getRequestPriority() + 1);
        }
 
        public short getPollingPriorityProgress() {
-               return root.getConfig().getRequestPriority();
+               return getRoot().getConfig().getRequestPriority();
        }
 
        protected Storage db;
-       protected PerstRoot root;
 
        /**
         * Initializes Database
@@ -694,30 +693,30 @@
 
                db.open("XMLSpider-" + version + ".dbs");
 
-               root = (PerstRoot) db.getRoot();
+               PerstRoot root = (PerstRoot) db.getRoot();
                if (root == null)
-                       root = PerstRoot.createRoot(db);
+                       PerstRoot.createRoot(db);
 
                return db;
        }
 
-       public PerstRoot getDbRoot() {
-               return root;
+       public PerstRoot getRoot() {
+               return (PerstRoot) db.getRoot();
        }
 
        protected Page getPageByURI(FreenetURI uri) {
-               return root.getPageByURI(uri, false, null);
+               return getRoot().getPageByURI(uri, false, null);
        }
 
        protected Page getPageById(long id) {
-               return root.getPageById(id);
+               return getRoot().getPageById(id);
        }
 
        // language for I10N
        private LANGUAGE language;
 
        protected Term getTermByWord(String word, boolean create) {
-               return root.getTermByWord(word, create);
+               return getRoot().getTermByWord(word, create);
        }
 
        public String getString(String key) {

Modified: trunk/plugins/XMLSpider/web/MainPage.java
===================================================================
--- trunk/plugins/XMLSpider/web/MainPage.java   2009-01-02 02:29:38 UTC (rev 
24869)
+++ trunk/plugins/XMLSpider/web/MainPage.java   2009-01-02 02:29:50 UTC (rev 
24870)
@@ -189,7 +189,7 @@
 
        //-- Utilities
        private PageStatus getPageStatus(Status status) {
-               PerstRoot root = xmlSpider.getDbRoot();
+               PerstRoot root = xmlSpider.getRoot();
                synchronized (root) {
                        int count = root.getPageCount(status);
                        Iterator<Page> it = root.getPages(status);

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

Reply via email to