`Class FirestoreSessionService`
java.lang.Object
com.google.adk.sessions.FirestoreSessionService
- All Implemented Interfaces:
BaseSessionService
`FirestoreSessionService` 使用 Google Firestore 作为后端来实现会话管理功能。
-
构造函数概述
ConstructorsConstructorDescriptionFirestoreSessionService(com.google.cloud.firestore.Firestore firestore) FirestoreSessionService 的构造函数。FirestoreSessionService(com.google.cloud.firestore.Firestore firestore, InstantSource instantSource, UuidProvider uuidProvider) 创建一个会话服务(session service),该服务能够生成会话 ID(session IDs)。lastUpdateTime这些值是从指定的提供者那里获取的,而不是……UUID.randomUUID()还有墙上的时钟。 -
方法概述
Modifier and TypeMethodDescriptionio.reactivex.rxjava3.core.Single<Event> appendEvent(Session session, Event event) 将一个事件添加到会话中,同时更新会话状态并将其数据持久化到 Firestore 中。io.reactivex.rxjava3.core.Single<Session> createSession(String appName, String userId, @Nullable Map<String, Object> state, @Nullable String sessionId) 在 Firestore 中创建一个新的会话。io.reactivex.rxjava3.core.Single<Session> createSession(String appName, String userId, @Nullable ConcurrentMap<String, Object> state, @Nullable String sessionId) 在 Firestore 中创建一个新的会话。io.reactivex.rxjava3.core.CompletabledeleteSession(String appName, String userId, String sessionId) 从 Firestore 中删除一个会话及其所有相关事件。io.reactivex.rxjava3.core.Maybe<Session> getSession(String appName, String userId, String sessionId, Optional<GetSessionConfig> configOpt) 从 Firestore 中根据appName、userId 和 sessionId 获取相应的会话信息。io.reactivex.rxjava3.core.Single<ListEventsResponse> listEvents(String appName, String userId, String sessionId) 列出给定应用程序名称(appName)、用户ID(userId)和会话ID(sessionId)的所有事件。io.reactivex.rxjava3.core.Single<ListSessionsResponse> listSessions(String appName, String userId) 列出给定应用程序名称(appName)和用户ID(userId)的所有会话记录。Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface BaseSessionService
closeSession, createSession, createSession, createSession, deleteSession, getSession, listEvents, listSessionsModifier and TypeMethodDescriptiondefault io.reactivex.rxjava3.core.CompletablecloseSession(Session session) 关闭会话。default io.reactivex.rxjava3.core.Single<Session> createSession(SessionKey sessionKey) 使用指定的应用程序名称和用户 ID 创建一个新的会话,会话初始状态为默认值(null),并允许服务自动生成一个唯一的会话 ID。default io.reactivex.rxjava3.core.Single<Session> createSession(SessionKey sessionKey, @Nullable Map<String, Object> state) 使用指定的参数创建一个新的会话。default io.reactivex.rxjava3.core.Single<Session> createSession(String appName, String userId) 使用指定的应用程序名称和用户 ID 创建一个新的会话,会话初始状态为默认值(null),并允许服务自动生成一个唯一的会话 ID。default io.reactivex.rxjava3.core.CompletabledeleteSession(SessionKey sessionKey) 删除特定的会话。default io.reactivex.rxjava3.core.Maybe<Session> getSession(SessionKey sessionKey, @Nullable GetSessionConfig config) 检索特定的会话(session),并可选择性地过滤其中包含的事件(events)。default io.reactivex.rxjava3.core.Single<ListEventsResponse> listEvents(SessionKey sessionKey) 列出特定会话中的所有事件。default io.reactivex.rxjava3.core.Single<ListSessionsResponse> listSessions(SessionKey sessionKey) 列出与特定应用程序和用户关联的会话(session)。
-
构造函数详细信息
-
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 thelastUpdateTimeof a newly created session.uuidProvider- Supplies the session ID whencreateSessionis 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:
createSessionin interfaceBaseSessionService- 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
Sessioninstance.
-
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:
createSessionin interfaceBaseSessionService- 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
Sessioninstance.
-
getSession
public io.reactivex.rxjava3.core.Maybe<Session> getSession(String appName, String userId, String sessionId, Optional<GetSessionConfig> configOpt) 从 Firestore 中根据appName、userId 和 sessionId 获取相应的会话信息。- Specified by:
getSessionin interfaceBaseSessionService- 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
Optionalcontaining theSessionif found, otherwiseOptional.empty().
-
listSessions
public io.reactivex.rxjava3.core.Single<ListSessionsResponse> listSessions(String appName, String userId) 列出给定应用程序名称(appName)和用户ID(userId)的所有会话记录。- Specified by:
listSessionsin interfaceBaseSessionService- Parameters:
appName- The name of the application.userId- The identifier of the user whose sessions are to be listed.- Returns:
- A
ListSessionsResponsecontaining a list of matching sessions.
-
deleteSession
public io.reactivex.rxjava3.core.Completable deleteSession(String appName, String userId, String sessionId) 从 Firestore 中删除一个会话及其所有相关事件。- Specified by:
deleteSessionin interfaceBaseSessionService- 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:
listEventsin interfaceBaseSessionService- 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
ListEventsResponsecontaining 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:
appendEventin interfaceBaseSessionService- Parameters:
session- TheSessionobject to which the event should be appended (will be mutated).event- TheEventto append.- Returns:
- The appended
Eventinstance (or the original event if it was partial).
-