Package dev.failsafe
Class Functions
- java.lang.Object
-
- dev.failsafe.Functions
-
final class Functions extends java.lang.Object
Utilities for creating and applying Failsafe executable functions.
-
-
Constructor Summary
Constructors Constructor Description Functions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static <R> java.util.function.Function<SyncExecutionImpl<R>,ExecutionResult<R>>
get(ContextualSupplier<R,R> supplier, java.util.concurrent.Executor executor)
Returns a Supplier for synchronous executions that pre-executes theexecution
, applies thesupplier
, records the result and returns the result.(package private) static <R> java.util.function.Function<AsyncExecutionInternal<R>,java.util.concurrent.CompletableFuture<ExecutionResult<R>>>
getPromise(ContextualSupplier<R,R> supplier, java.util.concurrent.Executor executor)
Returns a Function for asynchronous executions that pre-executes theexecution
, applies thesupplier
, records the result and returns a promise containing the result.(package private) static <R> java.util.function.Function<AsyncExecutionInternal<R>,java.util.concurrent.CompletableFuture<ExecutionResult<R>>>
getPromiseExecution(AsyncRunnable<R> runnable, java.util.concurrent.Executor executor)
Returns a Function for asynchronous executions that pre-executes theexecution
, runs therunnable
, and attempts to complete theexecution
if a failure occurs.(package private) static <R> java.util.function.Function<AsyncExecutionInternal<R>,java.util.concurrent.CompletableFuture<ExecutionResult<R>>>
getPromiseOfStage(ContextualSupplier<R,? extends java.util.concurrent.CompletionStage<? extends R>> supplier, FailsafeFuture<R> future, java.util.concurrent.Executor executor)
Returns a Function that for asynchronous executions that pre-executes theexecution
, applies thesupplier
, records the result and returns a promise containing the result.private static void
handleExecutorThrowable(java.lang.Throwable e)
(package private) static <R> java.util.function.Function<AsyncExecutionInternal<R>,java.util.concurrent.CompletableFuture<ExecutionResult<R>>>
toAsync(java.util.function.Function<AsyncExecutionInternal<R>,java.util.concurrent.CompletableFuture<ExecutionResult<R>>> innerFn, Scheduler scheduler, FailsafeFuture<R> future)
Returns a Function that asynchronously applies theinnerFn
on the first call, synchronously on subsequent calls, and returns a promise containing the result.(package private) static ContextualSupplier<java.lang.Void,java.lang.Void>
toCtxSupplier(CheckedRunnable runnable)
(package private) static <R,T>
ContextualSupplier<R,T>toCtxSupplier(CheckedSupplier<T> supplier)
(package private) static ContextualSupplier<java.lang.Void,java.lang.Void>
toCtxSupplier(ContextualRunnable<java.lang.Void> runnable)
(package private) static <R> java.util.function.Function<AsyncExecutionInternal<R>,java.util.concurrent.CompletableFuture<ExecutionResult<R>>>
toExecutionAware(java.util.function.Function<AsyncExecutionInternal<R>,java.util.concurrent.CompletableFuture<ExecutionResult<R>>> innerFn)
Returns a Function that returns an execution result if one was previously recorded, else applies theinnerFn
.(package private) static <T,R>
CheckedFunction<T,R>toFn(CheckedConsumer<T> consumer)
(package private) static <T,R>
CheckedFunction<T,R>toFn(CheckedRunnable runnable)
(package private) static <T,R>
CheckedFunction<T,R>toFn(CheckedSupplier<? extends R> supplier)
(package private) static <T,R>
CheckedFunction<T,R>toFn(R result)
(package private) static <R> AsyncRunnable<R>
withExecutor(AsyncRunnable<R> runnable, java.util.concurrent.Executor executor)
(package private) static <R,T>
ContextualSupplier<R,T>withExecutor(ContextualSupplier<R,T> supplier, java.util.concurrent.Executor executor)
-
-
-
Method Detail
-
get
static <R> java.util.function.Function<SyncExecutionImpl<R>,ExecutionResult<R>> get(ContextualSupplier<R,R> supplier, java.util.concurrent.Executor executor)
Returns a Supplier for synchronous executions that pre-executes theexecution
, applies thesupplier
, records the result and returns the result. This implementation also handles Thread interrupts.- Type Parameters:
R
- result type
-
getPromise
static <R> java.util.function.Function<AsyncExecutionInternal<R>,java.util.concurrent.CompletableFuture<ExecutionResult<R>>> getPromise(ContextualSupplier<R,R> supplier, java.util.concurrent.Executor executor)
Returns a Function for asynchronous executions that pre-executes theexecution
, applies thesupplier
, records the result and returns a promise containing the result.- Type Parameters:
R
- result type
-
getPromiseExecution
static <R> java.util.function.Function<AsyncExecutionInternal<R>,java.util.concurrent.CompletableFuture<ExecutionResult<R>>> getPromiseExecution(AsyncRunnable<R> runnable, java.util.concurrent.Executor executor)
Returns a Function for asynchronous executions that pre-executes theexecution
, runs therunnable
, and attempts to complete theexecution
if a failure occurs. Locks to ensure the resulting supplier cannot be applied multiple times concurrently.- Type Parameters:
R
- result type
-
getPromiseOfStage
static <R> java.util.function.Function<AsyncExecutionInternal<R>,java.util.concurrent.CompletableFuture<ExecutionResult<R>>> getPromiseOfStage(ContextualSupplier<R,? extends java.util.concurrent.CompletionStage<? extends R>> supplier, FailsafeFuture<R> future, java.util.concurrent.Executor executor)
Returns a Function that for asynchronous executions that pre-executes theexecution
, applies thesupplier
, records the result and returns a promise containing the result.- Type Parameters:
R
- result type- Throws:
java.lang.UnsupportedOperationException
- when using
-
toExecutionAware
static <R> java.util.function.Function<AsyncExecutionInternal<R>,java.util.concurrent.CompletableFuture<ExecutionResult<R>>> toExecutionAware(java.util.function.Function<AsyncExecutionInternal<R>,java.util.concurrent.CompletableFuture<ExecutionResult<R>>> innerFn)
Returns a Function that returns an execution result if one was previously recorded, else applies theinnerFn
.- Type Parameters:
R
- result type
-
toAsync
static <R> java.util.function.Function<AsyncExecutionInternal<R>,java.util.concurrent.CompletableFuture<ExecutionResult<R>>> toAsync(java.util.function.Function<AsyncExecutionInternal<R>,java.util.concurrent.CompletableFuture<ExecutionResult<R>>> innerFn, Scheduler scheduler, FailsafeFuture<R> future)
Returns a Function that asynchronously applies theinnerFn
on the first call, synchronously on subsequent calls, and returns a promise containing the result.- Type Parameters:
R
- result type
-
toCtxSupplier
static ContextualSupplier<java.lang.Void,java.lang.Void> toCtxSupplier(CheckedRunnable runnable)
-
toCtxSupplier
static ContextualSupplier<java.lang.Void,java.lang.Void> toCtxSupplier(ContextualRunnable<java.lang.Void> runnable)
-
toCtxSupplier
static <R,T> ContextualSupplier<R,T> toCtxSupplier(CheckedSupplier<T> supplier)
-
withExecutor
static <R,T> ContextualSupplier<R,T> withExecutor(ContextualSupplier<R,T> supplier, java.util.concurrent.Executor executor)
-
withExecutor
static <R> AsyncRunnable<R> withExecutor(AsyncRunnable<R> runnable, java.util.concurrent.Executor executor)
-
handleExecutorThrowable
private static void handleExecutorThrowable(java.lang.Throwable e)
-
toFn
static <T,R> CheckedFunction<T,R> toFn(CheckedConsumer<T> consumer)
-
toFn
static <T,R> CheckedFunction<T,R> toFn(CheckedRunnable runnable)
-
toFn
static <T,R> CheckedFunction<T,R> toFn(CheckedSupplier<? extends R> supplier)
-
toFn
static <T,R> CheckedFunction<T,R> toFn(R result)
-
-