`Class FirestoreSessionService`

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

public class FirestoreSessionService extends Object implements BaseSessionService
`FirestoreSessionService` 使用 Google Firestore 作为后端来实现会话管理功能。
  • 构造函数详细信息

    • FirestoreSessionService

      public FirestoreSessionService(com.google.cloud.firestore.Firestore firestore)
      FirestoreSessionService 的构造函数。
    • FirestoreSessionService

      public FirestoreSessionService(com.google.cloud.firestore.Firestore firestore, InstantSource instantSource, UuidProvider uuidProvider)
      创建一个会话服务(session service),该服务能够生成会话 ID(session IDs)。 lastUpdateTime 这些值是从指定的提供者那里获取的,而不是…… UUID.randomUUID() 还有墙上的时钟。
      Parameters:
      firestore - The Firestore client.
      instantSource - Supplies the lastUpdateTime of a newly created session.
      uuidProvider - Supplies the session ID when createSession is not given one.
  • 方法详细信息(Method Details)

    • createSession

      public io.reactivex.rxjava3.core.Single<Session> createSession(String appName, String userId, @Nullable ConcurrentMap<String,Object> state, @Nullable String sessionId)
      在 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)
      在 Firestore 中创建一个新的会话。会话 ID 对每个用户来说都是唯一的(跨所有应用程序都相同),因此如果用户已经在某个应用程序中拥有一个会话 ID,那么尝试再次创建新的会话将会失败。 SessionException.
      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)
      从 Firestore 中根据appName、userId 和 sessionId 获取相应的会话信息。
      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)
      列出给定应用程序名称(appName)和用户ID(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)
      从 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)
      列出给定应用程序名称(appName)、用户ID(userId)和会话ID(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)
      将一个事件添加到会话中,同时更新会话状态并将其数据持久化到 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).