Package dev.failsafe
Class Functions
java.lang.Object
dev.failsafe.Functions
Utilities for creating and applying Failsafe executable functions.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static <R> Function<SyncExecutionImpl<R>, ExecutionResult<R>> get(ContextualSupplier<R, R> supplier, 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> Function<AsyncExecutionInternal<R>, CompletableFuture<ExecutionResult<R>>> getPromise(ContextualSupplier<R, R> supplier, 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> Function<AsyncExecutionInternal<R>, CompletableFuture<ExecutionResult<R>>> getPromiseExecution(AsyncRunnable<R> runnable, Executor executor) Returns a Function for asynchronous executions that pre-executes theexecution, runs therunnable, and attempts to complete theexecutionif a failure occurs.(package private) static <R> Function<AsyncExecutionInternal<R>, CompletableFuture<ExecutionResult<R>>> getPromiseOfStage(ContextualSupplier<R, ? extends CompletionStage<? extends R>> supplier, FailsafeFuture<R> future, 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(package private) static <R> Function<AsyncExecutionInternal<R>, CompletableFuture<ExecutionResult<R>>> toAsync(Function<AsyncExecutionInternal<R>, CompletableFuture<ExecutionResult<R>>> innerFn, Scheduler scheduler, FailsafeFuture<R> future) Returns a Function that asynchronously applies theinnerFnon the first call, synchronously on subsequent calls, and returns a promise containing the result.(package private) static ContextualSupplier<Void, Void> toCtxSupplier(CheckedRunnable runnable) (package private) static <R,T> ContextualSupplier <R, T> toCtxSupplier(CheckedSupplier<T> supplier) (package private) static ContextualSupplier<Void, Void> toCtxSupplier(ContextualRunnable<Void> runnable) (package private) static <R> Function<AsyncExecutionInternal<R>, CompletableFuture<ExecutionResult<R>>> toExecutionAware(Function<AsyncExecutionInternal<R>, 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, Executor executor) (package private) static <R,T> ContextualSupplier <R, T> withExecutor(ContextualSupplier<R, T> supplier, Executor executor)
-
Constructor Details
-
Functions
Functions()
-
-
Method Details
-
get
static <R> Function<SyncExecutionImpl<R>,ExecutionResult<R>> get(ContextualSupplier<R, R> supplier, 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> Function<AsyncExecutionInternal<R>,CompletableFuture<ExecutionResult<R>>> getPromise(ContextualSupplier<R, R> supplier, 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> Function<AsyncExecutionInternal<R>,CompletableFuture<ExecutionResult<R>>> getPromiseExecution(AsyncRunnable<R> runnable, Executor executor) Returns a Function for asynchronous executions that pre-executes theexecution, runs therunnable, and attempts to complete theexecutionif a failure occurs. Locks to ensure the resulting supplier cannot be applied multiple times concurrently.- Type Parameters:
R- result type
-
getPromiseOfStage
static <R> Function<AsyncExecutionInternal<R>,CompletableFuture<ExecutionResult<R>>> getPromiseOfStage(ContextualSupplier<R, ? extends CompletionStage<? extends R>> supplier, FailsafeFuture<R> future, 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:
UnsupportedOperationException- when using
-
toExecutionAware
static <R> Function<AsyncExecutionInternal<R>,CompletableFuture<ExecutionResult<R>>> toExecutionAware(Function<AsyncExecutionInternal<R>, 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> Function<AsyncExecutionInternal<R>,CompletableFuture<ExecutionResult<R>>> toAsync(Function<AsyncExecutionInternal<R>, CompletableFuture<ExecutionResult<R>>> innerFn, Scheduler scheduler, FailsafeFuture<R> future) Returns a Function that asynchronously applies theinnerFnon the first call, synchronously on subsequent calls, and returns a promise containing the result.- Type Parameters:
R- result type
-
toCtxSupplier
-
toCtxSupplier
-
toCtxSupplier
-
withExecutor
static <R,T> ContextualSupplier<R,T> withExecutor(ContextualSupplier<R, T> supplier, Executor executor) -
withExecutor
-
handleExecutorThrowable
-
toFn
-
toFn
-
toFn
-
toFn
-