Class SearchIndexerImpl
- java.lang.Object
-
- edu.cornell.mannlib.vitro.webapp.searchindex.SearchIndexerImpl
-
- All Implemented Interfaces:
Application.Component,Application.Module,SearchIndexer
public class SearchIndexerImpl extends Object implements SearchIndexer
An implementation of the SearchIndexer interface. This implementation uses a single-threaded task queue to permit indexing to run one at a time in a "background" thread. The task queue is controlled by a scheduler that allows us to suspend incoming tasks (pause). A thread pool is available so the tasks can create small units of work to be run in parallel. Each task should block until all of its work units are complete, to preserve the pattern of running one task at a time. The number of threads in the thread pool is specified in the application setup file.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceSearchIndexerImpl.IndexerConfigInterface for tasks to access the Indexer configstatic classSearchIndexerImpl.ListenerListA simple thread-safe list of event listeners.static interfaceSearchIndexerImpl.Taskstatic classSearchIndexerImpl.WorkerThreadPoolA thread pool for handling many small units of work submitted by a task.-
Nested classes/interfaces inherited from interface edu.cornell.mannlib.vitro.webapp.modules.Application.Component
Application.Component.LifecycleState
-
Nested classes/interfaces inherited from interface edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexer
SearchIndexer.Event, SearchIndexer.Listener
-
-
Constructor Summary
Constructors Constructor Description SearchIndexerImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(SearchIndexer.Listener listener)Add this listener, allowing it to receive events from the indexer.SearchIndexerStatusgetStatus()What is the current status of the indexer? Still valid after shutdown().voidpause()Stop processing new tasks.voidrebuildIndex()Remove all of the existing documents in the index, and schedule updates for all of the individuals in the model.voidremoveListener(SearchIndexer.Listener listener)Remove this listener, meaning that it will no longer receive events from the indexer.voidscheduleUpdatesForStatements(List<org.apache.jena.rdf.model.Statement> changes)Update any search documents that are affected by these statements.voidscheduleUpdatesForUris(Collection<String> uris)Update the search documents for these URIs.voidsetThreadPoolSize(String size)voidshutdown(Application application)Stop processing and release resources.voidstartup(Application application, ComponentStartupStatus ss)Start processing.voidunpause()Resume processing new tasks.voidvalidate()
-
-
-
Method Detail
-
setThreadPoolSize
public void setThreadPoolSize(String size)
-
startup
public void startup(Application application, ComponentStartupStatus ss)
Description copied from interface:SearchIndexerStart processing. If unpaused, schedule any queued tasks.- Specified by:
startupin interfaceApplication.Component- Specified by:
startupin interfaceSearchIndexer
-
shutdown
public void shutdown(Application application)
Description copied from interface:SearchIndexerStop processing and release resources. This call should block until the dependent threads are stopped. Repeated calls have no effect.- Specified by:
shutdownin interfaceApplication.Component- Specified by:
shutdownin interfaceSearchIndexer
-
pause
public void pause()
Description copied from interface:SearchIndexerStop processing new tasks. Requests will be queued until a call to unpause(). Fires a PAUSED event to listeners. This call has no effect if already paused, or if called after shutdown.- Specified by:
pausein interfaceSearchIndexer
-
unpause
public void unpause()
Description copied from interface:SearchIndexerResume processing new tasks. Any requests that were received since the call to pause() will now be scheduled for processing. Fires an UNPAUSED event to listeners. If startup has not been called, the unpaused state will be recorded, but tasks will still await the call to startup. This call has no effect if not paused, or if called after shutdown.- Specified by:
unpausein interfaceSearchIndexer
-
getStatus
public SearchIndexerStatus getStatus()
Description copied from interface:SearchIndexerWhat is the current status of the indexer? Still valid after shutdown().- Specified by:
getStatusin interfaceSearchIndexer
-
scheduleUpdatesForStatements
public void scheduleUpdatesForStatements(List<org.apache.jena.rdf.model.Statement> changes)
Description copied from interface:SearchIndexerUpdate any search documents that are affected by these statements. These statements are a mixture of additions and deletions. In either case, we feed them to the URI finders to see what individuals might have been affected by the change. We accumulate a batch of affected URIs, removing duplicates if they occur, and then submit them for updates. If called before startup or while paused, the task will be queued. If called after shutdown, this has no effect.- Specified by:
scheduleUpdatesForStatementsin interfaceSearchIndexer- Parameters:
changes- if null or empty, this call has no effect.
-
scheduleUpdatesForUris
public void scheduleUpdatesForUris(Collection<String> uris)
Description copied from interface:SearchIndexerUpdate the search documents for these URIs. For each URI that belongs in the index, a new search document is built, replacing any document that may already exist for that URI. For each URI that does not belong in the index, any existing document is removed. A URI belongs in the index if it refers to an existing individual in the model, and is not excluded. If called before startup or while paused, the task will be queued. If called after shutdown, this has no effect.- Specified by:
scheduleUpdatesForUrisin interfaceSearchIndexer- Parameters:
uris- if null or empty, this call has no effect.
-
rebuildIndex
public void rebuildIndex()
Description copied from interface:SearchIndexerRemove all of the existing documents in the index, and schedule updates for all of the individuals in the model. If a rebuild is already pending or in progress, this method has no effect. If called before startup or while paused, the task will be queued. If called after shutdown, this has no effect.- Specified by:
rebuildIndexin interfaceSearchIndexer
-
addListener
public void addListener(SearchIndexer.Listener listener)
Description copied from interface:SearchIndexerAdd this listener, allowing it to receive events from the indexer. The listener can safely assume that the SearchIndexer is not paused. If the SearchIndexer is indeed paused when the listener is added, then a PAUSE event will immediately be passed to the listener. If this listener has already been added, or if called after shutdown, this method has no effect.- Specified by:
addListenerin interfaceSearchIndexer- Parameters:
listener- if null, this method has no effect.
-
removeListener
public void removeListener(SearchIndexer.Listener listener)
Description copied from interface:SearchIndexerRemove this listener, meaning that it will no longer receive events from the indexer. If this listener is not active, or if called after shutdown, this method has no effect.- Specified by:
removeListenerin interfaceSearchIndexer- Parameters:
listener- if null, this method has no effect.
-
-