Author: remy.maucherat(a)jboss.com
Date: 2014-01-16 12:02:26 -0500 (Thu, 16 Jan 2014)
New Revision: 2344
Modified:
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/FutureToSendHandler.java
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsRemoteEndpointImplClient.java
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsSession.java
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/server/WsRemoteEndpointImplServer.java
Log:
Name cleanup (flush became a blocking write of the remaining data).
Modified:
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/FutureToSendHandler.java
===================================================================
---
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/FutureToSendHandler.java 2014-01-16
14:32:14 UTC (rev 2343)
+++
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/FutureToSendHandler.java 2014-01-16
17:02:26 UTC (rev 2344)
@@ -16,7 +16,6 @@
*/
package org.apache.tomcat.websocket;
-import java.io.IOException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
@@ -79,11 +78,7 @@
// If inside a container thread, must use an autoblocking flush as the write
// event will never come to the Servlet layer until the container thread
returns
if (latch.getCount() > 0 &&
Http11AbstractProcessor.containerThread.get() == Boolean.TRUE) {
- try {
- wsSession.forceFlush();
- } catch (IOException e) {
- throw new ExecutionException(e);
- }
+ wsSession.writeBlock();
}
latch.await();
} finally {
@@ -105,12 +100,12 @@
// If inside a container thread, must use an autoblocking flush as the write
// event will never come to the Servlet layer until the container thread
returns
if (latch.getCount() > 0 &&
Http11AbstractProcessor.containerThread.get() == Boolean.TRUE) {
- // FIXME: this uses the IO timeout, so it adds to the timeout specified
by the user
- try {
- wsSession.forceFlush();
- } catch (IOException e) {
- throw new ExecutionException(e);
- }
+ long nanoTime = System.nanoTime();
+ wsSession.writeBlock();
+ // Removing the time spent on IO from the specified timeout
+ // Note: it may wait more than what the user has specified
+ timeout = TimeUnit.NANOSECONDS.convert(timeout, unit) -
(System.nanoTime() - nanoTime);
+ unit = TimeUnit.NANOSECONDS;
}
retval = latch.await(timeout, unit);
} finally {
Modified:
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
===================================================================
---
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java 2014-01-16
14:32:14 UTC (rev 2343)
+++
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java 2014-01-16
17:02:26 UTC (rev 2344)
@@ -573,10 +573,11 @@
protected abstract void doWrite(SendHandler handler, ByteBuffer... data);
- protected abstract void doFlush() throws IOException;
+ protected abstract void writeBlock();
protected abstract boolean isMasked();
protected abstract void doClose();
+
private static void writeHeader(ByteBuffer headerBuffer, byte opCode,
ByteBuffer payload, boolean first, boolean last, boolean masked,
byte[] mask) {
Modified:
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsRemoteEndpointImplClient.java
===================================================================
---
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsRemoteEndpointImplClient.java 2014-01-16
14:32:14 UTC (rev 2343)
+++
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsRemoteEndpointImplClient.java 2014-01-16
17:02:26 UTC (rev 2344)
@@ -16,7 +16,6 @@
*/
package org.apache.tomcat.websocket;
-import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.concurrent.TimeUnit;
@@ -38,7 +37,7 @@
@Override
- protected void doFlush() throws IOException {
+ protected void writeBlock() {
}
@@ -47,7 +46,6 @@
long timeout = getSendTimeout();
if (timeout < 1) {
timeout = Long.MAX_VALUE;
-
}
SendHandlerToCompletionHandler sh2ch =
new SendHandlerToCompletionHandler(handler);
Modified: branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsSession.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsSession.java 2014-01-16
14:32:14 UTC (rev 2343)
+++ branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsSession.java 2014-01-16
17:02:26 UTC (rev 2344)
@@ -440,8 +440,8 @@
/**
* Force an autoblocking flush.
*/
- public void forceFlush() throws IOException {
- wsRemoteEndpoint.doFlush();
+ public void writeBlock() {
+ wsRemoteEndpoint.writeBlock();
}
private void fireEndpointOnClose(CloseReason closeReason) {
Modified:
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
===================================================================
---
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsWebSocketContainer.java 2014-01-16
14:32:14 UTC (rev 2343)
+++
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsWebSocketContainer.java 2014-01-16
17:02:26 UTC (rev 2344)
@@ -353,7 +353,6 @@
WsRemoteEndpointImplClient wsRemoteEndpointClient =
new WsRemoteEndpointImplClient(channel);
-
WsSession wsSession = new WsSession(endpoint, wsRemoteEndpointClient,
this, null, null, null, null, null, subProtocol,
Collections.<String, String> emptyMap(), false,
Modified:
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/server/WsRemoteEndpointImplServer.java
===================================================================
---
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/server/WsRemoteEndpointImplServer.java 2014-01-16
14:32:14 UTC (rev 2343)
+++
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/server/WsRemoteEndpointImplServer.java 2014-01-16
17:02:26 UTC (rev 2344)
@@ -76,7 +76,7 @@
@Override
- protected void doFlush() throws IOException {
+ protected void writeBlock() {
onWritePossible(false, true);
}