Class FirestoreSessionService
java.lang.Object
com.google.adk.sessions.FirestoreSessionService
- All Implemented Interfaces:
BaseSessionService
FirestoreSessionService implements session management using Google Firestore as the backend
storage.
-
Constructor Summary
ConstructorsConstructorDescriptionFirestoreSessionService(com.google.cloud.firestore.Firestore firestore) Constructor for FirestoreSessionService. -
Method Summary
Modifier and TypeMethodDescriptionio.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> Creates a new session in Firestore.io.reactivex.rxjava3.core.CompletabledeleteSession(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, waitMethods inherited from interface BaseSessionService
closeSession, createSession, createSession, createSession, deleteSession, getSession, listEvents, listSessions
-
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:
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) Creates a new session in 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.
-
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:
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) Lists all sessions for a given appName and 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) Deletes a session and all its associated events from 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) Lists all events for a given appName, userId, and 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) Appends an event to a session, updating the session state and persisting to 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).
-