Search in sources :

Example 1 with ConfigurationLoaderStage1

use of au.org.emii.portal.config.ConfigurationLoaderStage1 in project spatial-portal by AtlasOfLivingAustralia.

the class ApplicationInit method contextInitialized.

@Override
public void contextInitialized(ServletContextEvent sce) {
    // first log message can come from a log4j instance without substituting
    // variables, just so we know we at least got this far...
    LOGGER.debug("================[WEB PORTAL APPLICATION INIT]================");
    // now the spring context gets loaded by superclass...
    super.contextInitialized(sce);
    ServletContext servletContext = sce.getServletContext();
    WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
    /* configurationLoader is a daemon thread that runs for the duration
             * of the application - it is set to periodically reload the configuration.
             * We store the both the thread and the runnable in application scope so
             * we can kill the thread cleanly
             */
    ConfigurationLoaderStage1 configurationLoader = context.getBean(ConfigurationLoaderStage1.class);
    configurationLoader.setServletContext(servletContext);
    servletContext.setAttribute(CONFIGURATION_LOADER_ATTRIBUTE, configurationLoader);
    Thread configurationLoaderThread = new Thread(configurationLoader);
    // set the name for debugging purposes.  We tostring the thread object
    // so that the name will contain the memory address so we can distinguish
    // between diferent instances of the same thread should this happen.
    configurationLoaderThread.setName("ConfigurationLoader-instance-" + configurationLoaderThread.toString());
    servletContext.setAttribute(CONFIGURATION_LOADER_THREAD_ATTRIBUTE, configurationLoaderThread);
    // start the tread running and return control immediately
    configurationLoaderThread.start();
    //NC 2013-11-26: initialise the ZK Labels to include biocache WS i18n version. 
    LOGGER.debug("REGISTERING Biocache Labeller...");
    Labels.register(new BiocacheLabelLocator());
    LOGGER.debug("* APPLICATION INIT: complete");
}
Also used : BiocacheLabelLocator(zk.extra.BiocacheLabelLocator) ConfigurationLoaderStage1(au.org.emii.portal.config.ConfigurationLoaderStage1) ServletContext(javax.servlet.ServletContext) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 2 with ConfigurationLoaderStage1

use of au.org.emii.portal.config.ConfigurationLoaderStage1 in project spatial-portal by AtlasOfLivingAustralia.

the class ApplicationInit method contextDestroyed.

@Override
public void contextDestroyed(ServletContextEvent sce) {
    LOGGER.debug("APPLICATION shutdown requested");
    ServletContext servletContext = sce.getServletContext();
    ConfigurationLoaderStage1 configurationLoader = (ConfigurationLoaderStage1) servletContext.getAttribute(CONFIGURATION_LOADER_ATTRIBUTE);
    Thread configurationLoaderThread = (Thread) servletContext.getAttribute(CONFIGURATION_LOADER_THREAD_ATTRIBUTE);
    /* it's entirely possible that the value hasn't been put in scope yet
         * so protect against NPEs
         */
    if (configurationLoader != null) {
        configurationLoader.stop();
    }
    // interrupt the thread which is likely in sleep state
    if (configurationLoaderThread != null) {
        configurationLoaderThread.interrupt();
    }
    // now remove the attributes from servlet session...
    servletContext.removeAttribute(CONFIGURATION_LOADER_ATTRIBUTE);
    servletContext.removeAttribute(CONFIGURATION_LOADER_THREAD_ATTRIBUTE);
    super.contextDestroyed(sce);
}
Also used : ConfigurationLoaderStage1(au.org.emii.portal.config.ConfigurationLoaderStage1) ServletContext(javax.servlet.ServletContext)

Aggregations

ConfigurationLoaderStage1 (au.org.emii.portal.config.ConfigurationLoaderStage1)2 ServletContext (javax.servlet.ServletContext)2 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1 BiocacheLabelLocator (zk.extra.BiocacheLabelLocator)1