org.compass.core.lucene.engine.manager
Class DefaultLuceneSearchEngineIndexManager

java.lang.Object
  extended by org.compass.core.lucene.engine.manager.DefaultLuceneSearchEngineIndexManager
All Implemented Interfaces:
SearchEngineIndexManager, LuceneSearchEngineIndexManager

public class DefaultLuceneSearchEngineIndexManager
extends Object
implements LuceneSearchEngineIndexManager

Author:
kimchy

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.compass.core.engine.SearchEngineIndexManager
SearchEngineIndexManager.IndexOperationCallback, SearchEngineIndexManager.IndexOperationPlan, SearchEngineIndexManager.ReplaceIndexCallback
 
Constructor Summary
DefaultLuceneSearchEngineIndexManager(LuceneSearchEngineFactory searchEngineFactory, LuceneSearchEngineStore searchEngineStore)
           
 
Method Summary
 String[] calcSubIndexes(String[] subIndexes, String[] aliases, Class[] types)
          Returns the sub indexes the intersect with the given sub indexes and aliases provided.
 void checkAndClearIfNotifiedAllToClearCache()
          Manual check if the notified to clear the cache globally.
 void cleanIndex()
          Cleans the index from data (by deleting and creating an empty one).
 void cleanIndex(String subIndex)
          Cleans the index from data (by deleting and creating an empty one).
 void clearCache()
          Clears any internal caching done by the index.
 void clearCache(String subIndex)
          Clears any internal caching done by the index for the specified sub-index.
 void close()
          Closes the index manager.
 void createIndex()
          Creates an index data.
 void deleteIndex()
          Deletes the index.
protected  void doOperate(SearchEngineIndexManager.IndexOperationCallback callback)
           
protected  void doReplaceIndex(SearchEngineIndexManager indexManager, SearchEngineIndexManager.ReplaceIndexCallback callback)
           
 Directory getDirectory(String subIndex)
           
 ExecutorManager getExecutorManager()
          Returns an executor manager that can be used to execute / submit tasks.
 IndexHoldersCache getIndexHoldersCache()
           
 IndexWritersManager getIndexWritersManager()
           
 LuceneSearchEngineFactory getSearchEngineFactory()
           
 LuceneSettings getSettings()
           
 LuceneSearchEngineStore getStore()
           
 String[] getSubIndexes()
          Returns the sub indexes that Compass handles.
 TransactionContext getTransactionContext()
           
 boolean indexExists()
          Returns true if the index exists.
 void invalidateCache()
          Invalidates any internal caching done by the index.
 void invalidateCache(String subIndex)
          Invalidates any internal caching done by the index for the specified sub-index.
 boolean isCached()
          Returns true if one of the sub indexes is cached.
 boolean isCached(String subIndex)
          Returns true if the sub index is cached.
 boolean isLocked()
          Returns true if one of the sub indexes is locked.
 boolean isLocked(String subIndex)
          Returns true if the given sub index is locked.
 boolean isRunning()
          Returns true if the index manage is running
 void notifyAllToClearCache()
          Notifies all the compass instances that are working with the same index to clear cache.
 IndexSearcher openIndexSearcher(IndexReader reader)
           
 MultiSearcher openMultiSearcher(Searchable[] searchers)
           
 void operate(SearchEngineIndexManager.IndexOperationCallback callback)
          A general api for index operations.
 void performScheduledTasks()
          Performs scheduled tasks that are usually derived basde on the actual index storage used.
 String[] polyCalcSubIndexes(String[] subIndexes, String[] aliases, Class[] types)
          Returns the sub indexes that intersect with the given sub indexes, aliases and types.
 void refreshCache()
          Refresh any internal caching done by the index.
 void refreshCache(String subIndex)
          Refresh any internal caching done by the index for the specified sub-index.
 void releaseLock(String subIndex)
          Releases a lock for the given sub index.
 void releaseLocks()
          Releases all the locks held over all the possbile sub indexes.
 void replaceIndex(SearchEngineIndexManager indexManager, SearchEngineIndexManager.ReplaceIndexCallback callback)
          Replaces the index data that is used by the current instance, with the one that is pointed by the given indexManager.
 boolean requiresAsyncTransactionalContext()
          Returns true if a transaction needs to be started when performing operations with this store.
 void setWaitForCacheInvalidationBeforeSecondStep(long timeToWaitInMillis)
          Since there might be several instances of Compass running against the same index, they need to be globally notified to invalidate the cache after the commit lock has been obtained for the second step on the SearchEngineIndexManager.operate(org.compass.core.engine.SearchEngineIndexManager.IndexOperationCallback) or SearchEngineIndexManager.replaceIndex(org.compass.core.engine.SearchEngineIndexManager, org.compass.core.engine.SearchEngineIndexManager.ReplaceIndexCallback).
 void start()
          Starts the index manager
 void stop()
          Stops / closes the index manager
 boolean subIndexExists(String subIndex)
          Returns true if the sub index exists.
 boolean supportsConcurrentCommits()
          Returns true if the index store supports concurrent commits.
 boolean supportsConcurrentOperations()
          Returns true if the index store supports concurrent operations.
 boolean verifyIndex()
          Verify the index data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultLuceneSearchEngineIndexManager

public DefaultLuceneSearchEngineIndexManager(LuceneSearchEngineFactory searchEngineFactory,
                                             LuceneSearchEngineStore searchEngineStore)
Method Detail

start

public void start()
Description copied from interface: SearchEngineIndexManager
Starts the index manager

Specified by:
start in interface SearchEngineIndexManager

stop

public void stop()
Description copied from interface: SearchEngineIndexManager
Stops / closes the index manager

Specified by:
stop in interface SearchEngineIndexManager

isRunning

public boolean isRunning()
Description copied from interface: SearchEngineIndexManager
Returns true if the index manage is running

Specified by:
isRunning in interface SearchEngineIndexManager

createIndex

public void createIndex()
                 throws SearchEngineException
Description copied from interface: SearchEngineIndexManager
Creates an index data. If exists, deletes it and creates a new one.

Specified by:
createIndex in interface SearchEngineIndexManager
Throws:
SearchEngineException

deleteIndex

public void deleteIndex()
                 throws SearchEngineException
Description copied from interface: SearchEngineIndexManager
Deletes the index.

Specified by:
deleteIndex in interface SearchEngineIndexManager
Throws:
SearchEngineException

cleanIndex

public void cleanIndex()
                throws SearchEngineException
Description copied from interface: SearchEngineIndexManager
Cleans the index from data (by deleting and creating an empty one).

Specified by:
cleanIndex in interface SearchEngineIndexManager
Throws:
SearchEngineException

cleanIndex

public void cleanIndex(String subIndex)
                throws SearchEngineException
Description copied from interface: SearchEngineIndexManager
Cleans the index from data (by deleting and creating an empty one).

Specified by:
cleanIndex in interface SearchEngineIndexManager
Throws:
SearchEngineException

verifyIndex

public boolean verifyIndex()
                    throws SearchEngineException
Description copied from interface: SearchEngineIndexManager
Verify the index data. If exists, does nothing. If it doesn't exists, creates it. Returns true if the index was created. If the index exists, and it's LuceneEnvironment.SearchEngineIndex.USE_COMPOUND_FILE changed it's settings, will compound / un-compound the index accordingly.

Specified by:
verifyIndex in interface SearchEngineIndexManager
Throws:
SearchEngineException

indexExists

public boolean indexExists()
                    throws SearchEngineException
Description copied from interface: SearchEngineIndexManager
Returns true if the index exists.

Specified by:
indexExists in interface SearchEngineIndexManager
Throws:
SearchEngineException

operate

public void operate(SearchEngineIndexManager.IndexOperationCallback callback)
             throws SearchEngineException
Description copied from interface: SearchEngineIndexManager
A general api for index operations. Provides the ability to perform safe operations using the SearchEngineIndexManager.IndexOperationCallback.

Specified by:
operate in interface SearchEngineIndexManager
Throws:
SearchEngineException

doOperate

protected void doOperate(SearchEngineIndexManager.IndexOperationCallback callback)
                  throws SearchEngineException
Throws:
SearchEngineException

replaceIndex

public void replaceIndex(SearchEngineIndexManager indexManager,
                         SearchEngineIndexManager.ReplaceIndexCallback callback)
                  throws SearchEngineException
Description copied from interface: SearchEngineIndexManager
Replaces the index data that is used by the current instance, with the one that is pointed by the given indexManager. A callback interface can be registered if the index is dynamically created.

The replace process is safe, in terms that it will aquire dirty locks and read locks, so the index can be safely replaced while it is being used.

Specified by:
replaceIndex in interface SearchEngineIndexManager
Throws:
SearchEngineException

doReplaceIndex

protected void doReplaceIndex(SearchEngineIndexManager indexManager,
                              SearchEngineIndexManager.ReplaceIndexCallback callback)
                       throws SearchEngineException
Throws:
SearchEngineException

close

public void close()
Description copied from interface: SearchEngineIndexManager
Closes the index manager. Used by compass, probably not a good idea to call it.

Specified by:
close in interface SearchEngineIndexManager

isCached

public boolean isCached(String subIndex)
                 throws SearchEngineException
Description copied from interface: SearchEngineIndexManager
Returns true if the sub index is cached.

Specified by:
isCached in interface SearchEngineIndexManager
Throws:
SearchEngineException

isCached

public boolean isCached()
                 throws SearchEngineException
Description copied from interface: SearchEngineIndexManager
Returns true if one of the sub indexes is cached.

Specified by:
isCached in interface SearchEngineIndexManager
Throws:
SearchEngineException

clearCache

public void clearCache(String subIndex)
                throws SearchEngineException
Description copied from interface: SearchEngineIndexManager
Clears any internal caching done by the index for the specified sub-index. Closes any cached resources.

Specified by:
clearCache in interface SearchEngineIndexManager
Throws:
SearchEngineException

clearCache

public void clearCache()
                throws SearchEngineException
Description copied from interface: SearchEngineIndexManager
Clears any internal caching done by the index. Closes any cached resources.

Specified by:
clearCache in interface SearchEngineIndexManager
Throws:
SearchEngineException

invalidateCache

public void invalidateCache(String subIndex)
                     throws SearchEngineException
Description copied from interface: SearchEngineIndexManager
Invalidates any internal caching done by the index for the specified sub-index. More lightweight than SearchEngineIndexManager.clearCache(String).

Specified by:
invalidateCache in interface SearchEngineIndexManager
Throws:
SearchEngineException

invalidateCache

public void invalidateCache()
                     throws SearchEngineException
Description copied from interface: SearchEngineIndexManager
Invalidates any internal caching done by the index. More lightweight than SearchEngineIndexManager.clearCache().

Specified by:
invalidateCache in interface SearchEngineIndexManager
Throws:
SearchEngineException

refreshCache

public void refreshCache(String subIndex)
                  throws SearchEngineException
Description copied from interface: SearchEngineIndexManager
Refresh any internal caching done by the index for the specified sub-index.

Specified by:
refreshCache in interface SearchEngineIndexManager
Throws:
SearchEngineException

refreshCache

public void refreshCache()
                  throws SearchEngineException
Description copied from interface: SearchEngineIndexManager
Refresh any internal caching done by the index.

Specified by:
refreshCache in interface SearchEngineIndexManager
Throws:
SearchEngineException

notifyAllToClearCache

public void notifyAllToClearCache()
                           throws SearchEngineException
Description copied from interface: SearchEngineIndexManager
Notifies all the compass instances that are working with the same index to clear cache.

Specified by:
notifyAllToClearCache in interface SearchEngineIndexManager
Throws:
SearchEngineException

checkAndClearIfNotifiedAllToClearCache

public void checkAndClearIfNotifiedAllToClearCache()
                                            throws SearchEngineException
Description copied from interface: SearchEngineIndexManager
Manual check if the notified to clear the cache globally. If it does, will clear the cache.

Specified by:
checkAndClearIfNotifiedAllToClearCache in interface SearchEngineIndexManager
Throws:
SearchEngineException

openIndexSearcher

public IndexSearcher openIndexSearcher(IndexReader reader)
Specified by:
openIndexSearcher in interface LuceneSearchEngineIndexManager

openMultiSearcher

public MultiSearcher openMultiSearcher(Searchable[] searchers)
                                throws IOException
Specified by:
openMultiSearcher in interface LuceneSearchEngineIndexManager
Throws:
IOException

getStore

public LuceneSearchEngineStore getStore()
Specified by:
getStore in interface LuceneSearchEngineIndexManager

getIndexHoldersCache

public IndexHoldersCache getIndexHoldersCache()
Specified by:
getIndexHoldersCache in interface LuceneSearchEngineIndexManager

getIndexWritersManager

public IndexWritersManager getIndexWritersManager()
Specified by:
getIndexWritersManager in interface LuceneSearchEngineIndexManager

getDirectory

public Directory getDirectory(String subIndex)
Specified by:
getDirectory in interface LuceneSearchEngineIndexManager

performScheduledTasks

public void performScheduledTasks()
                           throws SearchEngineException
Description copied from interface: SearchEngineIndexManager
Performs scheduled tasks that are usually derived basde on the actual index storage used.

This API will be called when disabling the automatic scheduler that comes built in with Compass.

Specified by:
performScheduledTasks in interface SearchEngineIndexManager
Throws:
SearchEngineException

getSubIndexes

public String[] getSubIndexes()
Description copied from interface: SearchEngineIndexManager
Returns the sub indexes that Compass handles.

Specified by:
getSubIndexes in interface SearchEngineIndexManager

subIndexExists

public boolean subIndexExists(String subIndex)
Description copied from interface: SearchEngineIndexManager
Returns true if the sub index exists.

Specified by:
subIndexExists in interface SearchEngineIndexManager

isLocked

public boolean isLocked()
                 throws SearchEngineException
Description copied from interface: SearchEngineIndexManager
Returns true if one of the sub indexes is locked.

Specified by:
isLocked in interface SearchEngineIndexManager
Throws:
SearchEngineException

isLocked

public boolean isLocked(String subIndex)
                 throws SearchEngineException
Description copied from interface: SearchEngineIndexManager
Returns true if the given sub index is locked.

Specified by:
isLocked in interface SearchEngineIndexManager
Throws:
SearchEngineException

releaseLocks

public void releaseLocks()
                  throws SearchEngineException
Description copied from interface: SearchEngineIndexManager
Releases all the locks held over all the possbile sub indexes.

Specified by:
releaseLocks in interface SearchEngineIndexManager
Throws:
SearchEngineException

releaseLock

public void releaseLock(String subIndex)
                 throws SearchEngineException
Description copied from interface: SearchEngineIndexManager
Releases a lock for the given sub index.

Specified by:
releaseLock in interface SearchEngineIndexManager
Throws:
SearchEngineException

calcSubIndexes

public String[] calcSubIndexes(String[] subIndexes,
                               String[] aliases,
                               Class[] types)
Description copied from interface: SearchEngineIndexManager
Returns the sub indexes the intersect with the given sub indexes and aliases provided. The types are translated to aliases and retuned as well.

Specified by:
calcSubIndexes in interface SearchEngineIndexManager

polyCalcSubIndexes

public String[] polyCalcSubIndexes(String[] subIndexes,
                                   String[] aliases,
                                   Class[] types)
Description copied from interface: SearchEngineIndexManager
Returns the sub indexes that intersect with the given sub indexes, aliases and types. Types are translated to the matching aliases. Any extending aliases of the given aliases (or types) are added as well.

Specified by:
polyCalcSubIndexes in interface SearchEngineIndexManager

requiresAsyncTransactionalContext

public boolean requiresAsyncTransactionalContext()
Description copied from interface: SearchEngineIndexManager
Returns true if a transaction needs to be started when performing operations with this store.

Specified by:
requiresAsyncTransactionalContext in interface SearchEngineIndexManager

supportsConcurrentOperations

public boolean supportsConcurrentOperations()
Description copied from interface: SearchEngineIndexManager
Returns true if the index store supports concurrent operations.

Specified by:
supportsConcurrentOperations in interface SearchEngineIndexManager

supportsConcurrentCommits

public boolean supportsConcurrentCommits()
Description copied from interface: SearchEngineIndexManager
Returns true if the index store supports concurrent commits.

Specified by:
supportsConcurrentCommits in interface SearchEngineIndexManager

setWaitForCacheInvalidationBeforeSecondStep

public void setWaitForCacheInvalidationBeforeSecondStep(long timeToWaitInMillis)
Description copied from interface: LuceneSearchEngineIndexManager
Since there might be several instances of Compass running against the same index, they need to be globally notified to invalidate the cache after the commit lock has been obtained for the second step on the SearchEngineIndexManager.operate(org.compass.core.engine.SearchEngineIndexManager.IndexOperationCallback) or SearchEngineIndexManager.replaceIndex(org.compass.core.engine.SearchEngineIndexManager, org.compass.core.engine.SearchEngineIndexManager.ReplaceIndexCallback).

If directly set to 0, will not wait.

Specified by:
setWaitForCacheInvalidationBeforeSecondStep in interface LuceneSearchEngineIndexManager

getSettings

public LuceneSettings getSettings()
Specified by:
getSettings in interface LuceneSearchEngineIndexManager

getExecutorManager

public ExecutorManager getExecutorManager()
Description copied from interface: LuceneSearchEngineIndexManager
Returns an executor manager that can be used to execute / submit tasks.

Specified by:
getExecutorManager in interface LuceneSearchEngineIndexManager

getTransactionContext

public TransactionContext getTransactionContext()
Specified by:
getTransactionContext in interface LuceneSearchEngineIndexManager

getSearchEngineFactory

public LuceneSearchEngineFactory getSearchEngineFactory()
Specified by:
getSearchEngineFactory in interface LuceneSearchEngineIndexManager


Copyright (c) 2004-2009 The Compass Project.