Author: vgritsenko
Date: Fri Nov  3 20:25:44 2006
New Revision: 471113

URL: http://svn.apache.org/viewvc?view=rev&rev=471113
Log:
<action dev="VG" type="fix" fixes-bug="23571">
  Stop timer thread on database shutdown.
</action>


Modified:
    xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java
    xml/xindice/trunk/java/src/org/apache/xindice/core/Database.java
    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/Collection.java
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java?view=diff&rev=471113&r1=471112&r2=471113
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java 
(original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java Fri Nov  
3 20:25:44 2006
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
- * CVS $Id$
+ * $Id$
  */
 
 package org.apache.xindice.core;
@@ -66,7 +66,7 @@
  * the Filer storage implementation, and the Indexes associated with
  * the Collection.
  *
- * @version CVS $Revision$, $Date$
+ * @version $Revision$, $Date$
  */
 public class Collection extends CollectionManager
                         implements Named, DBObject, Configurable {
@@ -1044,9 +1044,8 @@
      * @return A parsed DOM document or null if failure
      */
     private Document parseDocument(Key key, String xml) throws DBException {
-        Document doc = null;
         try {
-            doc = DOMParser.toDocument(xml);
+            Document doc = DOMParser.toDocument(xml);
 
             // Have to move it to Xindice DOM for XMLObject AutoLinking
             byte[] b = DOMCompressor.Compress(doc, symbols);
@@ -1055,11 +1054,12 @@
             if (documentCache != null) {
                 documentCache.putDocument(this, key, b);
             }
+
+            return doc;
         } catch (Exception e) {
             throw new DBException(FaultCodes.COL_DOCUMENT_MALFORMED,
                                   "Unable to parse document '" + key + "' in 
'" + getCanonicalName() + "'", e);
         }
-        return doc;
     }
 
     /*
@@ -1121,7 +1121,7 @@
          *        otherwise without headers, for the BTree.
          */
 
-        byte[] documentBytes = null;
+        byte[] documentBytes;
 
         if (compressed) {
             try {
@@ -1240,7 +1240,7 @@
         }
 
         checkFiler(FaultCodes.QRY_STYLE_NOT_FOUND);
-        Key[] k = null;
+        Key[] k;
         if (key instanceof Key[]) {
             k = (Key[]) key;
         } else {
@@ -1435,7 +1435,7 @@
 
             // Index Manager
             try {
-                indexManager = new IndexManager(this);
+                indexManager = new IndexManager(this, 
getDatabase().getTimer());
                 Configuration idxConfig = config.getChild(INDEXES, true);
                 indexManager.setConfig(idxConfig);
             } catch (Exception e) {
@@ -1531,7 +1531,7 @@
         // update the meta data if necessary
         if (isMetaEnabled()) {
             MetaSystemCollection metacol = getMetaSystemCollection();
-            MetaData meta = null;
+            MetaData meta;
             try {
                 meta = metacol.getCollectionMeta(this);
             } catch (DBException e) {
@@ -1563,7 +1563,6 @@
                 if (log.isWarnEnabled()) {
                     log.warn("Error setting meta for collection '" + 
getCanonicalName() + "'", e);
                 }
-                return;
             }
         }
     }

Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/Database.java
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/Database.java?view=diff&rev=471113&r1=471112&r2=471113
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/Database.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/Database.java Fri Nov  3 
20:25:44 2006
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
- * CVS $Id$
+ * $Id$
  */
 
 package org.apache.xindice.core;
@@ -39,13 +39,15 @@
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Timer;
 
 /**
  * Database is the primary container for the Xindice Database Engine.
  *
- * @version CVS $Revision$, $Date$
+ * @version $Revision$, $Date$
  */
-public final class Database extends Collection implements Named {
+public final class Database extends Collection
+                            implements Named {
 
     private static final Log log = LogFactory.getLog(Database.class);
 
@@ -61,6 +63,7 @@
 
     private static final Map databases = new HashMap(); // String to Database
     private static final DatabaseShutdownHandler shutdownHandler = new 
DatabaseShutdownHandler();
+
     static {
         // sets up our golbal observer. will automatically flush document
         // changes to disk.
@@ -150,11 +153,16 @@
     private FileOutputStream lock;
     private boolean closed;
 
+    /** Shared timer instance for this database's IndexManagers */
+    private Timer timer;
+
+
     public Database() {
         super();
         this.docCache = new DocumentCache();
         this.engine = new QueryEngine(this);
         shutdownHandler.registerDatabase(this);
+        timer = new Timer(false);
         closed = false;
     }
 
@@ -192,11 +200,16 @@
             synchronized (databases) {
                 databases.remove(getName());
             }
+
+            // Stop the timer thread
+            timer.cancel();
+
             closed = true;
         }
 
         return true;
     }
+
     /**
      * @see org.apache.xindice.core.DBObject#close()
      * @see org.apache.xindice.core.Database#close(boolean removeFromShutdown)
@@ -265,6 +278,13 @@
      */
     public SystemCollection getSystemCollection() {
         return systemCollection;
+    }
+
+    /**
+     * Return database's timer instance.
+     */
+    protected Timer getTimer() {
+        return timer;
     }
 
     /**

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=471113&r1=471112&r2=471113
==============================================================================
--- 
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 
Fri Nov  3 20:25:44 2006
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
- * CVS $Id$
+ * $Id$
  */
 
 package org.apache.xindice.core.indexer;
@@ -44,15 +44,15 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Timer;
 import java.util.TimerTask;
 import java.util.WeakHashMap;
+import java.util.Timer;
 
 /**
  * IndexManager is a class that manages Indexes.  Good description, eh?
  * I should win a Pulitzer Prize for that one.
  *
- * @version CVS $Revision$, $Date$
+ * @version $Revision$, $Date$
  */
 public final class IndexManager extends SimpleConfigurable {
 
@@ -72,19 +72,17 @@
     private static final int ACTION_UPDATE = 1;
     private static final int ACTION_DELETE = 2;
 
-    // FIXME: Bug#23571: Timer is not disposed on webapp shutdown. Need to 
replace with cron service. 
-    private static final Timer timer = new Timer(true);
-
-    private Map patternMap = new HashMap(); // IndexPattern to IndexerInfo
-    private Map indexes = new HashMap(); // String to IndexerInfo
-    private Map bestIndexers = new HashMap(); // String to SoftRefTab
-    // of IndexPattern to Indexer
+    private Map patternMap = new HashMap();   // IndexPattern to IndexerInfo
+    private Map indexes = new HashMap();      // String to IndexerInfo
+    private Map bestIndexers = new HashMap(); // String to Map of IndexPattern 
to Indexer
 
     private IndexerInfo[] idxList = EMPTY_INDEXERS;
 
     private Collection collection;
+    private Timer timer;
     private SymbolTable symbols;
-    private List newIndexers = new ArrayList(); // of IndexerInfo
+    private final List newIndexers = new ArrayList(); // of IndexerInfo
+
 
     /**
      * Create IndexManager for a given collection
@@ -92,9 +90,10 @@
      * @param collection Collection for this IndexManager
      * @throws DBException if can't get collection's symbols
      */
-    public IndexManager(Collection collection) throws DBException {
+    public IndexManager(Collection collection, Timer timer) throws DBException 
{
         this.collection = collection;
         this.symbols = collection.getSymbols();
+        this.timer = timer;
     }
 
     /**
@@ -288,7 +287,7 @@
     }
 
     private void populateNewIndexers() throws DBException {
-        IndexerInfo[] list = null;
+        IndexerInfo[] list;
         synchronized (newIndexers) {
             list = (IndexerInfo[]) newIndexers.toArray(EMPTY_INDEXERS);
             newIndexers.clear();

Modified: xml/xindice/trunk/status.xml
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/status.xml?view=diff&rev=471113&r1=471112&r2=471113
==============================================================================
--- xml/xindice/trunk/status.xml (original)
+++ xml/xindice/trunk/status.xml Fri Nov  3 20:25:44 2006
@@ -74,6 +74,9 @@
 
     <changes>
         <release version="1.1b5-dev" date="Oct 27 2006">
+            <action dev="VG" type="fix" fixes-bug="23571">
+                Stop timer thread on database shutdown.
+            </action>
             <action dev="VG" type="fix" fixes-bug="31159">
                 Add pagecount configuration parameter to Paged based
                 filers: HashFiler, BTreeFiler.


Reply via email to