summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2016-06-17 14:21:57 +0300
committerArtur Signell <artur@vaadin.com>2016-06-19 15:41:23 +0300
commit976373836584a4a398cb8c34a59e79c67de89ce1 (patch)
treee6bd173ffc061ee08a46f0b614f9ab15b92d727c /server
parent8117b2602a53486c543b7cd47033f01a366d78d7 (diff)
downloadvaadin-framework-976373836584a4a398cb8c34a59e79c67de89ce1.tar.gz
vaadin-framework-976373836584a4a398cb8c34a59e79c67de89ce1.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: I9c5188884637be8d1bd2cdf11167e3bdd6081bea
Diffstat (limited to 'server')
-rw-r--r--server/src/main/java/com/vaadin/server/communication/JSR356WebsocketInitializer.java32
1 files changed, 31 insertions, 1 deletions
diff --git a/server/src/main/java/com/vaadin/server/communication/JSR356WebsocketInitializer.java b/server/src/main/java/com/vaadin/server/communication/JSR356WebsocketInitializer.java
index 6d2843a4fc..fc4dc53714 100644
--- a/server/src/main/java/com/vaadin/server/communication/JSR356WebsocketInitializer.java
+++ b/server/src/main/java/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();
+ }
+ }
+ }
}
}