Class InMemoryTaskStore

java.lang.Object
io.a2a.server.tasks.InMemoryTaskStore
All Implemented Interfaces:
TaskStateProvider, TaskStore

@ApplicationScoped public class InMemoryTaskStore extends Object implements TaskStore, TaskStateProvider
In-memory implementation of TaskStore and TaskStateProvider.

This implementation uses a ConcurrentHashMap to store tasks in memory. Tasks are lost on application restart. For persistent storage, use a database-backed implementation such as the JPA TaskStore in the extras module.

This is the default TaskStore used when no other implementation is provided.

  • Constructor Details

    • InMemoryTaskStore

      public InMemoryTaskStore()
  • Method Details

    • save

      public void save(Task task, boolean isReplicated)
      Description copied from interface: TaskStore
      Saves or updates a task.
      Specified by:
      save in interface TaskStore
      Parameters:
      task - the task to save
      isReplicated - true if this task update came from a replicated event, false if it originated locally. Used to prevent feedback loops in replicated scenarios (e.g., don't fire TaskFinalizedEvent for replicated updates)
    • get

      public @Nullable Task get(String taskId)
      Description copied from interface: TaskStore
      Retrieves a task by its ID.
      Specified by:
      get in interface TaskStore
      Parameters:
      taskId - the task identifier
      Returns:
      the task if found, null otherwise
    • delete

      public void delete(String taskId)
      Description copied from interface: TaskStore
      Deletes a task by its ID.
      Specified by:
      delete in interface TaskStore
      Parameters:
      taskId - the task identifier
    • list

      public ListTasksResult list(ListTasksParams params)
      Description copied from interface: TaskStore
      List tasks with optional filtering and pagination.
      Specified by:
      list in interface TaskStore
      Parameters:
      params - the filtering and pagination parameters
      Returns:
      the list of tasks matching the criteria with pagination info
    • isTaskActive

      public boolean isTaskActive(String taskId)
      Description copied from interface: TaskStateProvider
      Determines whether a task is considered active for queue management purposes.

      This method includes the grace period in its check. A task is considered active if:

      • Its state is not final, OR
      • Its state is final but finalized within the grace period (now < finalizedAt + gracePeriod)

      This method is used to decide whether to process late-arriving events.

      Specified by:
      isTaskActive in interface TaskStateProvider
      Parameters:
      taskId - the ID of the task to check
      Returns:
      true if the task is active (or recently finalized within grace period), false otherwise
    • isTaskFinalized

      public boolean isTaskFinalized(String taskId)
      Description copied from interface: TaskStateProvider
      Determines whether a task is in a final state, ignoring the grace period.

      This method performs an immediate check: returns true only if the task is in a final state (COMPLETED, CANCELED, FAILED, etc.), regardless of when it was finalized.

      This method is used by cleanup callbacks and MainQueue closing logic to decide whether a queue can be closed and removed. By ignoring the grace period, it ensures responsive cleanup while late in-flight events are still handled by the grace period mechanism for isTaskActive.

      Specified by:
      isTaskFinalized in interface TaskStateProvider
      Parameters:
      taskId - the ID of the task to check
      Returns:
      true if the task is in a final state (ignoring grace period), false otherwise