View Javadoc

1   package com.atlassian.config.lifecycle;
2   
3   import com.atlassian.spring.container.ContainerManager;
4   import com.atlassian.config.util.BootstrapUtils;
5   
6   import javax.servlet.ServletContextListener;
7   import javax.servlet.ServletContextEvent;
8   
9   /**
10   * Servlet context listener to synchronise lifecycle startup and shutdown with the web application.
11   */
12  public class LifecycleServletContextListener implements ServletContextListener
13  {
14      public void contextInitialized(ServletContextEvent servletContextEvent)
15      {
16          if (shouldRunLifecycle())
17              getLifecycleManager().startUp(servletContextEvent.getServletContext());
18      }
19  
20      public void contextDestroyed(ServletContextEvent servletContextEvent)
21      {
22          if (shouldRunLifecycle())
23              getLifecycleManager().shutDown(servletContextEvent.getServletContext());
24      }
25  
26      private LifecycleManager getLifecycleManager()
27      {
28          return ((LifecycleManager) ContainerManager.getComponent("lifecycleManager"));
29      }
30  
31      private boolean shouldRunLifecycle()
32      {
33          return ContainerManager.isContainerSetup() && BootstrapUtils.getBootstrapManager().isSetupComplete();
34      }
35  
36  }