org.opencms.search
Class CmsIndexingThreadManager

java.lang.Object
  extended byjava.lang.Thread
      extended byorg.opencms.search.CmsIndexingThreadManager
All Implemented Interfaces:
java.lang.Runnable

public class CmsIndexingThreadManager
extends java.lang.Thread

Implements the management of indexing threads.

Since:
6.0.0
Version:
$Revision: 1.25 $
Author:
Carsten Weinholz, Alexander Kandzior

Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
CmsIndexingThreadManager(I_CmsReport report, long timeout, java.lang.String indexName, java.util.Map documentCache)
          Creates and starts a thread manager for indexing threads.
 
Method Summary
 void addDocument(A_CmsIndexResource res, java.lang.String locale, org.apache.lucene.document.Document doc)
          Caches the generated Document for the index resource to avoid multiple text extraction.
 void createIndexingThread(CmsObject cms, org.apache.lucene.index.IndexWriter writer, A_CmsIndexResource res, CmsSearchIndex index)
          Creates and starts a new indexing thread for a resource.
 void finished()
          Signals the thread manager that a thread has finished its job and will exit immediately.
 int getCounter()
          Gets the current thread (file) count.
 boolean isRunning()
          Returns if the indexing manager still have indexing threads.
 void reportStatistics()
          Writes statistical information to the report.
 void run()
          Starts the thread manager to look for non-terminated threads The thread manager looks all 10 minutes if threads are not returned and reports the number to the log file.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CmsIndexingThreadManager

public CmsIndexingThreadManager(I_CmsReport report,
                                long timeout,
                                java.lang.String indexName,
                                java.util.Map documentCache)
Creates and starts a thread manager for indexing threads.

Parameters:
report - the report to write out progress information
timeout - timeout after a thread is abandoned
indexName - the name of the index
documentCache - cache for storing indexed documents in (to avoid multiple text extraction)
Method Detail

addDocument

public void addDocument(A_CmsIndexResource res,
                        java.lang.String locale,
                        org.apache.lucene.document.Document doc)
Caches the generated Document for the index resource to avoid multiple text extraction.

Parameters:
res - the index resource to cache the Document for
locale - the locale to chache the Document fot
doc - the Document to cache

createIndexingThread

public void createIndexingThread(CmsObject cms,
                                 org.apache.lucene.index.IndexWriter writer,
                                 A_CmsIndexResource res,
                                 CmsSearchIndex index)
Creates and starts a new indexing thread for a resource.

After an indexing thread was started, the manager suspends itself and waits for an amount of time specified by the timeout value. If the timeout value is reached, the indexing thread is aborted by an interrupt signal.

Parameters:
cms - the cms object
writer - the write to write the index
res - the resource
index - the index

finished

public void finished()
Signals the thread manager that a thread has finished its job and will exit immediately.


getCounter

public int getCounter()
Gets the current thread (file) count.

Returns:
the current thread count

isRunning

public boolean isRunning()
Returns if the indexing manager still have indexing threads.

Returns:
true if the indexing manager still have indexing threads

reportStatistics

public void reportStatistics()
Writes statistical information to the report.

The method reports the total number of threads started (equals to the number of indexed files), the number of returned threads (equals to the number of successfully indexed files), and the number of abandoned threads (hanging threads reaching the timeout).


run

public void run()
Starts the thread manager to look for non-terminated threads

The thread manager looks all 10 minutes if threads are not returned and reports the number to the log file.

See Also:
Runnable.run()