Class JpaDatabaseTaskStore

java.lang.Object
org.a2aproject.sdk.extras.taskstore.database.jpa.JpaDatabaseTaskStore
All Implemented Interfaces:
org.a2aproject.sdk.server.tasks.TaskStateProvider, org.a2aproject.sdk.server.tasks.TaskStore

@ApplicationScoped @Alternative @Priority(50) public class JpaDatabaseTaskStore extends Object implements org.a2aproject.sdk.server.tasks.TaskStore, org.a2aproject.sdk.server.tasks.TaskStateProvider
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    JpaDatabaseTaskStore(jakarta.enterprise.inject.Instance<org.a2aproject.sdk.server.auth.TaskAuthorizationProvider> authorizationProviderInstance)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    delete(String taskId)
     
    org.a2aproject.sdk.spec.Task
    get(String taskId)
     
    boolean
    Determines if a task is considered active for queue management purposes.
    boolean
    Determines if a task is in a final state, ignoring the grace period.
    org.a2aproject.sdk.jsonrpc.common.wrappers.ListTasksResult
    list(org.a2aproject.sdk.spec.ListTasksParams params, @Nullable org.a2aproject.sdk.server.ServerCallContext context)
     
    void
    save(org.a2aproject.sdk.spec.Task task, boolean isReplicated)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.a2aproject.sdk.server.tasks.TaskStore

    isReadAuthorized
  • Constructor Details

    • JpaDatabaseTaskStore

      public JpaDatabaseTaskStore()
    • JpaDatabaseTaskStore

      @Inject public JpaDatabaseTaskStore(@Any jakarta.enterprise.inject.Instance<org.a2aproject.sdk.server.auth.TaskAuthorizationProvider> authorizationProviderInstance)
  • Method Details

    • save

      public void save(org.a2aproject.sdk.spec.Task task, boolean isReplicated)
      Specified by:
      save in interface org.a2aproject.sdk.server.tasks.TaskStore
    • get

      public org.a2aproject.sdk.spec.Task get(String taskId)
      Specified by:
      get in interface org.a2aproject.sdk.server.tasks.TaskStore
    • delete

      public void delete(String taskId)
      Specified by:
      delete in interface org.a2aproject.sdk.server.tasks.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 org.a2aproject.sdk.server.tasks.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 org.a2aproject.sdk.server.tasks.TaskStateProvider
      Parameters:
      taskId - the task ID to check
      Returns:
      true if the task is in a final state (ignoring grace period), false otherwise
    • list

      public org.a2aproject.sdk.jsonrpc.common.wrappers.ListTasksResult list(org.a2aproject.sdk.spec.ListTasksParams params, @Nullable org.a2aproject.sdk.server.ServerCallContext context)
      Specified by:
      list in interface org.a2aproject.sdk.server.tasks.TaskStore