Skip to content

Commit

Permalink
Update to executeBlocking API change
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Jul 19, 2023
1 parent f4ac00a commit ba89adb
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/main/java/io/vertx/cassandra/impl/CassandraClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,32 +233,28 @@ synchronized Future<CqlSession> getSession(ContextInternal context) {
if (holder.session != null) {
return context.succeededFuture(holder.session);
}
return context.executeBlocking(promise -> {
connect(promise);
}, holder.connectionQueue);
return context.executeBlocking(this::connect, holder.connectionQueue);
}

private void connect(Promise<CqlSession> promise) {
private CqlSession connect() {
SessionHolder current = holders.get(clientName);
if (current == null) {
promise.fail("Client closed while connecting");
return;
throw new VertxException("Client closed while connecting", true);
}
if (current.session != null) {
promise.complete(current.session);
return;
return current.session;
}
CqlSessionBuilder builder = options.dataStaxClusterBuilder();
CqlSession session = builder.build();
current = holders.compute(clientName, (k, h) -> h == null ? null : h.connected(session));
if (current != null) {
promise.complete(current.session);
return current.session;
} else {
try {
session.close();
} catch (Exception ignored) {
}
promise.fail("Client closed while connecting");
throw new VertxException("Client closed while connecting", true);
}
}
}

0 comments on commit ba89adb

Please sign in to comment.