# 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 Summary

  Constructors
  Constructor
  Description
  `FirestoreSessionService(com.google.cloud.firestore.Firestore firestore)`
  Constructor for FirestoreSessionService.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `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.
  `io.reactivex.rxjava3.core.Single<Session>`
  `createSession(String appName, String userId, ConcurrentMap<String,Object> state, String sessionId)`
  Creates a new session in Firestore.
  `io.reactivex.rxjava3.core.Single<Session>`
  `createSession(String appName, String userId, Map<String,Object> state, String sessionId)`
  Creates a new session in Firestore.
  `io.reactivex.rxjava3.core.Completable`
  `deleteSession(String appName, String userId, String sessionId)`
  Deletes a session and all its associated events from Firestore.
  `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.
  `io.reactivex.rxjava3.core.Single<ListEventsResponse>`
  `listEvents(String appName, String userId, String sessionId)`
  Lists all events for a given appName, userId, and sessionId.
  `io.reactivex.rxjava3.core.Single<ListSessionsResponse>`
  `listSessions(String appName, String userId)`
  Lists all sessions for a given appName and userId.

  ### Methods inherited from class Object

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

  ### Methods inherited from interface BaseSessionService

  `closeSession, createSession, createSession, createSession, deleteSession, getSession, listEvents, listSessions`
  Modifier and Type
  Method
  Description
  `default io.reactivex.rxjava3.core.Completable`
  `closeSession(Session session)`
  Closes a session.
  `default io.reactivex.rxjava3.core.Single<Session>`
  `createSession(SessionKey sessionKey)`
  Creates a new session with the specified application name and user ID, using a default state (null) and allowing the service to generate a unique session ID.
  `default io.reactivex.rxjava3.core.Single<Session>`
  `createSession(SessionKey sessionKey, @Nullable Map<String,Object> state)`
  Creates a new session with the specified parameters.
  `default io.reactivex.rxjava3.core.Single<Session>`
  `createSession(String appName, String userId)`
  Creates a new session with the specified application name and user ID, using a default state (null) and allowing the service to generate a unique session ID.
  `default io.reactivex.rxjava3.core.Completable`
  `deleteSession(SessionKey sessionKey)`
  Deletes a specific session.
  `default io.reactivex.rxjava3.core.Maybe<Session>`
  `getSession(SessionKey sessionKey, @Nullable GetSessionConfig config)`
  Retrieves a specific session, optionally filtering the events included.
  `default io.reactivex.rxjava3.core.Single<ListEventsResponse>`
  `listEvents(SessionKey sessionKey)`
  Lists the events within a specific session.
  `default io.reactivex.rxjava3.core.Single<ListSessionsResponse>`
  `listSessions(SessionKey sessionKey)`
  Lists sessions associated with a specific application and user.

- ## 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).