svn commit: r513587 - in /xml/xindice/trunk: java/src/org/apache/xindice/core/indexer/IndexManager.java status.xml

[email protected]
Newsgroups gmane.text.xml.xindice.devel
Message-ID <[email protected]>
Author: vgritsenko
Date: Thu Mar  1 18:08:50 2007
New Revision: 513587

URL: http://svn.apache.org/viewvc?view=rev&rev=513587
Log:
            <action dev="VG" type="fix" fixes-bug="41710" due-to="Natalia Shilenkova">
                Ensure that background indexing processes are complete before
                shutting database down.
            </action>


Modified:
    xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java
    xml/xindice/trunk/status.xml

Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java?view=diff&rev=513587&r1=513586&r2=513587
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java Thu Mar  1 18:08:50 2007
@@ -63,7 +63,7 @@
     private static final IndexerInfo[] EMPTY_INDEXERS = new IndexerInfo[0];
 
     private static final String INDEX = "index";
-    private static final String NAME = "name";
+    private static final String NAME  = "name";
     private static final String CLASS = "class";
 
     private static final int STATUS_READY = 0;
@@ -84,6 +84,8 @@
     private SymbolTable symbols;
     private final List newIndexers = new ArrayList(); // of IndexerInfo
 
+    private int taskCount;                      // counter of scheduled tasks
+    private final Object lock = new Object();   // lock object for manipulating taskCounter
 
     /**
      * Create IndexManager for a given collection
@@ -215,6 +217,17 @@
      * Closes all indexers managed by this index manager.
      */
     public synchronized void close() {
+        // wait for all scheduled tasks to finish
+        synchronized(lock) {
+            while (taskCount > 0) {
+                try {
+                    lock.wait();
+                } catch (InterruptedException e) {
+                    // ignore
+                }
+            }
+        }
+        // close all indexers
         for (int i = 0; i < idxList.length; i++) {
             try {
                 idxList[i].indexer.close();
@@ -246,7 +259,26 @@
                 synchronized (newIndexers) {
                     newIndexers.add(info);
                 }
-                timer.schedule(new PopulateIndexersTimerTask(this), 0);
+
+                synchronized (lock) {
+                    taskCount++;
+                    try {
+                        // Schedule new task
+                        timer.schedule(new PopulateIndexersTimerTask(), 0);
+                    } catch (RuntimeException e) {
+                        // If failed to schedule the task, decrease the counter.
+                        taskCount--;
+                        throw e;
+                    } catch (Error e) {
+                        // If failed to schedule the task, decrease the counter.
+                        taskCount--;
+                        throw e;
+                    }
+
+                    if (log.isDebugEnabled()) {
+                        log.debug("Scheduled new task, count is " + taskCount);
+                    }
+                }
             } else {
                 info.status = STATUS_READY;
                 idx.open();
@@ -610,19 +642,23 @@
         }
     }
 
-    private static class PopulateIndexersTimerTask extends TimerTask {
-        private IndexManager mgr;
-
-        public PopulateIndexersTimerTask(IndexManager mgr) {
-            this.mgr = mgr;
-        }
-
+    private class PopulateIndexersTimerTask extends TimerTask {
         public void run() {
             try {
-                mgr.populateNewIndexers();
+                populateNewIndexers();
             } catch (DBException e) {
                 if (log.isWarnEnabled()) {
                     log.warn("ignored exception", e);
+                }
+            } finally {
+                synchronized (lock) {
+                    taskCount--;
+                    if (log.isDebugEnabled()) {
+                        log.debug("Task completed, count is " + taskCount);
+                    }
+                    if (taskCount == 0) {
+                        lock.notifyAll();
+                    }
                 }
             }
         }

Modified: xml/xindice/trunk/status.xml
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/status.xml?view=diff&rev=513587&r1=513586&r2=513587
==============================================================================
--- xml/xindice/trunk/status.xml (original)
+++ xml/xindice/trunk/status.xml Thu Mar  1 18:08:50 2007
@@ -117,7 +117,11 @@
     </todo>
 
     <changes>
-        <release version="1.1b5-dev" date="Feb 22 2007">
+        <release version="1.1b5-dev" date="Mar 1 2007">
+            <action dev="VG" type="fix" fixes-bug="41710" due-to="Natalia Shilenkova">
+                Ensure that background indexing processes are complete before
+                shutting database down.
+            </action>
             <action dev="VG" type="fix" fixes-bug="41605" due-to="Natalia Shilenkova">
                 Fix support of uncompressed collections. Add test cases.
             </action>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.