From 2e36402a762193a9e2fd3b85ccda30429c09b5df Mon Sep 17 00:00:00 2001 From: rob bygrave Date: Sun, 27 May 2018 15:54:32 +1200 Subject: [PATCH] #1387 - Revert #1374 and expose io.ebean.event.ServletContextListener (as public API) --- .../ebean/event/ServletContextListener.java | 38 +++++++++++++++++++ .../server/core/ServletContextListener.java | 3 ++ 2 files changed, 41 insertions(+) create mode 100644 src/main/java/io/ebean/event/ServletContextListener.java diff --git a/src/main/java/io/ebean/event/ServletContextListener.java b/src/main/java/io/ebean/event/ServletContextListener.java new file mode 100644 index 000000000..d0b8b2222 --- /dev/null +++ b/src/main/java/io/ebean/event/ServletContextListener.java @@ -0,0 +1,38 @@ +package io.ebean.event; + +import io.ebeaninternal.server.lib.ShutdownManager; + +import javax.servlet.ServletContextEvent; + +/** + * Listens for webserver server starting and stopping events. + *

+ * This should be used when the deployment is into a servlet container where the webapp + * can be shutdown or redeployed without the JVM stopping. + *

+ *

+ * If deployment is into a container where the JVM is completely shutdown (like spring boot, + * runnable war or when using a servlet container that only contains the single webapp and + * the JVM is shutdown then this isn't required. Instead we can just rely on the JVM shutdown + * hook that Ebean registers. + *

+ */ +public class ServletContextListener implements javax.servlet.ServletContextListener { + + /** + * The servlet container is stopping. + */ + @Override + public void contextDestroyed(ServletContextEvent event) { + ShutdownManager.shutdown(); + } + + /** + * Do nothing on startup. + */ + @Override + public void contextInitialized(ServletContextEvent event) { + + } + +} diff --git a/src/main/java/io/ebeaninternal/server/core/ServletContextListener.java b/src/main/java/io/ebeaninternal/server/core/ServletContextListener.java index e77aa24f2..260cfa296 100644 --- a/src/main/java/io/ebeaninternal/server/core/ServletContextListener.java +++ b/src/main/java/io/ebeaninternal/server/core/ServletContextListener.java @@ -5,12 +5,15 @@ import io.ebeaninternal.server.lib.ShutdownManager; import javax.servlet.ServletContextEvent; /** + * Deprecated - migrate to io.ebean.event.ServletContextListener. + *

* Listens for webserver server starting and stopping events. *

* Register this listener in the web.xml configuration file. This will listen * for startup and shutdown events. *

*/ +@Deprecated public class ServletContextListener implements javax.servlet.ServletContextListener { /**