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:
- 10.0.24
- API:
- This is a public API.
-
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) 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 instance of the executor
- 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:
- The executor
- 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:
- The executor
- 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.Sample:
ExecutorService executor = Executors.newSingleThreadExecutor(); CompletableFuture<String> result = IvyAsyncExecutor.create().executor(executor).call(slowFunction);
- Parameters:
executor- theExecutorServiceto be used- Returns:
- The executor
- API:
- This public API is available in Java.
-