@InterfaceAudience.Public @InterfaceStability.Unstable public final class FutureIO extends Object
Contains methods promoted from
FutureIOSupport
because they
are a key part of integrating async IO in application code.
One key feature is that the awaitFuture(Future)
and
awaitFuture(Future, long, TimeUnit)
calls will
extract and rethrow exceptions raised in the future's execution,
including extracting the inner IOException of any
UncheckedIOException
raised in the future.
This makes it somewhat easier to execute IOException-raising
code inside futures.
Modifier and Type | Method and Description |
---|---|
static <T> T |
awaitFuture(Future<T> future)
Given a future, evaluate it.
|
static <T> T |
awaitFuture(Future<T> future,
long timeout,
TimeUnit unit)
Given a future, evaluate it.
|
static <T> T |
raiseInnerCause(CompletionException e)
Extract the cause of a completion failure and rethrow it if an IOE
or RTE.
|
static <T> T |
raiseInnerCause(ExecutionException e)
From the inner cause of an execution exception, extract the inner cause
if it is an IOE or RTE.
|
static IOException |
unwrapInnerException(Throwable e)
From the inner cause of an execution exception, extract the inner cause
to an IOException, raising RuntimeExceptions and Errors immediately.
|
public static <T> T awaitFuture(Future<T> future) throws InterruptedIOException, IOException, RuntimeException
Any exception generated in the future is extracted and rethrown.
T
- type of the result.future
- future to evaluateInterruptedIOException
- future was interruptedIOException
- if something went wrongRuntimeException
- any nested RTE thrownpublic static <T> T awaitFuture(Future<T> future, long timeout, TimeUnit unit) throws InterruptedIOException, IOException, RuntimeException, TimeoutException
Any exception generated in the future is extracted and rethrown.
T
- type of the result.future
- future to evaluateInterruptedIOException
- future was interruptedIOException
- if something went wrongRuntimeException
- any nested RTE thrownTimeoutException
- the future timed out.public static <T> T raiseInnerCause(ExecutionException e) throws IOException
T
- type of return value.e
- exception.IOException
- either the inner IOException, or a wrapper around
any non-Runtime-ExceptionRuntimeException
- if that is the inner cause.public static <T> T raiseInnerCause(CompletionException e) throws IOException
T
- type of return value.e
- exception.IOException
- either the inner IOException, or a wrapper around
any non-Runtime-ExceptionRuntimeException
- if that is the inner cause.public static IOException unwrapInnerException(Throwable e)
UncheckedIOException
: return the causee
- exception.RuntimeException
- if that is the inner cause.Error
- if that is the inner cause.Copyright © 2021 Apache Software Foundation. All rights reserved.