@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> CompletableFuture<T> |
eval(org.apache.hadoop.util.functional.CallableRaisingIOE<T> callable)
Evaluate a CallableRaisingIOE in the current thread,
converting IOEs to RTEs and propagating.
|
static void |
propagateOptions(FSBuilder<?,?> builder,
Configuration conf,
String prefix,
boolean mandatory)
Propagate options to any builder, converting everything with the
prefix to an option where, if there were 2+ dot-separated elements,
it is converted to a schema.
|
static <T,U extends FSBuilder<T,U>> |
propagateOptions(FSBuilder<T,U> builder,
Configuration conf,
String optionalPrefix,
String mandatoryPrefix)
Propagate options to any builder, converting everything with the
prefix to an option where, if there were 2+ dot-separated elements,
it is converted to a schema.
|
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 evaluatetimeout
- timeout to waitunit
- time unit.InterruptedIOException
- 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.public static <T,U extends FSBuilder<T,U>> FSBuilder<T,U> propagateOptions(FSBuilder<T,U> builder, Configuration conf, String optionalPrefix, String mandatoryPrefix)
propagateOptions(FSBuilder, Configuration, String, boolean)
.T
- type of resultU
- type of builderbuilder
- builder to modifyconf
- configuration to readoptionalPrefix
- prefix for optional settingsmandatoryPrefix
- prefix for mandatory settingspublic static void propagateOptions(FSBuilder<?,?> builder, Configuration conf, String prefix, boolean mandatory)
fs.example.s3a.option becomes "s3a.option" fs.example.fs.io.policy becomes "fs.io.policy" fs.example.something becomes "something"
builder
- builder to modifyconf
- configuration to readprefix
- prefix to scan/stripmandatory
- are the options to be mandatory or optional?public static <T> CompletableFuture<T> eval(org.apache.hadoop.util.functional.CallableRaisingIOE<T> callable)
T
- Return type.callable
- callable to invokeUnsupportedOperationException
- fail fast if unsupportedIllegalArgumentException
- invalid argumentCopyright © 2023 Apache Software Foundation. All rights reserved.