Class WorkerExecutor

java.lang.Object
io.vertx.mutiny.core.WorkerExecutor
All Implemented Interfaces:
MutinyDelegate, Measured

public class WorkerExecutor extends Object implements Measured, MutinyDelegate
An executor for executing blocking code in Vert.x .

It provides the same executeBlocking operation than Context and Vertx but on a separate worker pool.

NOTE: This class has been automatically generated from the original non Mutiny-ified interface.

Author:
Julien Viet
See Also:
  • WorkerExecutor
  • Field Details

  • Constructor Details

    • WorkerExecutor

      public WorkerExecutor(io.vertx.core.WorkerExecutor delegate)
      Create a new instance of WorkerExecutor delegating to the given (non-null) instance of WorkerExecutor.
    • WorkerExecutor

      public WorkerExecutor(Object delegate)
  • Method Details

    • getDelegate

      public io.vertx.core.WorkerExecutor getDelegate()
      Get the delegate instance.

      This method returns the instance on which this shim is delegating the calls. And so, give you access to the bare API.

      Specified by:
      getDelegate in interface Measured
      Specified by:
      getDelegate in interface MutinyDelegate
      Returns:
      the delegate instance
    • executeBlocking

      @CheckReturnValue public <T> io.smallrye.mutiny.Uni<T> executeBlocking(Callable<T> blockingCodeHandler, boolean ordered)
      Safely execute some blocking code.

      Executes the blocking code in the handler blockingCodeHandler using a thread from the worker pool.

      The returned uni will be completed with the result on the original context (i.e. on the original event loop of the caller) or failed when the handler throws an exception.

      In the blockingCodeHandler the current context remains the original context and therefore any task scheduled in the blockingCodeHandler will be executed on this context and not on the worker thread.

      Unlike the bare Vert.x variant, this method returns a Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.

      Don't forget to subscribe on it to trigger the operation.

      Type Parameters:
      T - the type of the result
      Parameters:
      blockingCodeHandler - handler representing the blocking code to run
      ordered - if true then if executeBlocking is called several times on the same context, the executions for that context will be executed serially, not in parallel. if false then they will be no ordering guarantees
      Returns:
      A Uni representing the asynchronous result of this operation.
      See Also:
      • WorkerExecutor.executeBlocking(Callable, boolean)
    • executeBlockingAndAwait

      public <T> T executeBlockingAndAwait(Callable<T> blockingCodeHandler, boolean ordered)
      Safely execute some blocking code.

      Executes the blocking code in the handler blockingCodeHandler using a thread from the worker pool.

      The returned underlying uni will be completed with the result on the original context (i.e. on the original event loop of the caller) or failed when the handler throws an exception.

      In the blockingCodeHandler the current context remains the original context and therefore any task scheduled in the blockingCodeHandler will be executed on this context and not on the worker thread.

      Unlike the bare Vert.x variant, this method returns a WorkerExecutor. This method awaits indefinitely for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      Type Parameters:
      T - the type of the result
      Parameters:
      blockingCodeHandler - handler representing the blocking code to run
      ordered - if true then if executeBlocking is called several times on the same context, the executions for that context will be executed serially, not in parallel. if false then they will be no ordering guarantees
      Returns:
      The operation result
      See Also:
      • WorkerExecutor.executeBlocking(Callable, boolean)
    • executeBlockingAndForget

      public <T> WorkerExecutor executeBlockingAndForget(Callable<T> blockingCodeHandler, boolean ordered)
      Safely execute some blocking code.

      Executes the blocking code in the handler blockingCodeHandler using a thread from the worker pool.

      The returned underlying uni will be completed with the result on the original context (i.e. on the original event loop of the caller) or failed when the handler throws an exception.

      In the blockingCodeHandler the current context remains the original context and therefore any task scheduled in the blockingCodeHandler will be executed on this context and not on the worker thread.

      Unlike the bare Vert.x variant, this method ignores the WorkerExecutor result or any failure.

      Type Parameters:
      T - the type of the result
      Parameters:
      blockingCodeHandler - handler representing the blocking code to run
      ordered - if true then if executeBlocking is called several times on the same context, the executions for that context will be executed serially, not in parallel. if false then they will be no ordering guarantees
      Returns:
      The current instance to chain operations if needed.
      See Also:
      • WorkerExecutor.executeBlocking(Callable, boolean)
    • executeBlocking

      @CheckReturnValue public <T> io.smallrye.mutiny.Uni<T> executeBlocking(Callable<T> blockingCodeHandler)
      Like executeBlocking(Callable, boolean) called with ordered = true.

      Unlike the bare Vert.x variant, this method returns a Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.

      Don't forget to subscribe on it to trigger the operation.

      Returns:
      A Uni representing the asynchronous result of this operation.
      See Also:
      • WorkerExecutor.executeBlocking(Callable)
    • executeBlockingAndAwait

      public <T> T executeBlockingAndAwait(Callable<T> blockingCodeHandler)
      Like executeBlocking(Callable, boolean) called with ordered = true.

      Unlike the bare Vert.x variant, this method returns a WorkerExecutor. This method awaits indefinitely for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      Returns:
      The operation result
      See Also:
      • WorkerExecutor.executeBlocking(Callable)
    • executeBlockingAndForget

      public <T> WorkerExecutor executeBlockingAndForget(Callable<T> blockingCodeHandler)
      Like executeBlocking(Callable, boolean) called with ordered = true.

      Unlike the bare Vert.x variant, this method ignores the WorkerExecutor result or any failure.

      Returns:
      The current instance to chain operations if needed.
      See Also:
      • WorkerExecutor.executeBlocking(Callable)
    • close

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> close()
      Close the executor.

      Unlike the bare Vert.x variant, this method returns a Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.

      Don't forget to subscribe on it to trigger the operation.

      Returns:
      A Uni representing the asynchronous result of this operation.
      See Also:
      • WorkerExecutor.close()
    • closeAndAwait

      public void closeAndAwait()
      Close the executor.

      Unlike the bare Vert.x variant, this method returns a Void. This method awaits indefinitely for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      See Also:
      • WorkerExecutor.close()
    • closeAndForget

      public WorkerExecutor closeAndForget()
      Close the executor.

      Unlike the bare Vert.x variant, this method ignores the Void result or any failure.

      Returns:
      The current instance to chain operations if needed.
      See Also:
      • WorkerExecutor.close()
    • isMetricsEnabled

      public boolean isMetricsEnabled()
      Whether the metrics are enabled for this measured object
      Specified by:
      isMetricsEnabled in interface Measured
      Returns:
      true if metrics are enabled
    • newInstance

      public static WorkerExecutor newInstance(io.vertx.core.WorkerExecutor delegate)
      Creates a new instance of the WorkerExecutor.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object