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/10/02 10:37:52 UTC
svn commit: r1528369 -
/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/snake/SnakeAnnotation.java
Author: markt
Date: Wed Oct 2 08:37:51 2013
New Revision: 1528369
URL: http://svn.apache.org/r1528369
Log:
Handle error when user closes browser while playing snake game.
Modified:
tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/snake/SnakeAnnotation.java
Modified: tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/snake/SnakeAnnotation.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/snake/SnakeAnnotation.java?rev=1528369&r1=1528368&r2=1528369&view=diff
==============================================================================
--- tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/snake/SnakeAnnotation.java (original)
+++ tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/snake/SnakeAnnotation.java Wed Oct 2 08:37:51 2013
@@ -17,11 +17,13 @@
package websocket.snake;
import java.awt.Color;
+import java.io.EOFException;
import java.util.Iterator;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import javax.websocket.OnClose;
+import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
@@ -110,4 +112,24 @@ public class SnakeAnnotation {
SnakeTimer.broadcast(String.format("{\"type\": \"leave\", \"id\": %d}",
Integer.valueOf(id)));
}
+
+
+ @OnError
+ public void onError(Throwable t) throws Throwable {
+ // Most likely cause is a user closing their browser. Check to see if
+ // the root cause is EOF and if it is ignore it.
+ // Protect against infinite loops.
+ int count = 0;
+ Throwable root = t;
+ while (root.getCause() != null && count < 20) {
+ root = root.getCause();
+ count ++;
+ }
+ if (root instanceof EOFException) {
+ // Assume this is triggered by the user closing their browser and
+ // ignore it.
+ } else {
+ throw t;
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org