You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2013/12/18 18:14:53 UTC

svn commit: r1552035 - /tomcat/trunk/java/org/apache/tomcat/websocket/server/WsServerContainer.java

Author: markt
Date: Wed Dec 18 17:14:53 2013
New Revision: 1552035

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

Modified:
    tomcat/trunk/java/org/apache/tomcat/websocket/server/WsServerContainer.java

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/server/WsServerContainer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/WsServerContainer.java?rev=1552035&r1=1552034&r2=1552035&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/server/WsServerContainer.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/server/WsServerContainer.java Wed Dec 18 17:14:53 2013
@@ -87,91 +87,76 @@ public class WsServerContainer extends W
     private volatile boolean addAllowed = true;
     private final ConcurrentHashMap<String,Set<WsSession>> authenticatedSessions =
             new ConcurrentHashMap<>();
-    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(
+                "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-");
+        threadGroupName.append(servletContext.getVirtualServerName());
+        threadGroupName.append('-');
+        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-");
-            threadGroupName.append(servletContext.getVirtualServerName());
-            threadGroupName.append('-');
-            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);
     }
 
 
@@ -187,8 +172,6 @@ public class WsServerContainer extends W
     public void addEndpoint(ServerEndpointConfig sec)
             throws DeploymentException {
 
-        init();
-
         if (enforceNoAddAfterHandshake && !addAllowed) {
             throw new DeploymentException(
                     sm.getString("serverContainer.addNotAllowed"));
@@ -240,8 +223,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(



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