tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1552076 - in /tomcat/tc7.0.x/trunk: ./ java/org/apache/tomcat/websocket/server/WsServerContainer.java webapps/docs/changelog.xml
Date Wed, 18 Dec 2013 20:06:59 GMT
Author: markt
Date: Wed Dec 18 20:06:58 2013
New Revision: 1552076

URL: http://svn.apache.org/r1552076
Log:
Revert r1551356. Lazy init of WsServerContainer causes problems with Atmosphere that can't
easily be avoided.

Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/WsServerContainer.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Reverse-merged /tomcat/trunk:r1551352

Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/WsServerContainer.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/WsServerContainer.java?rev=1552076&r1=1552075&r2=1552076&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/WsServerContainer.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/WsServerContainer.java Wed
Dec 18 20:06:58 2013
@@ -87,89 +87,74 @@ public class WsServerContainer extends W
     private volatile boolean addAllowed = true;
     private final ConcurrentHashMap<String,Set<WsSession>> authenticatedSessions
=
             new ConcurrentHashMap<String, Set<WsSession>>();
-    private ExecutorService executorService;
-    private volatile boolean initialized = false;
+    private final ExecutorService executorService;
 
     WsServerContainer(ServletContext servletContext) {
-        this.servletContext = servletContext;
-    }
 
-    private void init() {
+        this.servletContext = servletContext;
 
-        // Double checked locking. This is safe since Java > 1.5 and initialized
-        // is volatile
-        if (initialized) {
-            return;
+        // Configure servlet context wide defaults
+        String value = servletContext.getInitParameter(
+                Constants.BINARY_BUFFER_SIZE_SERVLET_CONTEXT_INIT_PARAM);
+        if (value != null) {
+            setDefaultMaxBinaryMessageBufferSize(Integer.parseInt(value));
+        }
+
+        value = servletContext.getInitParameter(
+                Constants.TEXT_BUFFER_SIZE_SERVLET_CONTEXT_INIT_PARAM);
+        if (value != null) {
+            setDefaultMaxTextMessageBufferSize(Integer.parseInt(value));
+        }
+
+        value = servletContext.getInitParameter(
+                Constants.ENFORCE_NO_ADD_AFTER_HANDSHAKE_CONTEXT_INIT_PARAM);
+        if (value != null) {
+            setEnforceNoAddAfterHandshake(Boolean.parseBoolean(value));
+        }
+        // Executor config
+        int executorCoreSize = 0;
+        int executorMaxSize = 10;
+        long executorKeepAliveTimeSeconds = 60;
+        value = servletContext.getInitParameter(
+                Constants.EXECUTOR_CORE_SIZE_INIT_PARAM);
+        if (value != null) {
+            executorCoreSize = Integer.parseInt(value);
+        }
+        value = servletContext.getInitParameter(
+                Constants.EXECUTOR_MAX_SIZE_INIT_PARAM);
+        if (value != null) {
+            executorMaxSize = Integer.parseInt(value);
+        }
+        value = servletContext.getInitParameter(
+                Constants.EXECUTOR_KEEPALIVETIME_SECONDS_INIT_PARAM);
+        if (value != null) {
+            executorKeepAliveTimeSeconds = Long.parseLong(value);
+        }
+
+        FilterRegistration.Dynamic fr = servletContext.addFilter(
+                WsFilter.class.getName(), new WsFilter());
+        fr.setAsyncSupported(true);
+
+        EnumSet<DispatcherType> types = EnumSet.of(DispatcherType.REQUEST,
+                DispatcherType.FORWARD);
+
+        fr.addMappingForUrlPatterns(types, true, "/*");
+
+        // Use a per web application executor for any threads the the WebSocket
+        // server code needs to create. Group all of the threads under a single
+        // ThreadGroup.
+        StringBuffer threadGroupName = new StringBuffer("WebSocketServer-");
+        if ("".equals(servletContext.getContextPath())) {
+            threadGroupName.append("ROOT");
+        } else {
+            threadGroupName.append(servletContext.getContextPath());
         }
-        synchronized (this) {
-            if (initialized) {
-                return;
-            }
-            initialized = true;
-
-            // Configure servlet context wide defaults
-            String value = servletContext.getInitParameter(
-                    Constants.BINARY_BUFFER_SIZE_SERVLET_CONTEXT_INIT_PARAM);
-            if (value != null) {
-                setDefaultMaxBinaryMessageBufferSize(Integer.parseInt(value));
-            }
-
-            value = servletContext.getInitParameter(
-                    Constants.TEXT_BUFFER_SIZE_SERVLET_CONTEXT_INIT_PARAM);
-            if (value != null) {
-                setDefaultMaxTextMessageBufferSize(Integer.parseInt(value));
-            }
+        ThreadGroup threadGroup = new ThreadGroup(threadGroupName.toString());
+        WsThreadFactory wsThreadFactory = new WsThreadFactory(threadGroup);
 
-            value = servletContext.getInitParameter(
-                    Constants.ENFORCE_NO_ADD_AFTER_HANDSHAKE_CONTEXT_INIT_PARAM);
-            if (value != null) {
-                setEnforceNoAddAfterHandshake(Boolean.parseBoolean(value));
-            }
-            // Executor config
-            int executorCoreSize = 0;
-            int executorMaxSize = 10;
-            long executorKeepAliveTimeSeconds = 60;
-            value = servletContext.getInitParameter(
-                    Constants.EXECUTOR_CORE_SIZE_INIT_PARAM);
-            if (value != null) {
-                executorCoreSize = Integer.parseInt(value);
-            }
-            value = servletContext.getInitParameter(
-                    Constants.EXECUTOR_MAX_SIZE_INIT_PARAM);
-            if (value != null) {
-                executorMaxSize = Integer.parseInt(value);
-            }
-            value = servletContext.getInitParameter(
-                    Constants.EXECUTOR_KEEPALIVETIME_SECONDS_INIT_PARAM);
-            if (value != null) {
-                executorKeepAliveTimeSeconds = Long.parseLong(value);
-            }
-
-            FilterRegistration.Dynamic fr = servletContext.addFilter(
-                    "Tomcat WebSocket (JSR356) Filter", new WsFilter());
-            fr.setAsyncSupported(true);
-
-            EnumSet<DispatcherType> types = EnumSet.of(DispatcherType.REQUEST,
-                    DispatcherType.FORWARD);
-
-            fr.addMappingForUrlPatterns(types, true, "/*");
-
-            // Use a per web application executor for any threads the the WebSocket
-            // server code needs to create. Group all of the threads under a single
-            // ThreadGroup.
-            StringBuffer threadGroupName = new StringBuffer("WebSocketServer-");
-            if ("".equals(servletContext.getContextPath())) {
-                threadGroupName.append("ROOT");
-            } else {
-                threadGroupName.append(servletContext.getContextPath());
-            }
-            ThreadGroup threadGroup = new ThreadGroup(threadGroupName.toString());
-            WsThreadFactory wsThreadFactory = new WsThreadFactory(threadGroup);
-
-            executorService = new ThreadPoolExecutor(executorCoreSize,
-                    executorMaxSize, executorKeepAliveTimeSeconds, TimeUnit.SECONDS,
-                    new LinkedBlockingQueue<Runnable>(), wsThreadFactory);
-        }
+        executorService = new ThreadPoolExecutor(executorCoreSize,
+                executorMaxSize, executorKeepAliveTimeSeconds, TimeUnit.SECONDS,
+                new LinkedBlockingQueue<Runnable>(), wsThreadFactory);
     }
 
 
@@ -185,8 +170,6 @@ public class WsServerContainer extends W
     public void addEndpoint(ServerEndpointConfig sec)
             throws DeploymentException {
 
-        init();
-
         if (enforceNoAddAfterHandshake && !addAllowed) {
             throw new DeploymentException(
                     sm.getString("serverContainer.addNotAllowed"));
@@ -238,8 +221,6 @@ public class WsServerContainer extends W
     @Override
     public void addEndpoint(Class<?> pojo) throws DeploymentException {
 
-        init();
-
         ServerEndpoint annotation = pojo.getAnnotation(ServerEndpoint.class);
         if (annotation == null) {
             throw new DeploymentException(

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1552076&r1=1552075&r2=1552076&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Wed Dec 18 20:06:58 2013
@@ -77,11 +77,6 @@
         limit larger than the default permitted by Tomcat. (markt)
       </fix>
       <fix>
-        <bug>55855</bug>: This is a partial fix that makes the additional of
the
-        WebSocket Filter lazy so that it is not added to web applications that
-        do not need it. (markt) 
-      </fix>
-      <fix>
         <bug>55905</bug>: Prevent a NPE when web.xml references a taglib file
         that does not exist. Provide better error message. (violetagg)
       </fix>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message