Closes #224: scan for indexing handler

This commit is contained in:
Benjamin Gamard 2018-04-05 19:19:22 +02:00
parent c0678e9a90
commit 6798e01f49
3 changed files with 26 additions and 2 deletions

View File

@ -1,5 +1,6 @@
package com.sismics.docs.core.model.context;
import com.google.common.collect.Lists;
import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
import com.sismics.docs.core.constant.Constants;
@ -11,7 +12,7 @@ import com.sismics.docs.core.service.FileService;
import com.sismics.docs.core.service.InboxService;
import com.sismics.docs.core.util.PdfUtil;
import com.sismics.docs.core.util.indexing.IndexingHandler;
import com.sismics.docs.core.util.indexing.LuceneIndexingHandler;
import com.sismics.util.ClasspathScanner;
import com.sismics.util.EnvironmentUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -76,8 +77,16 @@ public class AppContext {
resetEventBus();
// Start indexing handler
indexingHandler = new LuceneIndexingHandler();
try {
List<Class<? extends IndexingHandler>> indexingHandlerList = Lists.newArrayList(
new ClasspathScanner<IndexingHandler>().findClasses(IndexingHandler.class, "com.sismics.docs.core.util.indexing"));
for (Class<? extends IndexingHandler> handlerClass : indexingHandlerList) {
IndexingHandler handler = handlerClass.newInstance();
if (handler.accept()) {
indexingHandler = handler;
break;
}
}
indexingHandler.startUp();
} catch (Exception e) {
log.error("Error starting the indexing handler, rebuilding the index: " + e.getMessage());

View File

@ -16,6 +16,13 @@ import java.util.List;
* @author bgamard
*/
public interface IndexingHandler {
/**
* Return true if this indexing handler can start.
*
* @return True if able to start
*/
boolean accept();
/**
* Start the indexing handler.
*

View File

@ -16,6 +16,7 @@ import com.sismics.docs.core.util.jpa.PaginatedList;
import com.sismics.docs.core.util.jpa.PaginatedLists;
import com.sismics.docs.core.util.jpa.QueryParam;
import com.sismics.docs.core.util.jpa.SortCriteria;
import com.sismics.util.ClasspathScanner;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.StringField;
@ -44,6 +45,7 @@ import java.util.*;
*
* @author bgamard
*/
@ClasspathScanner.Priority(100)
public class LuceneIndexingHandler implements IndexingHandler {
/**
* Logger.
@ -60,6 +62,12 @@ public class LuceneIndexingHandler implements IndexingHandler {
*/
private DirectoryReader directoryReader;
@Override
public boolean accept() {
// Embedded Lucene can always start
return true;
}
@Override
public void startUp() throws Exception {
ConfigDao configDao = new ConfigDao();