Skip to content

Commit 9a8a3b5

Browse files
committed
Add transaction interruption support for internal use
This update is for Neo4j internal use only.
1 parent 8845e0b commit 9a8a3b5

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

driver/src/main/java/org/neo4j/driver/internal/async/UnmanagedTransaction.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ private enum State {
9191
private CompletableFuture<Void> commitFuture;
9292
private CompletableFuture<Void> rollbackFuture;
9393
private Throwable causeOfTermination;
94+
private CompletionStage<Void> interruptStage;
9495

9596
public UnmanagedTransaction(Connection connection, BookmarksHolder bookmarksHolder, long fetchSize) {
9697
this(connection, bookmarksHolder, fetchSize, new ResultCursorsHolder());
@@ -303,4 +304,21 @@ private CompletionStage<Void> closeAsync(boolean commit, boolean completeWithNul
303304

304305
return stage;
305306
}
307+
308+
/**
309+
* Marks transaction as terminated and sends {@code RESET} message over allocated connection.
310+
* <p>
311+
* <b>THIS METHOD IS NOT PART OF PUBLIC API</b>
312+
*
313+
* @return {@code RESET} response stage
314+
*/
315+
public CompletionStage<Void> interruptAsync() {
316+
return executeWithLock(lock, () -> {
317+
if (interruptStage == null) {
318+
markTerminated(null);
319+
interruptStage = connection.reset();
320+
}
321+
return interruptStage;
322+
});
323+
}
306324
}

driver/src/main/java/org/neo4j/driver/internal/reactive/InternalReactiveTransaction.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,15 @@ public Publisher<ReactiveResult> run(Query query) {
5757
})
5858
.map(InternalReactiveResult::new);
5959
}
60+
61+
/**
62+
* Marks transaction as terminated and sends {@code RESET} message over allocated connection.
63+
* <p>
64+
* <b>THIS METHOD IS NOT PART OF PUBLIC API</b>
65+
*
66+
* @return {@code RESET} response publisher
67+
*/
68+
public Publisher<Void> interrupt() {
69+
return Mono.fromCompletionStage(tx.interruptAsync());
70+
}
6071
}

0 commit comments

Comments
 (0)