Interface BaseSessionService
- All Known Implementing Classes:
FirestoreSessionService, InMemorySessionService, VertexAiSessionService
public interface BaseSessionService
定义了用于管理的合同(或协议)。
Session“s”及其相关内容 Event该接口提供了用于创建、检索、列出和删除会话(session)的方法,以及用于向会话中添加事件(event)的方法。该接口的实现负责处理底层的存储和数据检索逻辑。
不同的实现方式在处理重复的会话 ID 时有所不同:有些实现会通过特定的信号来表明存在重复的会话 ID。 SessionException “whose message is” 的意思是“谁的信息是……”。 SessionException.SESSION_ALREADY_EXISTS这适用于所有情况。 createSession 创建一个可以接受会话 ID 的重载方法(overload method)。
-
方法概述
Modifier and TypeMethodDescriptiondefault io.reactivex.rxjava3.core.Single<Event> appendEvent(Session session, Event event) 将一个事件添加到内存中的会话对象中,并根据该事件的状态变化(如果适用的话)更新会话的状态。default 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.Single<Session> createSession(String appName, String userId, @Nullable Map<String, Object> state, @Nullable String sessionId) 使用指定的参数创建一个新的会话。io.reactivex.rxjava3.core.Single<Session> createSession(String appName, String userId, @Nullable ConcurrentMap<String, Object> state, @Nullable String sessionId) 已弃用(Deprecated)。default io.reactivex.rxjava3.core.CompletabledeleteSession(SessionKey sessionKey) 删除特定的会话。io.reactivex.rxjava3.core.CompletabledeleteSession(String appName, String userId, String sessionId) 删除特定的会话。default io.reactivex.rxjava3.core.Maybe<Session> getSession(SessionKey sessionKey, @Nullable GetSessionConfig config) 检索特定的会话(session),并可选择性地过滤其中包含的事件(events)。io.reactivex.rxjava3.core.Maybe<Session> getSession(String appName, String userId, String sessionId, Optional<GetSessionConfig> config) 检索特定的会话(session),并可选择性地过滤其中包含的事件(events)。default io.reactivex.rxjava3.core.Single<ListEventsResponse> listEvents(SessionKey sessionKey) 列出特定会话中的所有事件。io.reactivex.rxjava3.core.Single<ListEventsResponse> listEvents(String appName, String userId, String sessionId) 列出特定会话中的所有事件。default io.reactivex.rxjava3.core.Single<ListSessionsResponse> listSessions(SessionKey sessionKey) 列出与特定应用程序和用户关联的会话(session)。io.reactivex.rxjava3.core.Single<ListSessionsResponse> listSessions(String appName, String userId) 列出与特定应用程序和用户关联的会话(session)。
-
方法详细信息(Method Details)
-
createSession
@Deprecated io.reactivex.rxjava3.core.Single<Session> createSession(String appName, String userId, @Nullable ConcurrentMap<String, Object> state, @Nullable String sessionId) Deprecated.UsecreateSession(String, String, Map, String)instead.使用指定的参数创建一个新的会话。- 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. - Throws:
SessionException- if creation fails.
-
createSession
default io.reactivex.rxjava3.core.Single<Session> createSession(String appName, String userId, @Nullable Map<String, Object> state, @Nullable String sessionId) 使用指定的参数创建一个新的会话。- 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. - Throws:
SessionException- withSessionException.SESSION_ALREADY_EXISTSifsessionIdis already in use for this app and user; only implementations that reject duplicates throw it.SessionException- if creation fails.
-
createSession
default io.reactivex.rxjava3.core.Single<Session> createSession(SessionKey sessionKey, @Nullable Map<String, Object> state) 使用指定的参数创建一个新的会话。- Parameters:
sessionKey- The session key containing appName, userId and sessionId.state- An optional map representing the initial state of the session. Can be null or empty.
-
createSession
使用指定的应用程序名称和用户 ID 创建一个新的会话,会话初始状态为默认值(null),并允许服务自动生成一个唯一的会话 ID。这是一个快捷方式(用于访问或执行某个功能)。
createSession(String, String, Map, String)状态为“null”,会话 ID 也为“null”。- Parameters:
appName- The name of the application associated with the session.userId- The identifier for the user associated with the session.- Returns:
- The newly created
Sessioninstance. - Throws:
SessionException- if creation fails.
-
createSession
使用指定的应用程序名称和用户 ID 创建一个新的会话,会话初始状态为默认值(null),并允许服务自动生成一个唯一的会话 ID。 -
getSession
io.reactivex.rxjava3.core.Maybe<Session> getSession(String appName, String userId, String sessionId, Optional<GetSessionConfig> config) 检索特定的会话(session),并可选择性地过滤其中包含的事件(events)。- Parameters:
appName- The name of the application.userId- The identifier of the user.sessionId- The unique identifier of the session to retrieve.config- 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(). - Throws:
SessionException- for retrieval errors other than not found.
-
getSession
default io.reactivex.rxjava3.core.Maybe<Session> getSession(SessionKey sessionKey, @Nullable GetSessionConfig config) 检索特定的会话(session),并可选择性地过滤其中包含的事件(events)。 -
listSessions
列出与特定应用程序和用户关联的会话(session)。The
Session响应中的对象通常只包含元数据(如 ID、创建时间等),而不包含完整的事件列表或系统状态,这样有助于优化性能。- 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. - Throws:
SessionException- if listing fails.
-
listSessions
列出与特定应用程序和用户关联的会话(session)。 -
deleteSession
io.reactivex.rxjava3.core.Completable deleteSession(String appName, String userId, String sessionId) 删除特定的会话。- Parameters:
appName- The name of the application.userId- The identifier of the user.sessionId- The unique identifier of the session to delete.- Throws:
SessionNotFoundException- if the session doesn't exist.SessionException- for other deletion errors.
-
deleteSession
删除特定的会话。 -
listEvents
io.reactivex.rxjava3.core.Single<ListEventsResponse> listEvents(String appName, String userId, String sessionId) 列出特定会话中的所有事件。支持通过响应对象实现分页功能。- 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. - Throws:
SessionNotFoundException- if the session doesn't exist.SessionException- for other listing errors.
-
listEvents
列出特定会话中的所有事件。 -
closeSession
关闭会话。目前这只是一个占位符(即尚未实现的具体功能);在未来的实现中,该操作可能包括完成会话状态的清理工作或执行其他必要的清理操作。默认实现中,此功能没有任何具体效果(即什么都不做)。- Parameters:
session- The session object to close.
-
appendEvent
@CanIgnoreReturnValue default io.reactivex.rxjava3.core.Single<Event> appendEvent(Session session, Event event) 将一个事件添加到内存中的会话对象中,并根据该事件的状态变化(如果适用的话)更新会话的状态。此方法主要修改传入的参数(即 `passed` 参数)。
session这些数据存储在内存中。要使这些更改持久化(即让它们在系统重启后仍然存在),通常需要调用特定服务提供的 `update` 或 `save` 方法;不过,根据该服务的实现方式,这一过程也可能被隐式地完成(即无需用户进行任何操作)。如果该事件被标记为“部分完成”(例如:……),
event.isPartial() == true当数据被返回时,它会直接被发送出去,而不会修改会话状态或事件列表。以 “State delta keys starting with” 开头的键用于表示状态变化的相关信息。State.TEMP_PREFIX在状态更新过程中,这些内容会被忽略。- 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). - Throws:
NullPointerException- if session or event is null.
-
createSession(String, String, Map, String)相反。