Author: markt
Date: Thu Oct 17 11:28:57 2013
New Revision: 1533050

URL: http://svn.apache.org/r1533050
Log:
Use lazy init for the room in the WebSocket drawing board example.
This is primarily to avoid an issue with a hang on Java 6 in Tomcat 7 (the 
JSR-356 examples require Java 6) but may also help with adding multiple room 
support.

Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
    
tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardContextListener.java
    
tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardEndpoint.java

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1533048-1533049

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=1533050&r1=1533049&r2=1533050&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Thu Oct 17 11:28:57 2013
@@ -64,6 +64,14 @@
       </fix>
     </changelog>
   </subsection>
+  <subsection name="Web applications">
+    <changelog>
+      <fix>
+        Avoid hang observed with Java 6 on Windows when stopping the Tomcat
+        process via CTRL-C. (markt) 
+      </fix>
+    </changelog>
+  </subsection>
 </section>
 <section name="Tomcat 7.0.46 (violetagg)" rtext="not released">
   <subsection name="Catalina">
@@ -93,12 +101,6 @@
         thread-safe manner. (markt)
       </fix>
       <fix>
-        Ensure that unused input is not swallowed when keep-alive is disabled
-        and the connection enters an error state. This allows the connection to
-        be closed immediately rather than having to wait for the client to 
first
-        send any remaining data that is only going to be ignored. (markt)
-      </fix>
-      <fix>
         Update the APR/native connector to version 1.1.29. (violetagg)
       </fix>
     </changelog>

Modified: 
tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardContextListener.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardContextListener.java?rev=1533050&r1=1533049&r2=1533050&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardContextListener.java
 (original)
+++ 
tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardContextListener.java
 Thu Oct 17 11:28:57 2013
@@ -29,6 +29,9 @@ public final class DrawboardContextListe
     @Override
     public void contextDestroyed(ServletContextEvent sce) {
         // Shutdown our room.
-        DrawboardEndpoint.getRoom().shutdown();
+        Room room = DrawboardEndpoint.getRoom(false);
+        if (room != null) {
+            room.shutdown();
+        }
     }
 }

Modified: 
tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardEndpoint.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardEndpoint.java?rev=1533050&r1=1533049&r2=1533050&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardEndpoint.java
 (original)
+++ 
tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardEndpoint.java
 Thu Oct 17 11:28:57 2013
@@ -40,10 +40,22 @@ public final class DrawboardEndpoint ext
     /**
      * Our room where players can join.
      */
-    private static final Room room = new Room();
+    private static volatile Room room = null;
+    private static final Object roomLock = new Object();
 
-    public static Room getRoom() {
-        return room;
+    public static Room getRoom(boolean create) {
+        if (create) {
+            if (room == null) {
+                synchronized (roomLock) {
+                    if (room == null) {
+                        room = new Room();
+                    }
+                }
+            }
+            return room;
+        } else {
+            return room;
+        }
     }
 
     /**
@@ -72,6 +84,7 @@ public final class DrawboardEndpoint ext
         session.addMessageHandler(stringHandler);
         final Client client = new Client(session);
 
+        final Room room = getRoom(true);
         room.invokeAndWait(new Runnable() {
             @Override
             public void run() {
@@ -100,23 +113,23 @@ public final class DrawboardEndpoint ext
 
     @Override
     public void onClose(Session session, CloseReason closeReason) {
-        room.invokeAndWait(new Runnable() {
-            @Override
-            public void run() {
-                try {
-
-                    // Player can be null if it couldn't enter the room
-                    if (player != null) {
-                        // Remove this player from the room.
-                        player.removeFromRoom();
+        Room room = getRoom(false);
+        if (room != null) {
+            room.invokeAndWait(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        // Player can be null if it couldn't enter the room
+                        if (player != null) {
+                            // Remove this player from the room.
+                            player.removeFromRoom();
+                        }
+                    } catch (RuntimeException ex) {
+                        log.error("Unexpected exception: " + ex.toString(), 
ex);
                     }
-
-                } catch (RuntimeException ex) {
-                    log.error("Unexpected exception: " + ex.toString(), ex);
                 }
-            }
-        });
-
+            });
+        }
     }
 
 



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

Reply via email to