`Class InMemorySessionService`
java.lang.Object
com.google.adk.sessions.InMemorySessionService
- All Implemented Interfaces:
BaseSessionService
一种基于内存的实现方式(in-memory implementation)
BaseSessionService 假设…… Session 这些对象的状态映射(state map)、事件列表(events list)以及最后更新时间(last update time)都是可变的(即可被修改的)。
这种实现方式将会话数据、用户状态以及应用程序状态直接存储在内存中,并使用“并发映射”(concurrent maps)来确保线程安全。它适用于测试环境或单节点部署场景,在这些场景中并不需要数据的持久化存储。
注意:状态合并(应用程序/用户状态前缀为“app/”或“user/”) _app_ / _user_这种情况发生在数据检索过程中。)getSession, createSession).
-
嵌套类概述
Nested ClassesModifier and TypeClassDescriptionstatic enum什么createSession当……时,它会做……sessionId该名称已被其他人使用(或:该名称已被占用,因此无法被再次使用)。 -
构造函数概述
ConstructorsConstructorDescription创建一个新的内存会话服务实例,该实例的存储空间为空(即不包含任何数据)。InMemorySessionService(InMemorySessionService.DuplicateSessionIdBehavior duplicateSessionIdBehavior) 创建一个新的内存会话服务实例,该实例的存储空间为空(即不包含任何数据)。InMemorySessionService(InMemorySessionService.DuplicateSessionIdBehavior duplicateSessionIdBehavior, InstantSource instantSource, UuidProvider uuidProvider) 创建一个新的内存会话服务实例,该实例的存储空间为空(即不包含任何数据)。 -
方法概述
Modifier and TypeMethodDescriptionio.reactivex.rxjava3.core.Single<Event> appendEvent(Session session, Event event) 将一个事件添加到内存中的会话对象中,并根据该事件的状态变化(如果适用的话)更新会话的状态。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) 使用指定的参数创建一个新的会话。io.reactivex.rxjava3.core.CompletabledeleteSession(String appName, String userId, String sessionId) 删除特定的会话。io.reactivex.rxjava3.core.Maybe<Session> getSession(String appName, String userId, String sessionId, Optional<GetSessionConfig> configOpt) 检索特定的会话(session),并可选择性地过滤其中包含的事件(events)。io.reactivex.rxjava3.core.Single<ListEventsResponse> listEvents(String appName, String userId, String sessionId) 列出特定会话中的所有事件。io.reactivex.rxjava3.core.Single<ListSessionsResponse> listSessions(String appName, String userId) 列出与特定应用程序和用户关联的会话(session)。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)。
-
构造函数详细信息
-
InMemorySessionService
public InMemorySessionService()创建一个新的内存会话服务实例,该实例的存储空间为空。如果使用相同的会话 ID,新的会话会覆盖已存储的会话数据;此时,会话的默认设置将继续生效,直到调用者完成数据迁移。 -
InMemorySessionService
public InMemorySessionService(InMemorySessionService.DuplicateSessionIdBehavior duplicateSessionIdBehavior) 创建一个新的内存会话服务实例,该实例的存储空间为空(即不包含任何数据)。- Parameters:
duplicateSessionIdBehavior- WhatcreateSessiondoes when the session ID is already in use.
-
InMemorySessionService
public InMemorySessionService(InMemorySessionService.DuplicateSessionIdBehavior duplicateSessionIdBehavior, InstantSource instantSource, UuidProvider uuidProvider) 创建一个新的内存会话服务实例,该实例的存储空间为空(即不包含任何数据)。- Parameters:
duplicateSessionIdBehavior- WhatcreateSessiondoes when the session ID is already in use.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) 描述内容复制自接口文档:BaseSessionService使用指定的参数创建一个新的会话。- 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) 描述内容复制自接口文档:BaseSessionService使用指定的参数创建一个新的会话。- 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) 描述内容复制自接口文档:BaseSessionService检索特定的会话(session),并可选择性地过滤其中包含的事件(events)。- 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) 描述内容复制自接口文档:BaseSessionService列出与特定应用程序和用户关联的会话(session)。The
Session响应中的对象通常只包含元数据(如 ID、创建时间等),而不包含完整的事件列表或系统状态,这样有助于优化性能。- 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) 描述内容复制自接口文档:BaseSessionService删除特定的会话。- 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) 描述内容复制自接口文档:BaseSessionService列出特定会话中的所有事件。支持通过响应对象实现分页功能。- 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) 描述内容复制自接口文档:BaseSessionService将一个事件添加到内存中的会话对象中,并根据该事件的状态变化(如果适用的话)更新会话的状态。此方法主要修改传入的参数(即 `passed` 参数)。
session这些数据存储在内存中。要使这些更改持久化(即让它们在系统重启后仍然存在),通常需要调用特定服务提供的 `update` 或 `save` 方法;不过,根据该服务的实现方式,这一过程也可能被隐式地完成(即无需用户进行任何操作)。如果该事件被标记为“部分完成”(例如:……),
event.isPartial() == true当数据被返回时,它会直接被发送出去,而不会修改会话状态或事件列表。以 “State delta keys starting with” 开头的键用于表示状态变化的相关信息。State.TEMP_PREFIX在状态更新过程中,这些内容会被忽略。- 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).
-