diff options
author | Artur Signell <artur@vaadin.com> | 2016-06-17 14:21:57 +0300 |
---|---|---|
committer | Aleksi Hietanen <aleksi@vaadin.com> | 2016-06-23 13:35:35 +0000 |
commit | 2d404f6c7ca607bc3eeed86aa6dc05ffabd86ebf (patch) | |
tree | a22d21ea1128001e6fdb7166abeaa54b47d4858a | |
parent | 5eed1ac05390e47082c5d9defb55adc9c5b5e88d (diff) | |
download | vaadin-framework-2d404f6c7ca607bc3eeed86aa6dc05ffabd86ebf.tar.gz vaadin-framework-2d404f6c7ca607bc3eeed86aa6dc05ffabd86ebf.zip |
Make sure AtmosphereFramework is always properly destroyed (#17581)
If servlets have never been initialized, then destroy must happen in the
context destroy method
Change-Id: If5ea6072f729719c9d2f6b305b0dae2338efd07b
-rw-r--r-- | server/src/com/vaadin/server/communication/JSR356WebsocketInitializer.java | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/server/src/com/vaadin/server/communication/JSR356WebsocketInitializer.java b/server/src/com/vaadin/server/communication/JSR356WebsocketInitializer.java index 6d2843a4fc..fc4dc53714 100644 --- a/server/src/com/vaadin/server/communication/JSR356WebsocketInitializer.java +++ b/server/src/com/vaadin/server/communication/JSR356WebsocketInitializer.java @@ -171,6 +171,20 @@ public class JSR356WebsocketInitializer implements ServletContextListener { } /** + * Checks if the given attribute name matches the convention used for + * storing AtmosphereFramework references. + * + * @param attributeName + * the attribute name to check + * @return <code>true</code> if the attribute name matches the convention, + * <code>false</code> otherwise + */ + private static boolean isAtmosphereFrameworkAttribute(String attributeName) { + return attributeName.startsWith(JSR356WebsocketInitializer.class + .getName() + "."); + } + + /** * Tries to determine if the given servlet registration refers to a Vaadin * servlet. * @@ -202,7 +216,23 @@ public class JSR356WebsocketInitializer implements ServletContextListener { @Override public void contextDestroyed(ServletContextEvent sce) { - // Nothing to do here + // Destroy any AtmosphereFramework instance we have initialized. + // This must be done here to ensure that we cleanup Atmosphere instances + // related to servlets which are never initialized + ServletContext servletContext = sce.getServletContext(); + Enumeration<String> attributeNames = servletContext.getAttributeNames(); + while (attributeNames.hasMoreElements()) { + String attributeName = attributeNames.nextElement(); + if (isAtmosphereFrameworkAttribute(attributeName)) { + Object value = servletContext.getAttribute(attributeName); + if (value instanceof AtmosphereFramework) { + // This might result in calling destroy() twice, once from + // here and once from PushRequestHandler but + // AtmosphereFramework.destroy() deals with that + ((AtmosphereFramework) value).destroy(); + } + } + } } } |