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/07/09 22:08:08 UTC

svn commit: r1501512 - in /tomcat/trunk: java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java webapps/docs/web-socket-howto.xml

Author: markt
Date: Tue Jul  9 20:08:08 2013
New Revision: 1501512

URL: http://svn.apache.org/r1501512
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=55171
Add a default timeout of 5s to all blocking writes and make the timeout user configurable.

Modified:
    tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
    tomcat/trunk/webapps/docs/web-socket-howto.xml

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java?rev=1501512&r1=1501511&r2=1501512&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java Tue Jul  9 20:08:08 2013
@@ -52,6 +52,12 @@ public abstract class WsRemoteEndpointIm
     private static final StringManager sm =
             StringManager.getManager(Constants.PACKAGE_NAME);
 
+    // Milliseconds so this is 5 seconds
+    private static final long DEFAULT_BLOCKING_SEND_TIMEOUT = 5 * 1000;
+
+    public static final String BLOCKING_SEND_TIMEOUT_PROPERTY =
+            "org.apache.tomcat.websocket.BLOCKING_SEND_TIMEOUT";
+
     private final Log log = LogFactory.getLog(WsRemoteEndpointImplBase.class);
 
     private boolean messagePartInProgress = false;
@@ -76,7 +82,6 @@ public abstract class WsRemoteEndpointIm
     private WsSession wsSession;
     private List<EncoderEntry> encoderEntries = new ArrayList<>();
 
-
     public long getSendTimeout() {
         return sendTimeout;
     }
@@ -187,8 +192,14 @@ public abstract class WsRemoteEndpointIm
             TextMessageSendHandler tmsh = new TextMessageSendHandler(f2sh, part,
                     last, encoder, encoderBuffer, this);
             tmsh.write();
-            f2sh.get();
-        } catch (InterruptedException | ExecutionException e) {
+            long timeout = getBlockingSendTimeout();
+            if (timeout == -1) {
+                f2sh.get();
+            } else {
+                f2sh.get(timeout, TimeUnit.MILLISECONDS);
+            }
+        } catch (InterruptedException | ExecutionException |
+                TimeoutException e) {
             throw new IOException(e);
         }
     }
@@ -199,8 +210,14 @@ public abstract class WsRemoteEndpointIm
         FutureToSendHandler f2sh = new FutureToSendHandler();
         startMessage(opCode, payload, last, f2sh);
         try {
-            f2sh.get();
-        } catch (InterruptedException | ExecutionException e) {
+            long timeout = getBlockingSendTimeout();
+            if (timeout == -1) {
+                f2sh.get();
+            } else {
+                f2sh.get(timeout, TimeUnit.MILLISECONDS);
+            }
+        } catch (InterruptedException | ExecutionException |
+                TimeoutException e) {
             throw new IOException(e);
         }
     }
@@ -339,6 +356,21 @@ public abstract class WsRemoteEndpointIm
     }
 
 
+    private long getBlockingSendTimeout() {
+        Object obj = wsSession.getUserProperties().get(
+                BLOCKING_SEND_TIMEOUT_PROPERTY);
+        Long userTimeout = null;
+        if (obj instanceof Long) {
+            userTimeout = (Long) obj;
+        }
+        if (userTimeout == null) {
+            return DEFAULT_BLOCKING_SEND_TIMEOUT;
+        } else {
+            return userTimeout.longValue();
+        }
+    }
+
+
     private static class MessagePart {
         private final byte opCode;
         private final ByteBuffer payload;

Modified: tomcat/trunk/webapps/docs/web-socket-howto.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/web-socket-howto.xml?rev=1501512&r1=1501511&r2=1501512&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/web-socket-howto.xml (original)
+++ tomcat/trunk/webapps/docs/web-socket-howto.xml Tue Jul  9 20:08:08 2013
@@ -34,41 +34,34 @@
 
 <section name="Overview">
 <p>Tomcat provides support for WebSocket as defined by
-   <a href="http://tools.ietf.org/html/rfc6455">RFC 6455</a>. This feature is
-   not yet finalised and you are encouraged to provide feedback in the form
-   of bug reports (via
-   <a href="https://issues.apache.org/bugzilla">Bugzilla</a>), suggested API
-   changes (via the
-   <a href="http://tomcat.apache.org/lists.html#tomcat-dev">dev list</a>) or
-   other comments (again via the
-   <a href="http://tomcat.apache.org/lists.html#tomcat-dev">dev list</a>).</p>
+   <a href="http://tools.ietf.org/html/rfc6455">RFC 6455</a>.</p>
 </section>
 
 <section name="Application development">
-<p>The API used for application development has not yet been finalised. Rather
-   than document something here that will quickly be out of date, please see the
-   Javadoc for the
-   <a href="api/index.html?org/apache/catalina/websocket/package-summary.html">
-   <code>org.apache.catalina.websocket</code></a> package. The Javadoc
-   pages are not included with Tomcat binary distributions. To view them
-   locally you would have to download and install "Full documentation"
-   distribution, or build it from sources. You can
-   also read this on the Apache Tomcat web site. Start with the
-   <a href="api/index.html?org/apache/catalina/websocket/WebSocketServlet.html">
-   <code>WebSocketServlet</code></a> class.</p>
-
-<p>There are also several example applications that demonstrate how the
-   WebSocket API can be used. You will need to look at both the client side <a
+<p>Tomcat implements the Java WebSocket 1.0 API defined by <a
+   href="http://www.jcp.org/en/jsr/detail?id=356">JSR-356</a>.</p>
+   
+<p>There are several example applications that demonstrate how the WebSocket API
+   can be used. You will need to look at both the client side <a
    href="http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/websocket/">
    html</a> and the server side <a
    href="http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/">
    code</a>.</p>
-
-<p>Do keep in mind that the API is fluid and is likely to change, possibly
-   significantly, between point releases. The documentation will be updated once
-   the API is considered stable (unlikely to be until JSR 356 is complete).</p>
 </section>
 
+<section name="Tomcat WebSocket specific configuration">
+<p>Tomcat provides a number of Tomcat specific configuration options for
+   WebSocket. It is anticipated that these will be absorbed into the WebSocket
+   specification over time.</p>
+
+<p>The write timeout used when sending WebSocket messages in blocking mode
+   defaults to 5000 milliseconds (5 seconds). This may be changed by setting
+   the property <code>org.apache.tomcat.websocket.BLOCKING_SEND_TIMEOUT</code>
+   in the user properties collection attached to the WebSocket session. The
+   value assigned to this property should be a <code>Long</code> and represents
+   the timeout to use in milliseconds. For an infinite timeout, use
+   <code>-1</code>.</p>
+</section>
 
 </body>
 </document>



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