Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
injectives committed Apr 9, 2024
1 parent 1e62146 commit bb0373f
Showing 1 changed file with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,28 +109,6 @@ public BoltConnectionImpl(
this.logging = Objects.requireNonNull(logging);
}

private CompletionStage<Void> executeInEventLoop(Runnable runnable) {
var executeStage = new CompletableFuture<Void>();
Runnable stageCompletingRunnable = () -> {
try {
runnable.run();
} catch (Throwable throwable) {
executeStage.completeExceptionally(throwable);
}
executeStage.complete(null);
};
if (eventLoop.inEventLoop()) {
stageCompletingRunnable.run();
} else {
try {
eventLoop.execute(stageCompletingRunnable);
} catch (Throwable throwable) {
executeStage.completeExceptionally(throwable);
}
}
return executeStage;
}

@Override
public CompletionStage<BoltConnection> route(Set<String> bookmarks, String databaseName, String impersonatedUser) {
return executeInEventLoop(() -> messageWriters.add(handler -> protocol.route(
Expand Down Expand Up @@ -467,12 +445,10 @@ public CompletionStage<Void> flush(ResponseHandler handler) {

@Override
public CompletionStage<Void> close() {
var resultFuture = new CompletableFuture<Void>();
try {
return connection.close();
} catch (Throwable throwable) {
resultFuture.completeExceptionally(throwable);
return resultFuture;
return CompletableFuture.failedStage(throwable);
}
}

Expand Down Expand Up @@ -517,6 +493,28 @@ public void setImpersonatedUser(String impersonatedUser) {
this.connection.setImpersonatedUser(impersonatedUser);
}

private CompletionStage<Void> executeInEventLoop(Runnable runnable) {
var executeStage = new CompletableFuture<Void>();
Runnable stageCompletingRunnable = () -> {
try {
runnable.run();
} catch (Throwable throwable) {
executeStage.completeExceptionally(throwable);
}
executeStage.complete(null);
};
if (eventLoop.inEventLoop()) {
stageCompletingRunnable.run();
} else {
try {
eventLoop.execute(stageCompletingRunnable);
} catch (Throwable throwable) {
executeStage.completeExceptionally(throwable);
}
}
return executeStage;
}

private record BoltConnectionInfoRecord(
String serverAgent,
BoltServerAddress serverAddress,
Expand Down

0 comments on commit bb0373f

Please sign in to comment.