Skip to content

Commit

Permalink
Better CompletableFuture implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
noboomu committed Jun 25, 2019
1 parent 51bdb9f commit 452e82a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -690,10 +690,12 @@ protected void addClassMethodHandlers(TypeSpec.Builder typeBuilder, Class<?> cla
} else if (producesContentType.contains(MediaType.TEXT_HTML)) {
postProcess = ".textHtml().";
}
else {
postProcess = String.format(".contentType(%s).",producesContentType);
}
}

methodBuilder.addCode(
"$L.thenAcceptAsync( r -> r" + postProcess + "send(this,$L), io.undertow.util.SameThreadExecutor.INSTANCE )\n\t.exceptionally( ex -> ",
"$L.thenAcceptAsync( r -> io.sinistral.proteus.server.ServerResponse.response(r)" + postProcess + "send(this,$L), io.undertow.util.SameThreadExecutor.INSTANCE )\n\t.exceptionally( ex -> ",
"response", "exchange");
methodBuilder.beginControlFlow("", "");
methodBuilder.addCode("\t\tthrow new java.util.concurrent.CompletionException(ex);\n\t");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ public ServerResponse<ByteBuffer> responsePlaintext(ServerRequest request)

@GET
@Path("response/future/map")
public CompletableFuture<ServerResponse<Map<String,String>>> responseFutureMap( ServerRequest request )
public CompletableFuture<Map<String,String>> responseFutureMap( ServerRequest request )
{
Map<String,String> map = ImmutableMap.of("message", "success");
return CompletableFuture.completedFuture(response( map ).applicationJson());
return CompletableFuture.completedFuture(map);
}

@GET
Expand Down Expand Up @@ -393,9 +393,9 @@ public ServerResponse<Map<String,String>> debugBlockingEndpoint(ServerRequest re
@GET
@Path("response/future/user")
@Produces((MediaType.APPLICATION_JSON))
public CompletableFuture<ServerResponse<User>> responseFutureUser()
public CompletableFuture<User> responseFutureUser()
{
return CompletableFuture.completedFuture(response( new User(123L) ).applicationJson() );
return CompletableFuture.completedFuture( new User(123L) );
}

@GET
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<logger name="io.netty" level="ERROR" />
<logger name="io.netty.handler" level="ERROR" />
<logger name="io.sinistral.proteus.server.handlers" level="ERROR" />
<logger name="io.sinistral.proteus.server.handlers" level="DEBUG" />
<logger name="io.sinistral.proteus.services" level="ERROR" />

<logger name="com.sun.jersey" level="ERROR" />
Expand Down

0 comments on commit 452e82a

Please sign in to comment.