Class JpaDatabaseTaskStore

java.lang.Object
io.a2a.extras.taskstore.database.jpa.JpaDatabaseTaskStore
All Implemented Interfaces:
TaskStateProvider, TaskStore

@ApplicationScoped @Alternative @Priority(50) public class JpaDatabaseTaskStore extends Object implements TaskStore, TaskStateProvider
  • Constructor Details

    • JpaDatabaseTaskStore

      public JpaDatabaseTaskStore()
  • Method Details

    • save

      public void save(io.a2a.spec.Task task)
      Specified by:
      save in interface TaskStore
    • get

      public io.a2a.spec.Task get(String taskId)
      Specified by:
      get in interface TaskStore
    • delete

      public void delete(String taskId)
      Specified by:
      delete in interface TaskStore
    • isTaskActive

      public boolean isTaskActive(String taskId)
      Determines if a task is considered active for queue management purposes.

      A task is active if:

      • Its state is not final, OR
      • Its state is final but it was finalized within the grace period

      The grace period handles the race condition where events are published to Kafka while a task is active, but consumed on a replica node after the task is finalized.

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

      public boolean isTaskFinalized(String taskId)
      Determines if 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 the MainQueue.onClose callback to decide whether to publish the QueueClosedEvent "poison pill". By ignoring the grace period, it ensures that subscribers are terminated immediately when the task is done, providing responsive UX.

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