From 4beefd59bec12d82505dd3a751837aa7cde23875 Mon Sep 17 00:00:00 2001 From: Julien Viet Date: Thu, 7 Mar 2019 19:13:24 +0100 Subject: [PATCH] foo --- .../core/http/impl/HttpServerRequestImpl.java | 4 ++-- .../core/http/impl/HttpServerResponseImpl.java | 4 ++-- .../java/io/vertx/core/impl/AbstractContext.java | 4 ++-- .../java/io/vertx/core/impl/VertxThread.java | 16 +++++++--------- src/test/java/io/vertx/core/http/HttpTest.java | 11 +++++------ 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/main/java/io/vertx/core/http/impl/HttpServerRequestImpl.java b/src/main/java/io/vertx/core/http/impl/HttpServerRequestImpl.java index 1f78b5ef4f9..b5a399e6d00 100644 --- a/src/main/java/io/vertx/core/http/impl/HttpServerRequestImpl.java +++ b/src/main/java/io/vertx/core/http/impl/HttpServerRequestImpl.java @@ -153,13 +153,13 @@ void handleBegin() { check100(); } VertxThread current = VertxThread.current(); - ContextInternal prev = current.beginDispatch(context); + current.beginDispatch(context); try { conn.requestHandler.handle(this); } catch(Throwable t) { context.reportException(t); } finally { - current.endDispatch(prev); + current.endDispatch(); } } diff --git a/src/main/java/io/vertx/core/http/impl/HttpServerResponseImpl.java b/src/main/java/io/vertx/core/http/impl/HttpServerResponseImpl.java index 4e366441232..a606b859c87 100644 --- a/src/main/java/io/vertx/core/http/impl/HttpServerResponseImpl.java +++ b/src/main/java/io/vertx/core/http/impl/HttpServerResponseImpl.java @@ -342,10 +342,10 @@ public void end(Buffer chunk) { written = true; conn.responseComplete(); if (bodyEndHandler != null) { - context.dispatch(bodyEndHandler); + bodyEndHandler.handle(null); } if (endHandler != null) { - context.dispatch(endHandler); + endHandler.handle(null); } } } diff --git a/src/main/java/io/vertx/core/impl/AbstractContext.java b/src/main/java/io/vertx/core/impl/AbstractContext.java index eeb6901a3f6..5967c4c3061 100644 --- a/src/main/java/io/vertx/core/impl/AbstractContext.java +++ b/src/main/java/io/vertx/core/impl/AbstractContext.java @@ -73,13 +73,13 @@ public final void dispatch(Handler task) { @Override public final void dispatch(T arg, Handler task) { VertxThread currentThread = VertxThread.current(); - ContextInternal prev = currentThread.beginDispatch(this); + currentThread.beginDispatch(this); try { task.handle(arg); } catch (Throwable t) { reportException(t); } finally { - currentThread.endDispatch(prev); + currentThread.endDispatch(); } } diff --git a/src/main/java/io/vertx/core/impl/VertxThread.java b/src/main/java/io/vertx/core/impl/VertxThread.java index 25997b03511..a3af1df0a05 100644 --- a/src/main/java/io/vertx/core/impl/VertxThread.java +++ b/src/main/java/io/vertx/core/impl/VertxThread.java @@ -92,18 +92,18 @@ public TimeUnit getMaxExecTimeUnit() { * shall be used. * * @param context the context on which the task is dispatched on - * @return the current context that shall be restored */ - public ContextInternal beginDispatch(ContextInternal context) { + public void beginDispatch(ContextInternal context) { + if (this.context != null) { + throw new IllegalStateException("Already dispatching"); + } if (!ContextImpl.DISABLE_TIMINGS) { executeStart(); } if (!DISABLE_TCCL) { setContextClassLoader(context != null ? context.classLoader() : null); } - ContextInternal prev = this.context; this.context = context; - return prev; } /** @@ -111,15 +111,13 @@ public ContextInternal beginDispatch(ContextInternal context) { *

* This is a low level interface that should not be used, instead {@link ContextInternal#dispatch(Object, io.vertx.core.Handler)} * shall be used. - * - * @param context the previous context thread to restore, might be {@code null} */ - public void endDispatch(ContextInternal context) { + public void endDispatch() { // We don't unset the context after execution - this is done later when the context is closed via // VertxThreadFactory - this.context = context; + this.context = null; if (!DISABLE_TCCL) { - setContextClassLoader(context != null ? context.classLoader() : null); + setContextClassLoader(null); } if (!ContextImpl.DISABLE_TIMINGS) { executeEnd(); diff --git a/src/test/java/io/vertx/core/http/HttpTest.java b/src/test/java/io/vertx/core/http/HttpTest.java index 9d6a06e1cf8..f54ff4460e6 100644 --- a/src/test/java/io/vertx/core/http/HttpTest.java +++ b/src/test/java/io/vertx/core/http/HttpTest.java @@ -4662,12 +4662,12 @@ public void testHttpInvalidConnectResponseChunked() { @Test public void testEndFromAnotherThread() throws Exception { - - waitFor(2); - - // Same with pipelining - + waitFor(3); + disableThreadChecks(); server.requestHandler(req -> { + req.response().bodyEndHandler(v -> { + complete(); + }); req.response().endHandler(v -> { complete(); }); @@ -4680,7 +4680,6 @@ public void testEndFromAnotherThread() throws Exception { assertEquals(200, resp.statusCode()); complete(); })); - await(); }