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.

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.
  • Method Details

    • get

      <T> CompletableFuture<T> get(Supplier<T> supplier)
      Asynchronously gets the result supplied by a supplier.
      Type Parameters:
      T - the type of results supplied by the supplier
      Parameters:
      supplier - Supplier
      Returns:
      CompletableFuture of the result
      API:
      This public API is available in Java.
    • call

      <T> CompletableFuture<T> call(Callable<T> callable)
      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:
      CompletableFuture of the result
      API:
      This public API is available in Java.
    • run

      Asynchronously executes the method run of a runnable.
      Parameters:
      runnable - Runnable
      Returns:
      CompletableFuture of the result
      API:
      This public API is available in Java.
    • execute

      CompletableFuture<Void> execute(Executable executable)
      Asynchronously executes the method execute of an executable.
      Parameters:
      executable - Executable
      Returns:
      CompletableFuture of the result
      API:
      This public API is available in Java.
    • create

      static IvyAsyncExecutor 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 - the IProcessModelVersion to be set
      Returns:
      The executor
      API:
      This public API is available in Java.
    • session

      IvyAsyncExecutor session(ISession 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 - the ISession to be set
      Returns:
      The executor
      API:
      This public API is available in Java.
    • executor

      IvyAsyncExecutor executor(ExecutorService executor)
      Allows to provide a custom executor service to be used by the executor.
      By default, the executor service provided by ForkJoinPool.commonPool() is used.
      Executor services provided to this method will be ExecutorService.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 - the ExecutorService to be used
      Returns:
      The executor
      API:
      This public API is available in Java.