Class SharedTaskContext

java.lang.Object
org.hawaiiframework.async.timeout.SharedTaskContext

public class SharedTaskContext extends Object
The strategy is used by the TimeoutGuardTask to stop a running guarded task.

This class is called shared since it is shared by the guarded task and the guard task in order to communicate the task abort strategy.

Since:
2.0.0
  • Constructor Details

    • SharedTaskContext

      public SharedTaskContext(String taskName, ExecutorConfigurationProperties executorConfigurationProperties, ExecutorStatistics executorStatistics, List<TaskListener> taskListeners)
      Construct an instance.
      Parameters:
      taskName - the task name
      executorConfigurationProperties - the executor configuration properties
      executorStatistics - executor statisctics.
      taskListeners - task listeners.
  • Method Details

    • setTaskRemoveStrategy

      public void setTaskRemoveStrategy(TaskRemoveStrategy taskRemoveStrategy)
      Register the task removal strategy.
      Parameters:
      taskRemoveStrategy - The TaskRemoveStrategy to share.
    • setTimeoutGuardTaskRemoveStrategy

      public void setTimeoutGuardTaskRemoveStrategy(TaskRemoveStrategy timeoutGuardTaskRemoveStrategy)
      Register the timeout guard task removal strategy.
      Parameters:
      timeoutGuardTaskRemoveStrategy - the TaskRemoveStrategy to set.
    • setTaskAbortStrategy

      public void setTaskAbortStrategy(TaskAbortStrategy taskAbortStrategy)
      Register the task abort strategy.
      Parameters:
      taskAbortStrategy - The TaskAbortStrategy to share.
    • abortBusinessTask

      public void abortBusinessTask()
      Invoke the taskAbortStrategy.
    • getTimeout

      public Integer getTimeout()
      Get the timeout for the task this strategy is for.
      Returns:
      the timeout
      See Also:
    • getTaskId

      public String getTaskId()
      Get the task's id.
      Returns:
      The task's id.
    • getTaskName

      public String getTaskName()
      Retrieve the task's name.
      Returns:
      The task's name.
    • isAborted

      public boolean isAborted()
      Whether the task has been aborted or not..
      Returns:
      true if the task has been aborted.
    • timeout

      public void timeout()
      Remove the guarded task from the queue, or else abort the running guarded task.
    • startExecution

      public void startExecution()
      Signal the start of the task's execution.
    • finish

      public void finish()
      This method is invoked when the guarded task is finished.

      It will perform cleanups. The finish should always be invoked.

    • getTaskStatistics

      public TaskStatistics getTaskStatistics()
      Return the task's execution statistics.
      Returns:
      The task statistics.