datastax / cassandra-quarkus

An Apache Cassandra(R) extension for Quarkus
Apache License 2.0
40 stars 28 forks source link

JAVA-2719: Integrate with Netty event loop provided by Quarkus #18

Closed tomekl007 closed 4 years ago

tomekl007 commented 4 years ago

This is work in progress because we still didn't decide which path regarding integration with netty we should take. For more info, see the Mailing List topic: [quarkus-dev] Cassandra-extension and Quarkus Netty event loops

todo:

olim7t commented 4 years ago

I wrote this test resource to check that regular application code doesn't already run on the Netty event loop:

@Path("/threads")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class ThreadResource {

  @Inject CqlSession session;

  @GET
  public String get() throws ExecutionException, InterruptedException {
    StringBuilder builder =
        new StringBuilder("REST resource runs on: ")
            .append(Thread.currentThread().getName())
            .append('\n');
    CompletionStage<Void> asyncRequest =
        session
            .executeAsync("SELECT release_version FROM system.local")
            .thenApply(
                rs -> {
                  builder.append("Driver I/O runs on: ").append(Thread.currentThread().getName());
                  return null;
                });
    asyncRequest.toCompletableFuture().get();
    return builder.toString();
  }
}

Output:

REST resource runs on: executor-thread-1
Driver I/O runs on: vert.x-eventloop-thread-11

The thread names clearly show that these are two different executors; so we're safe, no risk of deadlocks if the application uses synchronous execute methods from REST resources.