Author: remy.maucherat(a)jboss.com
Date: 2014-01-15 12:23:55 -0500 (Wed, 15 Jan 2014)
New Revision: 2341
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/server/WsHttpUpgradeHandler.java
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/server/WsRemoteEndpointImplServer.java
Log:
Attempt another autoblocking technique. Uses a fake blocking write notification that would
write all content and flush.
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-15
15:17:33 UTC (rev 2340)
+++
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/FutureToSendHandler.java 2014-01-15
17:23:55 UTC (rev 2341)
@@ -74,26 +74,24 @@
@Override
public Void get() throws InterruptedException,
ExecutionException {
- // 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 (Http11AbstractProcessor.containerThread.get() == Boolean.TRUE) {
- // FIXME: this uses the IO timeout rather than no timeout as per the API
contract
- try {
- wsSession.forceFlush();
- } catch (IOException e) {
- throw new ExecutionException(e);
+ try {
+ wsSession.registerFuture(this);
+ // 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);
+ }
}
- } else {
- try {
- wsSession.registerFuture(this);
- latch.await();
- } finally {
- wsSession.unregisterFuture(this);
- }
- if (result.getException() != null) {
- throw new ExecutionException(result.getException());
- }
+ latch.await();
+ } finally {
+ wsSession.unregisterFuture(this);
}
+ if (result.getException() != null) {
+ throw new ExecutionException(result.getException());
+ }
return null;
}
@@ -101,31 +99,29 @@
public Void get(long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException,
TimeoutException {
- // 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 (Http11AbstractProcessor.containerThread.get() == Boolean.TRUE) {
- // FIXME: this uses the IO timeout rather than the timeout specified by the
user
- try {
- wsSession.forceFlush();
- } catch (IOException e) {
- throw new ExecutionException(e);
+ boolean retval = false;
+ try {
+ wsSession.registerFuture(this);
+ // 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);
+ }
}
- } else {
- boolean retval = false;
- try {
- wsSession.registerFuture(this);
- retval = latch.await(timeout, unit);
- } finally {
- wsSession.unregisterFuture(this);
-
- }
- if (retval == false) {
- throw new TimeoutException();
- }
- if (result.getException() != null) {
- throw new ExecutionException(result.getException());
- }
+ retval = latch.await(timeout, unit);
+ } finally {
+ wsSession.unregisterFuture(this);
}
+ if (retval == false) {
+ throw new TimeoutException();
+ }
+ if (result.getException() != null) {
+ throw new ExecutionException(result.getException());
+ }
return null;
}
}
Modified:
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/server/WsHttpUpgradeHandler.java
===================================================================
---
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/server/WsHttpUpgradeHandler.java 2014-01-15
15:17:33 UTC (rev 2340)
+++
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/server/WsHttpUpgradeHandler.java 2014-01-15
17:23:55 UTC (rev 2341)
@@ -231,7 +231,7 @@
public void onWritePossible() {
// Triggered by the poller so this isn't the same thread that
// triggered the write so no need for a dispatch
- wsRemoteEndpointServer.onWritePossible(false);
+ wsRemoteEndpointServer.onWritePossible(false, 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-15
15:17:33 UTC (rev 2340)
+++
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/server/WsRemoteEndpointImplServer.java 2014-01-15
17:23:55 UTC (rev 2341)
@@ -71,19 +71,17 @@
this.buffers = buffers;
// This is definitely the same thread that triggered the write so a
// dispatch will be required.
- onWritePossible(true);
+ onWritePossible(true, false);
}
@Override
protected void doFlush() throws IOException {
- if (timeoutExpiry != -1) {
- sos.flush();
- }
+ onWritePossible(false, true);
}
- public void onWritePossible(boolean useDispatch) {
+ public void onWritePossible(boolean useDispatch, boolean block) {
if (buffers == null) {
// Servlet 3.1 will call the write listener once even if nothing
// was written
@@ -92,7 +90,7 @@
boolean complete = true;
try {
// If this is false there will be a call back when it is true
- while (sos.isReady()) {
+ while (block || sos.isReady()) {
complete = true;
for (ByteBuffer buffer : buffers) {
if (buffer.hasRemaining()) {
Show replies by date