Class DelegatingExecutor

java.lang.Object
org.hawaiiframework.async.DelegatingExecutor
All Implemented Interfaces:
Executor, org.springframework.core.task.AsyncTaskExecutor, org.springframework.core.task.TaskExecutor, org.springframework.scheduling.SchedulingTaskExecutor

public class DelegatingExecutor extends Object implements org.springframework.core.task.AsyncTaskExecutor, org.springframework.scheduling.SchedulingTaskExecutor
Task executor that delegates to the task executor configured for a task.

In addition to the delegate, the async configuration properties and the task name is stored, so we know which task this executor is for and we are able to determine the timeout.

Since:
2.0.0
  • Constructor Details

    • DelegatingExecutor

      public DelegatingExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor delegate, ExecutorConfigurationProperties executorConfigurationProperties, Collection<TaskListenerFactory> taskListenerFactories, String taskName)
      Constructor.
      Parameters:
      delegate - the delegate
      executorConfigurationProperties - the configuration properties
      taskListenerFactories - The task context providers.
      taskName - the task name
  • Method Details

    • execute

      public void execute(@NonNull Runnable task)

      Configures a SharedTaskContextHolder before delegating execution.

      Specified by:
      execute in interface Executor
      Specified by:
      execute in interface org.springframework.core.task.TaskExecutor
    • execute

      @Deprecated public void execute(@NonNull Runnable task, long startTimeout)
      Deprecated.
      see super class for explanation. Configures a SharedTaskContextHolder before delegating execution.
      Specified by:
      execute in interface org.springframework.core.task.AsyncTaskExecutor
    • submit

      public Future<?> submit(@NonNull Runnable task)

      Configures a SharedTaskContextHolder before delegating execution.

      Specified by:
      submit in interface org.springframework.core.task.AsyncTaskExecutor
    • submit

      public <T> Future<T> submit(@NonNull Callable<T> task)

      Configures a SharedTaskContextHolder before delegating execution.

      Specified by:
      submit in interface org.springframework.core.task.AsyncTaskExecutor
      Type Parameters:
      T - The return type of the task.
      Parameters:
      task - The task to submit to be executed.
      Returns:
      A future for the task.
    • getExecutorStatistics

      public ExecutorStatisticsView getExecutorStatistics()
      Return the view on the statistics.
      Returns:
      A view on the executor's statistics.
    • hasDelegate

      public boolean hasDelegate(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor executor)
      For testing purposes.
      Parameters:
      executor - The executor to check this delegate against.
      Returns:
      true if this delegating executor has the given executor.
    • getActiveCount

      public int getActiveCount()
      For testing purposes. Return the number of currently active threads.
      Returns:
      the number of threads
      See Also:
    • prefersShortLivedTasks

      public boolean prefersShortLivedTasks()
      Specified by:
      prefersShortLivedTasks in interface org.springframework.scheduling.SchedulingTaskExecutor