java.lang.Object
org.neo4j.driver.internal.util.Futures
-
Method Summary
Modifier and TypeMethodDescriptionstatic CompletionException
asCompletionException
(Throwable error) Helped method to turn given exception into aCompletionException
.static void
Assert that current thread is not an event loop used for async IO operations.static <V> V
blockingGet
(CompletionStage<V> stage) static <V> V
blockingGet
(CompletionStage<V> stage, Runnable interruptHandler) static CompletionException
combineErrors
(Throwable error1, Throwable error2) Combine given errors into a singleCompletionException
to be rethrown from inside aCompletionStage
chain.static <T> CompletableFuture<T>
static Throwable
Helper method to extract cause of aCompletionException
.static <T> BiConsumer<T,
Throwable> futureCompletingConsumer
(CompletableFuture<T> future) static <T> T
getNow
(CompletionStage<T> stage) static boolean
isEventLoopThread
(Thread thread) Check if given thread is an event loop IO thread.
-
Method Details
-
completedWithNull
-
blockingGet
-
blockingGet
-
getNow
-
completionExceptionCause
Helper method to extract cause of aCompletionException
.When using
CompletionStage.whenComplete(BiConsumer)
andCompletionStage.handle(BiFunction)
propagated exceptions might get wrapped in aCompletionException
.- Parameters:
error
- the exception to get cause for.- Returns:
- cause of the given exception if it is a
CompletionException
, given exception otherwise.
-
asCompletionException
Helped method to turn given exception into aCompletionException
.- Parameters:
error
- the exception to convert.- Returns:
- given exception wrapped with
CompletionException
if it's not one already.
-
combineErrors
Combine given errors into a singleCompletionException
to be rethrown from inside aCompletionStage
chain.- Parameters:
error1
- the first error ornull
.error2
- the second error ornull
.- Returns:
null
if both errors are null,CompletionException
otherwise.
-
futureCompletingConsumer
-
assertNotInEventLoopThread
Assert that current thread is not an event loop used for async IO operations. This check is needed because blocking API methods are implemented on top of corresponding async API methods. Deadlocks might happen when IO thread executes blocking API call and has to wait for itself to read from the network.- Throws:
IllegalStateException
- when current thread is an event loop IO thread.
-
isEventLoopThread
Check if given thread is an event loop IO thread.- Parameters:
thread
- the thread to check.- Returns:
true
when given thread belongs to the event loop,false
otherwise.
-