Class TaskRegistry
java.lang.Object
de.iip_ecosphere.platform.support.TaskRegistry
Thread-based mechanism to track tasks (AAS, through UI). Call
cleanup() regularly
depending on getTimeout().- Author:
- Holger Eichelberger, SSE
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents data associated to a task.static enumConstants to represent the task status. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static Map<String, TaskRegistry.TaskData> static final TaskRegistry.TaskDataprivate static Map<Long, TaskRegistry.TaskData> private static long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidassociateTask(Thread thread, TaskRegistry.TaskData data) Associates existing taskdatawiththread.static voidcleanup()Cleans up outdated task data after no change withingetTimeout().private static voidcleanup(long now, Iterator<TaskRegistry.TaskData> iter) Checks the task data initerfor cleanup.static TaskRegistry.TaskDataReturns the task data assigned to the current thread.static TaskRegistry.TaskDatagetTaskData(String id) Returns the task data assigned to the given task id.static TaskRegistry.TaskDatagetTaskData(Thread thread) Returns the task data assigned to the given thread.private static longgetThreadId(Thread thread) Returns the thread id ofthread.static longReturns the timeout indicating aTaskRegistry.TaskDatainstance to be cleaned up.static TaskRegistry.TaskDataRegisters a new task on the current task.static TaskRegistry.TaskDataregisterTask(String taskId) Registers a new task on the current task.static TaskRegistry.TaskDataregisterTask(Thread thread) Registers a new task for the giventhread, turning a still running one intoTaskRegistry.TaskStatus.SUPPRESSED.static TaskRegistry.TaskDataregisterTask(Thread thread, String taskId) Registers a new task for the giventhread, turning a still running one intoTaskRegistry.TaskStatus.SUPPRESSED.static longsetTimeout(long to) Changes the timeout indicating aTaskRegistry.TaskDatainstance to be cleaned up.static voidstopTask()Stops the actual task of the current thread.static voidStops the given task.static voidStops the given task.static voidunassociateTask(Thread thread) Unassociates a thread.
-
Field Details
-
NO_TASK
-
timeout
private static long timeout -
idToData
-
threadToData
-
-
Constructor Details
-
TaskRegistry
public TaskRegistry()
-
-
Method Details
-
getThreadId
Returns the thread id ofthread.- Parameters:
thread- the thread, may be null the the id of the current thread is returned- Returns:
- the thread id
-
getTimeout
public static long getTimeout()Returns the timeout indicating aTaskRegistry.TaskDatainstance to be cleaned up.- Returns:
- the timeout in ms
-
setTimeout
public static long setTimeout(long to) Changes the timeout indicating aTaskRegistry.TaskDatainstance to be cleaned up.- Parameters:
to- the new timeout in ms- Returns:
- the old timeout in ms
-
registerTask
Registers a new task on the current task.- Returns:
- the task data of the new task
-
registerTask
Registers a new task on the current task.- Parameters:
taskId- a given task id, e.g., when passed in through distributed execution, null for generate one- Returns:
- the task data of the new task
-
registerTask
Registers a new task for the giventhread, turning a still running one intoTaskRegistry.TaskStatus.SUPPRESSED.- Parameters:
thread- the thread to register the task for- Returns:
- the task data of the new task
-
registerTask
Registers a new task for the giventhread, turning a still running one intoTaskRegistry.TaskStatus.SUPPRESSED.- Parameters:
thread- the thread to register the task fortaskId- a given task id, e.g., when passed in through distributed execution, null for generate one- Returns:
- the task data of the new task
-
associateTask
Associates existing taskdatawiththread. In contrast, registring creates a new task data object, here an existing (keeping the thread id indata) with its status is used further on.- Parameters:
thread- the thread, may be null then the current thread is assumeddata- the task data, may be null orNO_TASKthen nothing is happening
-
unassociateTask
Unassociates a thread.- Parameters:
thread- the thread, may be null then the current thread is assumed- See Also:
-
getTaskData
Returns the task data assigned to the current thread.- Returns:
- the task data, may be
NO_TASKfor none
-
getTaskData
Returns the task data assigned to the given thread.- Parameters:
thread- the thread denoting the task- Returns:
- the task data, may be
NO_TASKfor none
-
getTaskData
Returns the task data assigned to the given task id.- Parameters:
id- the task id denoting the task- Returns:
- the task data, may be
NO_TASKfor none
-
stopTask
public static void stopTask()Stops the actual task of the current thread. -
stopTask
Stops the given task.- Parameters:
thread- the thread denoting the task
-
stopTask
Stops the given task.- Parameters:
id- the task id denoting the task
-
cleanup
public static void cleanup()Cleans up outdated task data after no change withingetTimeout(). -
cleanup
Checks the task data initerfor cleanup.- Parameters:
now- the timestamp for calculating the timeout vs. the last change in aTaskRegistry.TaskDatainstanceiter- the iterator for traversing/removing instances
-