fix reindexing on application startup

This commit is contained in:
Benjamin Gamard 2018-03-31 13:24:25 +02:00
parent e72dab2a6e
commit b3349176d9
2 changed files with 12 additions and 11 deletions

View File

@ -25,7 +25,7 @@ import java.util.concurrent.TimeUnit;
/** /**
* Global application context. * Global application context.
* *
* @author jtremeaux * @author jtremeaux
*/ */
public class AppContext { public class AppContext {
/** /**
@ -62,11 +62,11 @@ public class AppContext {
* Asynchronous executors. * Asynchronous executors.
*/ */
private List<ExecutorService> asyncExecutorList; private List<ExecutorService> asyncExecutorList;
/** /**
* Private constructor. * Start the application context.
*/ */
private AppContext() { private void startUp() {
resetEventBus(); resetEventBus();
// Start indexing handler // Start indexing handler
@ -74,7 +74,7 @@ public class AppContext {
try { try {
indexingHandler.startUp(); indexingHandler.startUp();
} catch (Exception e) { } catch (Exception e) {
log.error("Error starting the indexing handler, rebuilding the index", e); log.error("Error starting the indexing handler, rebuilding the index: " + e.getMessage());
RebuildIndexAsyncEvent rebuildIndexAsyncEvent = new RebuildIndexAsyncEvent(); RebuildIndexAsyncEvent rebuildIndexAsyncEvent = new RebuildIndexAsyncEvent();
asyncEventBus.post(rebuildIndexAsyncEvent); asyncEventBus.post(rebuildIndexAsyncEvent);
} }
@ -109,13 +109,13 @@ public class AppContext {
} }
} }
} }
/** /**
* (Re)-initializes the event buses. * (Re)-initializes the event buses.
*/ */
private void resetEventBus() { private void resetEventBus() {
asyncExecutorList = new ArrayList<>(); asyncExecutorList = new ArrayList<>();
asyncEventBus = newAsyncEventBus(); asyncEventBus = newAsyncEventBus();
asyncEventBus.register(new FileProcessingAsyncListener()); asyncEventBus.register(new FileProcessingAsyncListener());
asyncEventBus.register(new FileDeletedAsyncListener()); asyncEventBus.register(new FileDeletedAsyncListener());
@ -132,19 +132,20 @@ public class AppContext {
/** /**
* Returns a single instance of the application context. * Returns a single instance of the application context.
* *
* @return Application context * @return Application context
*/ */
public static AppContext getInstance() { public static AppContext getInstance() {
if (instance == null) { if (instance == null) {
instance = new AppContext(); instance = new AppContext();
instance.startUp();
} }
return instance; return instance;
} }
/** /**
* Creates a new asynchronous event bus. * Creates a new asynchronous event bus.
* *
* @return Async event bus * @return Async event bus
*/ */
private EventBus newAsyncEventBus() { private EventBus newAsyncEventBus() {

View File

@ -13,7 +13,7 @@ public class DialectUtil {
* @return Object not found * @return Object not found
*/ */
public static boolean isObjectNotFound(String message) { public static boolean isObjectNotFound(String message) {
return EMF.isDriverH2() && message.contains("object not found") || return EMF.isDriverH2() && message.contains("not found") ||
EMF.isDriverPostgresql() && message.contains("does not exist"); EMF.isDriverPostgresql() && message.contains("does not exist");
} }