Class SessionManager

java.lang.Object
ai.pipeline.connector.intake.service.SessionManager

@ApplicationScoped public class SessionManager extends Object
Service for managing crawl session lifecycle.

Handles session creation, state transitions, and statistics tracking.

  • Constructor Details

    • SessionManager

      public SessionManager()
      Default constructor for CDI.
  • Method Details

    • createSession

      public io.smallrye.mutiny.Uni<String> createSession(String datasourceId, String crawlId, String accountId, String connectorType, String sourceSystem, String metadata, boolean trackDocuments, boolean deleteOrphans)
      Create a new crawl session.

      If a session already exists for the same datasourceId and crawlId, the existing session ID is returned. Otherwise, a new session is persisted in the database and its ID is returned. Reactive semantics: executes on the default worker pool due to blocking persistence. Side effects: inserts a row into the crawl_session table.

      Parameters:
      datasourceId - DataSource ID
      crawlId - Client-provided crawl ID
      accountId - Account ID
      connectorType - Connector type
      sourceSystem - Source system identifier
      metadata - Crawl metadata as JSON
      trackDocuments - Whether to track documents for orphan detection
      deleteOrphans - Whether to delete orphans at end
      Returns:
      a Uni emitting the session ID (existing or newly created)
    • getSession

      public io.smallrye.mutiny.Uni<CrawlSession> getSession(String sessionId)
      Retrieve a crawl session by its identifier.

      Reactive semantics: executes on the default worker pool due to database access. Side effects: none (read-only).

      Parameters:
      sessionId - unique session identifier
      Returns:
      a Uni that emits the CrawlSession if found; fails if not found
    • updateHeartbeat

      public io.smallrye.mutiny.Uni<Void> updateHeartbeat(String sessionId)
      Update a session's heartbeat timestamp to the current time.

      Reactive semantics: executes on the default worker pool due to database access. Side effects: updates the lastHeartbeat column for the given session.

      Parameters:
      sessionId - unique session identifier
      Returns:
      a Uni that completes when the heartbeat has been updated
    • completeSession

      public io.smallrye.mutiny.Uni<Void> completeSession(String sessionId, String state)
      Mark a session as completed and persist its final state.

      Sets the session's state and completedAt timestamp. No-op if the session does not exist will result in a failure from the repository layer. Reactive semantics: executes on the default worker pool due to database access. Side effects: updates the crawl_session row for the given session.

      Parameters:
      sessionId - unique session identifier
      state - terminal state to set (e.g., COMPLETED, FAILED, ABORTED)
      Returns:
      a Uni that completes when the session is marked complete
    • incrementDocumentsFound

      public io.smallrye.mutiny.Uni<Void> incrementDocumentsFound(String sessionId)
      Increment the count of documents discovered for a session.

      Reactive semantics: executes on the default worker pool due to database access. Side effects: increments the documentsFound counter in the session row.

      Parameters:
      sessionId - unique session identifier
      Returns:
      a Uni that completes after the counter has been incremented
    • incrementDocumentsProcessed

      public io.smallrye.mutiny.Uni<Void> incrementDocumentsProcessed(String sessionId)
      Increment the count of documents successfully processed for a session.

      Reactive semantics: executes on the default worker pool due to database access. Side effects: increments the documentsProcessed counter in the session row.

      Parameters:
      sessionId - unique session identifier
      Returns:
      a Uni that completes after the counter has been incremented
    • incrementDocumentsFailed

      public io.smallrye.mutiny.Uni<Void> incrementDocumentsFailed(String sessionId)
      Increment the count of documents that failed processing for a session.

      Reactive semantics: executes on the default worker pool due to database access. Side effects: increments the documentsFailed counter in the session row.

      Parameters:
      sessionId - unique session identifier
      Returns:
      a Uni that completes after the counter has been incremented
    • incrementDocumentsSkipped

      public io.smallrye.mutiny.Uni<Void> incrementDocumentsSkipped(String sessionId)
      Increment the count of documents skipped (not processed) for a session.

      Reactive semantics: executes on the default worker pool due to database access. Side effects: increments the documentsSkipped counter in the session row.

      Parameters:
      sessionId - unique session identifier
      Returns:
      a Uni that completes after the counter has been incremented
    • addBytesProcessed

      public io.smallrye.mutiny.Uni<Void> addBytesProcessed(String sessionId, long bytes)
      Add the number of processed bytes to the session total.

      Reactive semantics: executes on the default worker pool due to database access. Side effects: increments the bytesProcessed counter in the session row.

      Parameters:
      sessionId - unique session identifier
      bytes - number of bytes to add (must be non-negative)
      Returns:
      a Uni that completes after the counter has been updated