Class FirestoreSessionService

java.lang.Object
com.google.adk.sessions.FirestoreSessionService
All Implemented Interfaces:
BaseSessionService

public class FirestoreSessionService extends Object implements BaseSessionService
FirestoreSessionService implements session management using Google Firestore as the backend storage.
  • Constructor Details

    • FirestoreSessionService

      public FirestoreSessionService(com.google.cloud.firestore.Firestore firestore)
      Constructor for FirestoreSessionService.
  • Method Details

    • createSession

      public io.reactivex.rxjava3.core.Single<Session> createSession(String appName, String userId, @Nullable ConcurrentMap<String,Object> state, @Nullable String sessionId)
      Creates a new session in Firestore.
      Specified by:
      createSession in interface BaseSessionService
      Parameters:
      appName - The name of the application associated with the session.
      userId - The identifier for the user associated with the session.
      state - An optional map representing the initial state of the session. Can be null or empty.
      sessionId - An optional client-provided identifier for the session. If empty or null, the service should generate a unique ID.
      Returns:
      The newly created Session instance.
    • createSession

      public io.reactivex.rxjava3.core.Single<Session> createSession(String appName, String userId, @Nullable Map<String,Object> state, @Nullable String sessionId)
      Creates a new session in Firestore.
      Specified by:
      createSession in interface BaseSessionService
      Parameters:
      appName - The name of the application associated with the session.
      userId - The identifier for the user associated with the session.
      state - An optional map representing the initial state of the session. Can be null or empty.
      sessionId - An optional client-provided identifier for the session. If empty or null, the service should generate a unique ID.
      Returns:
      The newly created Session instance.
    • getSession

      public io.reactivex.rxjava3.core.Maybe<Session> getSession(String appName, String userId, String sessionId, Optional<GetSessionConfig> configOpt)
      Retrieves a session by appName, userId, and sessionId from Firestore.
      Specified by:
      getSession in interface BaseSessionService
      Parameters:
      appName - The name of the application.
      userId - The identifier of the user.
      sessionId - The unique identifier of the session to retrieve.
      configOpt - Optional configuration to filter the events returned within the session (e.g., limit number of recent events, filter by timestamp). If empty, default retrieval behavior is used (potentially all events or a service-defined limit).
      Returns:
      An Optional containing the Session if found, otherwise Optional.empty().
    • listSessions

      public io.reactivex.rxjava3.core.Single<ListSessionsResponse> listSessions(String appName, String userId)
      Lists all sessions for a given appName and userId.
      Specified by:
      listSessions in interface BaseSessionService
      Parameters:
      appName - The name of the application.
      userId - The identifier of the user whose sessions are to be listed.
      Returns:
      A ListSessionsResponse containing a list of matching sessions.
    • deleteSession

      public io.reactivex.rxjava3.core.Completable deleteSession(String appName, String userId, String sessionId)
      Deletes a session and all its associated events from Firestore.
      Specified by:
      deleteSession in interface BaseSessionService
      Parameters:
      appName - The name of the application.
      userId - The identifier of the user.
      sessionId - The unique identifier of the session to delete.
    • listEvents

      public io.reactivex.rxjava3.core.Single<ListEventsResponse> listEvents(String appName, String userId, String sessionId)
      Lists all events for a given appName, userId, and sessionId.
      Specified by:
      listEvents in interface BaseSessionService
      Parameters:
      appName - The name of the application.
      userId - The identifier of the user.
      sessionId - The unique identifier of the session whose events are to be listed.
      Returns:
      A ListEventsResponse containing a list of events and an optional token for retrieving the next page.
    • appendEvent

      @CanIgnoreReturnValue public io.reactivex.rxjava3.core.Single<Event> appendEvent(Session session, Event event)
      Appends an event to a session, updating the session state and persisting to Firestore.
      Specified by:
      appendEvent in interface BaseSessionService
      Parameters:
      session - The Session object to which the event should be appended (will be mutated).
      event - The Event to append.
      Returns:
      The appended Event instance (or the original event if it was partial).