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
- Author:
- Rutger Lubbers, Paul Klos
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static SharedTaskContext
get()
Getter for #sharedTaskAbortStrategy.static String
getTaskId()
Return the task id for the current thread's task.static void
register(SharedTaskContext sharedTaskContext)
Initialize theSharedTaskContextHolder
with thesharedTaskContext
.static void
remove()
Removes the currentSharedTaskContext
from the ThreadLocal store.static void
setTaskAbortStrategy(TaskAbortStrategy taskAbortStrategy)
Set the current thread'staskAbortStrategy
.
-
-
-
Method Detail
-
register
public static void register(SharedTaskContext sharedTaskContext)
Initialize theSharedTaskContextHolder
with thesharedTaskContext
.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 thesharedTaskContext
. This can be done by calling thesetTaskAbortStrategy(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 currentSharedTaskContext
from the ThreadLocal store.
-
setTaskAbortStrategy
public static void setTaskAbortStrategy(TaskAbortStrategy taskAbortStrategy)
Set the current thread'staskAbortStrategy
.This sets the
taskAbortStrategy
into the thread'sSharedTaskContext
.- 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 localSharedTaskContext.getTaskId()
.- Returns:
- The task's id.
-
-