Search in sources :

Example 1 with SiteContextInitializationException

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);
        }
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) CrafterException(org.craftercms.core.exception.CrafterException) SiteContextInitializationException(org.craftercms.engine.exception.SiteContextInitializationException) GraphQLBuildException(org.craftercms.engine.exception.GraphQLBuildException) SiteContextInitializationException(org.craftercms.engine.exception.SiteContextInitializationException)

Aggregations

CrafterException (org.craftercms.core.exception.CrafterException)1 GraphQLBuildException (org.craftercms.engine.exception.GraphQLBuildException)1 SiteContextInitializationException (org.craftercms.engine.exception.SiteContextInitializationException)1 SchedulerException (org.quartz.SchedulerException)1