Package ch.ivyteam.ivy.request.async
Interface IvyAsyncExecutor
public interface IvyAsyncExecutor
Runs asynchronous code in an Ivy context.
This allows the execution of code that runs against the Ivy API in any thread pool.
By default, the Ivy context active while the executor was created is used, but a custom context can be provided instead.
This allows the execution of code that runs against the Ivy API in any thread pool.
By default, the Ivy context active while the executor was created is used, but a custom context can be provided instead.
Sample:
Callable<String> slowFunction = () -> {
Thread.sleep(10_000);
return "result";
};
CompletableFuture<String> result = IvyAsyncExecutor.create().call(slowFunction);
- Since:
- 12.0.0
- API:
- This is a public API.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceOptions for the custom executor service used by theIvyAsyncExecutorprovided viaexecutor(ExecutorService, ExecutorOptions). -
Method Summary
Modifier and TypeMethodDescription<T> CompletableFuture<T> Asynchronously executes the method call of a callable.static IvyAsyncExecutorcreate()Creates an executor with the current Ivy context.execute(Executable executable) Asynchronously executes the method execute of an executable.executor(ExecutorService executor) executor(ExecutorService executor, IvyAsyncExecutor.ExecutorOptions options) Allows to provide a custom executor service to be used by the executor.
By default, the executor service provided byForkJoinPool.commonPool()is used.
Executor services provided to this method will beExecutorService.shutdown()automatically once the request that created the executor is finished.<T> CompletableFuture<T> Asynchronously gets the result supplied by a supplier.pmv(IProcessModelVersion pmv) Sets the process model version of the Ivy context used by the executor.Asynchronously executes the method run of a runnable.Sets the session of the Ivy context used by the executor.
-
Method Details
-
get
Asynchronously gets the result supplied by a supplier.- Type Parameters:
T- the type of results supplied by the supplier- Parameters:
supplier-Supplier- Returns:
CompletableFutureof the result- API:
- This public API is available in Java.
-
call
Asynchronously executes the method call of a callable.- Type Parameters:
T- the result type of the call method of the callable- Parameters:
callable-Callable- Returns:
CompletableFutureof the result- API:
- This public API is available in Java.
-
run
Asynchronously executes the method run of a runnable.- Parameters:
runnable-Runnable- Returns:
CompletableFutureof the result- API:
- This public API is available in Java.
-
execute
Asynchronously executes the method execute of an executable.- Parameters:
executable-Executable- Returns:
CompletableFutureof the result- API:
- This public API is available in Java.
-
create
Creates an executor with the current Ivy context.- Returns:
- An new
IvyAsyncExecutor - API:
- This public API is available in Java.
-
pmv
Sets the process model version of the Ivy context used by the executor.Sample:
IProcessModelVersion pmv = IApplication.current().findProcessModelVersion("pmv$1"); CompletableFuture<String> result = IvyAsyncExecutor.create().pmv(pmv).call(slowFunction);- Parameters:
pmv- theIProcessModelVersionto be set- Returns:
- This
IvyAsyncExecutor - API:
- This public API is available in Java.
-
session
Sets the session of the Ivy context used by the executor.Sample:
ISession session = ISecurityContext.current().sessions().systemUser(); CompletableFuture<String> result = IvyAsyncExecutor.create().session(session).call(slowFunction);
- Parameters:
session- theISessionto be set- Returns:
- This
IvyAsyncExecutor - API:
- This public API is available in Java.
-
executor
- Parameters:
executor- theExecutorServiceto be used- Returns:
- This
IvyAsyncExecutor - See Also:
- API:
- This public API is available in Java.
-
executor
Allows to provide a custom executor service to be used by the executor.
By default, the executor service provided byForkJoinPool.commonPool()is used.
Executor services provided to this method will beExecutorService.shutdown()automatically once the request that created the executor is finished. This behavior can be changed via the argumentIvyAsyncExecutor.ExecutorOptions.Sample:
ExecutorService executor = Executors.newSingleThreadExecutor(); CompletableFuture<String> result = IvyAsyncExecutor.create().executor(executor).call(slowFunction);
- Parameters:
executor- theExecutorServiceto be used- Returns:
- This
IvyAsyncExecutor - Since:
- 13.2
- API:
- This public API is available in Java.
-