use of org.craftercms.engine.exception.SiteContextInitializationException in project engine by craftercms.
the class SiteContext method init.
public void init(boolean waitTillFinished) throws SiteContextInitializationException {
if (state == State.INITIALIZING) {
publishEvent(new SiteContextCreatedEvent(this));
Runnable initTask = () -> {
SiteContext.setCurrent(this);
try {
logger.info("--------------------------------------------------");
logger.info("<Initializing context site: " + siteName + ">");
logger.info("--------------------------------------------------");
if (cacheWarmer != null) {
cacheWarmer.warmUpCache(this, false);
}
buildGraphQLSchema();
executeInitScript();
state = State.READY;
logger.info("--------------------------------------------------");
logger.info("</Initializing context site: " + siteName + ">");
logger.info("--------------------------------------------------");
publishEvent(new SiteContextInitializedEvent(this));
} catch (Exception e) {
// If there is any exception during the init process then release the resources created so far
this.destroy();
throw e;
} finally {
initializationLatch.countDown();
SiteContext.clear();
}
};
if (waitTillFinished) {
// Done through the executor so that maintenance tasks submitted while init are queued
Future<?> future = maintenanceTaskExecutor.submit(initTask);
try {
future.get();
} catch (InterruptedException | ExecutionException e) {
throw new SiteContextInitializationException("Error while waiting for context init", e);
}
} else {
maintenanceTaskExecutor.execute(initTask);
}
}
}
Aggregations