001package io.ebean.event;
002
003import io.ebeaninternal.server.lib.ShutdownManager;
004
005import javax.servlet.ServletContextEvent;
006
007/**
008 * Listens for webserver server starting and stopping events.
009 * <p>
010 * This should be used when the deployment is into a servlet container where the webapp
011 * can be shutdown or redeployed without the JVM stopping.
012 * </p>
013 * <p>
014 * If deployment is into a container where the JVM is completely shutdown (like spring boot,
015 * runnable war or when using a servlet container that only contains the single webapp and
016 * the JVM is shutdown then this isn't required. Instead we can just rely on the JVM shutdown
017 * hook that Ebean registers.
018 * </p>
019 */
020public class ServletContextListener implements javax.servlet.ServletContextListener {
021
022  /**
023   * The servlet container is stopping.
024   */
025  @Override
026  public void contextDestroyed(ServletContextEvent event) {
027    ShutdownManager.shutdown();
028  }
029
030  /**
031   * Do nothing on startup.
032   */
033  @Override
034  public void contextInitialized(ServletContextEvent event) {
035
036  }
037
038}