Class SharedTaskContextHolder

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

public final class SharedTaskContextHolder extends Object
Is used by the guarded task to register it's task abort command (if applicable).
Since:
2.0.0
  • Method Details

    • register

      public static void register(SharedTaskContext sharedTaskContext)
      Initialize the SharedTaskContextHolder with the sharedTaskContext.

      By registering the sharedTaskContext the strategy is made available for other code within the executing thread. This allows the guard task to abort the task being executed without knowing how.

      The task itself is responsible to register a TaskAbortStrategy in the sharedTaskContext. This can be done by calling the setTaskAbortStrategy(TaskAbortStrategy).

      As an example, see the HawaiiHttpComponentsClientHttpRequestFactory.

      Parameters:
      sharedTaskContext - the shared strategy to hold for the current thread.
    • remove

      public static void remove()
      Removes the current SharedTaskContext from the ThreadLocal store.
    • setTaskAbortStrategy

      public static void setTaskAbortStrategy(TaskAbortStrategy taskAbortStrategy)
      Set the current thread's taskAbortStrategy.

      This sets the taskAbortStrategy into the thread's SharedTaskContext.

      Parameters:
      taskAbortStrategy - The strategy to set.
    • get

      public static SharedTaskContext get()
      Getter for #sharedTaskAbortStrategy.
      Returns:
      the shared task abort strategy
    • getTaskId

      public static String getTaskId()
      Return the task id for the current thread's task.

      It delegates to the thread local SharedTaskContext.getTaskId().

      Returns:
      The task's id.