jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r634632 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene: IndexingQueue.java MultiIndex.java
Date Fri, 07 Mar 2008 12:24:15 GMT
Author: mreutegg
Date: Fri Mar  7 04:24:15 2008
New Revision: 634632

URL: http://svn.apache.org/viewvc?rev=634632&view=rev
Log:
JCR-1459: NullPointerException on startup if IndexingQueue has pending nodes

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingQueue.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingQueue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingQueue.java?rev=634632&r1=634631&r2=634632&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingQueue.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingQueue.java
Fri Mar  7 04:24:15 2008
@@ -53,12 +53,29 @@
     private final Map pendingDocuments = new HashMap();
 
     /**
+     * Flag that indicates whether this indexing queue had been
+     * {@link #initialize(MultiIndex) initialized}.
+     */
+    private volatile boolean initialized = false;
+
+    /**
      * Creates an indexing queue.
      *
      * @param queueStore the store where to read the pending extraction jobs.
      */
-    IndexingQueue(IndexingQueueStore queueStore, MultiIndex index) {
+    IndexingQueue(IndexingQueueStore queueStore) {
         this.queueStore = queueStore;
+    }
+
+    /**
+     * Initializes the indexing queue.
+     *
+     * @param index the multi index this indexing queue belongs to.
+     */
+    void initialize(MultiIndex index) {
+        if (initialized) {
+            throw new IllegalStateException("already initialized");
+        }
         String[] uuids = queueStore.getPending();
         for (int i = 0; i < uuids.length; i++) {
             try {
@@ -78,6 +95,7 @@
                 }
             }
         }
+        initialized = true;
     }
 
     /**
@@ -86,6 +104,7 @@
      * @return the {@link Document}s that are finished.
      */
     public Document[] getFinishedDocuments() {
+        checkInitialized();
         List finished = new ArrayList();
         synchronized (this) {
             finished.addAll(pendingDocuments.values());
@@ -113,6 +132,7 @@
      *                     queue.
      */
     public synchronized Document removeDocument(String uuid) throws IOException {
+        checkInitialized();
         Document doc = (Document) pendingDocuments.remove(uuid);
         if (doc != null) {
             queueStore.removeUUID(uuid);
@@ -133,6 +153,7 @@
      *                     queue.
      */
     public synchronized Document addDocument(Document doc) throws IOException {
+        checkInitialized();
         String uuid = doc.get(FieldNames.UUID);
         Document existing = (Document) pendingDocuments.put(uuid, doc);
         log.debug("added node {}. New size of indexing queue: {}",
@@ -151,6 +172,7 @@
      * @throws IOException if an error occurs while closing this queue.
      */
     public synchronized void close() throws IOException {
+        checkInitialized();
         // go through pending documents and close readers
         Iterator it = pendingDocuments.values().iterator();
         while (it.hasNext()) {
@@ -168,6 +190,17 @@
      *                     disk.
      */
     public synchronized void commit() throws IOException {
+        checkInitialized();
         queueStore.commit();
+    }
+
+    /**
+     * Checks if this indexing queue is initialized and otherwise throws a
+     * {@link IllegalStateException}.
+     */
+    private void checkInitialized() {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java?rev=634632&r1=634631&r2=634632&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
Fri Mar  7 04:24:15 2008
@@ -261,7 +261,7 @@
         }
 
         // initialize indexing queue
-        this.indexingQueue = new IndexingQueue(store, this);
+        this.indexingQueue = new IndexingQueue(store);
 
         // open persistent indexes
         for (int i = 0; i < indexNames.size(); i++) {
@@ -297,6 +297,8 @@
         } finally {
             reader.close();
         }
+
+        indexingQueue.initialize(this);
 
         redoLogApplied = redoLog.hasEntries();
 



Mime
View raw message