Class TaskRegistry

java.lang.Object
de.iip_ecosphere.platform.support.TaskRegistry

public class TaskRegistry extends Object
Thread-based mechanism to track tasks (AAS, through UI). Call cleanup() regularly depending on getTimeout().
Author:
Holger Eichelberger, SSE
  • Field Details

  • Constructor Details

    • TaskRegistry

      public TaskRegistry()
  • Method Details

    • getThreadId

      private static long getThreadId(Thread thread)
      Returns the thread id of thread.
      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 a TaskRegistry.TaskData instance to be cleaned up.
      Returns:
      the timeout in ms
    • setTimeout

      public static long setTimeout(long to)
      Changes the timeout indicating a TaskRegistry.TaskData instance to be cleaned up.
      Parameters:
      to - the new timeout in ms
      Returns:
      the old timeout in ms
    • registerTask

      public static TaskRegistry.TaskData registerTask()
      Registers a new task on the current task.
      Returns:
      the task data of the new task
    • registerTask

      public static TaskRegistry.TaskData registerTask(String taskId)
      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

      public static TaskRegistry.TaskData registerTask(Thread thread)
      Registers a new task for the given thread, turning a still running one into TaskRegistry.TaskStatus.SUPPRESSED.
      Parameters:
      thread - the thread to register the task for
      Returns:
      the task data of the new task
    • registerTask

      public static TaskRegistry.TaskData registerTask(Thread thread, String taskId)
      Registers a new task for the given thread, turning a still running one into TaskRegistry.TaskStatus.SUPPRESSED.
      Parameters:
      thread - the thread to register the task for
      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
    • associateTask

      public static void associateTask(Thread thread, TaskRegistry.TaskData data)
      Associates existing task data with thread. In contrast, registring creates a new task data object, here an existing (keeping the thread id in data) with its status is used further on.
      Parameters:
      thread - the thread, may be null then the current thread is assumed
      data - the task data, may be null or NO_TASK then nothing is happening
    • unassociateTask

      public static void unassociateTask(Thread thread)
      Unassociates a thread.
      Parameters:
      thread - the thread, may be null then the current thread is assumed
      See Also:
    • getTaskData

      public static TaskRegistry.TaskData getTaskData()
      Returns the task data assigned to the current thread.
      Returns:
      the task data, may be NO_TASK for none
    • getTaskData

      public static TaskRegistry.TaskData getTaskData(Thread thread)
      Returns the task data assigned to the given thread.
      Parameters:
      thread - the thread denoting the task
      Returns:
      the task data, may be NO_TASK for none
    • getTaskData

      public static TaskRegistry.TaskData getTaskData(String id)
      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_TASK for none
    • stopTask

      public static void stopTask()
      Stops the actual task of the current thread.
    • stopTask

      public static void stopTask(Thread thread)
      Stops the given task.
      Parameters:
      thread - the thread denoting the task
    • stopTask

      public static void stopTask(String id)
      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 within getTimeout().
    • cleanup

      private static void cleanup(long now, Iterator<TaskRegistry.TaskData> iter)
      Checks the task data in iter for cleanup.
      Parameters:
      now - the timestamp for calculating the timeout vs. the last change in a TaskRegistry.TaskData instance
      iter - the iterator for traversing/removing instances