Skip to content

Commit

Permalink
foo
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Mar 7, 2019
1 parent 4147cbf commit 4beefd5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 21 deletions.
Expand Up @@ -153,13 +153,13 @@ void handleBegin() {
check100(); check100();
} }
VertxThread current = VertxThread.current(); VertxThread current = VertxThread.current();
ContextInternal prev = current.beginDispatch(context); current.beginDispatch(context);
try { try {
conn.requestHandler.handle(this); conn.requestHandler.handle(this);
} catch(Throwable t) { } catch(Throwable t) {
context.reportException(t); context.reportException(t);
} finally { } finally {
current.endDispatch(prev); current.endDispatch();
} }
} }


Expand Down
Expand Up @@ -342,10 +342,10 @@ public void end(Buffer chunk) {
written = true; written = true;
conn.responseComplete(); conn.responseComplete();
if (bodyEndHandler != null) { if (bodyEndHandler != null) {
context.dispatch(bodyEndHandler); bodyEndHandler.handle(null);
} }
if (endHandler != null) { if (endHandler != null) {
context.dispatch(endHandler); endHandler.handle(null);
} }
} }
} }
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/vertx/core/impl/AbstractContext.java
Expand Up @@ -73,13 +73,13 @@ public final void dispatch(Handler<Void> task) {
@Override @Override
public final <T> void dispatch(T arg, Handler<T> task) { public final <T> void dispatch(T arg, Handler<T> task) {
VertxThread currentThread = VertxThread.current(); VertxThread currentThread = VertxThread.current();
ContextInternal prev = currentThread.beginDispatch(this); currentThread.beginDispatch(this);
try { try {
task.handle(arg); task.handle(arg);
} catch (Throwable t) { } catch (Throwable t) {
reportException(t); reportException(t);
} finally { } finally {
currentThread.endDispatch(prev); currentThread.endDispatch();
} }
} }


Expand Down
16 changes: 7 additions & 9 deletions src/main/java/io/vertx/core/impl/VertxThread.java
Expand Up @@ -92,34 +92,32 @@ public TimeUnit getMaxExecTimeUnit() {
* shall be used. * shall be used.
* *
* @param context the context on which the task is dispatched on * @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) { if (!ContextImpl.DISABLE_TIMINGS) {
executeStart(); executeStart();
} }
if (!DISABLE_TCCL) { if (!DISABLE_TCCL) {
setContextClassLoader(context != null ? context.classLoader() : null); setContextClassLoader(context != null ? context.classLoader() : null);
} }
ContextInternal prev = this.context;
this.context = context; this.context = context;
return prev;
} }


/** /**
* End the dispatch of a context task. * End the dispatch of a context task.
* <p> * <p>
* This is a low level interface that should not be used, instead {@link ContextInternal#dispatch(Object, io.vertx.core.Handler)} * This is a low level interface that should not be used, instead {@link ContextInternal#dispatch(Object, io.vertx.core.Handler)}
* shall be used. * 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 // We don't unset the context after execution - this is done later when the context is closed via
// VertxThreadFactory // VertxThreadFactory
this.context = context; this.context = null;
if (!DISABLE_TCCL) { if (!DISABLE_TCCL) {
setContextClassLoader(context != null ? context.classLoader() : null); setContextClassLoader(null);
} }
if (!ContextImpl.DISABLE_TIMINGS) { if (!ContextImpl.DISABLE_TIMINGS) {
executeEnd(); executeEnd();
Expand Down
11 changes: 5 additions & 6 deletions src/test/java/io/vertx/core/http/HttpTest.java
Expand Up @@ -4662,12 +4662,12 @@ public void testHttpInvalidConnectResponseChunked() {


@Test @Test
public void testEndFromAnotherThread() throws Exception { public void testEndFromAnotherThread() throws Exception {

waitFor(3);
waitFor(2); disableThreadChecks();

// Same with pipelining

server.requestHandler(req -> { server.requestHandler(req -> {
req.response().bodyEndHandler(v -> {
complete();
});
req.response().endHandler(v -> { req.response().endHandler(v -> {
complete(); complete();
}); });
Expand All @@ -4680,7 +4680,6 @@ public void testEndFromAnotherThread() throws Exception {
assertEquals(200, resp.statusCode()); assertEquals(200, resp.statusCode());
complete(); complete();
})); }));

await(); await();
} }


Expand Down

0 comments on commit 4beefd5

Please sign in to comment.