Class DefaultTaskRepository

java.lang.Object
com.alibaba.cloud.ai.graph.agent.tools.task.DefaultTaskRepository
All Implemented Interfaces:
TaskRepository

public class DefaultTaskRepository extends Object implements TaskRepository
Default implementation of TaskRepository using a thread pool for background execution.
Author:
Spring AI Alibaba
  • Constructor Details

    • DefaultTaskRepository

      public DefaultTaskRepository()
      Create a repository with a default cached thread pool executor.
    • DefaultTaskRepository

      public DefaultTaskRepository(ExecutorService executor)
      Create a repository with a custom executor service.
    • DefaultTaskRepository

      public DefaultTaskRepository(ExecutorService executor, boolean ownsExecutor)
      Internal constructor for specifying executor ownership.
  • Method Details

    • getTask

      public BackgroundTask getTask(String taskId)
      Description copied from interface: TaskRepository
      Get a background task by its ID.
      Specified by:
      getTask in interface TaskRepository
      Parameters:
      taskId - the task identifier
      Returns:
      the background task, or null if not found
    • putTask

      public BackgroundTask putTask(String taskId, Supplier<String> taskExecution)
      Description copied from interface: TaskRepository
      Add a new background task to the repository.
      Specified by:
      putTask in interface TaskRepository
      Parameters:
      taskId - the task identifier
      taskExecution - the supplier that executes the task and returns its output
      Returns:
      the created background task
    • removeTask

      public void removeTask(String taskId)
      Description copied from interface: TaskRepository
      Remove a background task from the repository.
      Specified by:
      removeTask in interface TaskRepository
      Parameters:
      taskId - the task identifier
    • clear

      public void clear()
      Description copied from interface: TaskRepository
      Clear all tasks from the repository.
      Specified by:
      clear in interface TaskRepository
    • clearCompletedTasks

      public void clearCompletedTasks()
      Remove completed tasks from the repository.
    • shutdown

      public void shutdown()
      Shutdown the executor service if this repository owns it.