BufferedSessionService
A SessionService that persists writes in the background: appendEvent updates the live session and returns, and a writer per session writes the events to delegate in order, and in order across sessions for app: and user: state, retrying as BufferedSessionServiceConfig.retryPolicy decides.
Buffered writes stay in memory until they are persisted; reads that go to the store and flush wait for the writes they depend on, and the runner flushes before each final response, which bounds how many writes a session holds. When retries run out, the session's buffered writes are dropped and a SessionException reports the failure to any flush or delete waiting on them, or else to the session's next append, flush or delete unless failures in 1024 other sessions displaced it; reload the session with getSession before appending again, since the live session still holds the dropped events.
Parameters
The store the writes are persisted to, which close leaves open; its SessionService.appendEvent receives a Session with only the key and the Session.lastUpdateTime the write replaces, so it must persist from the event alone. A retry after an attempt that failed but was persisted resends the event with that same Session.lastUpdateTime, so the store should treat an event it already holds as persisted, rather than store it twice or, with a stale-write check, reject it and fail the session. A call that never returns holds back the session's later writes, the reads that wait for them, and close.
Where the writes run. They outlive the run that made them, so they take their own context rather than the caller's; a kotlinx.coroutines.Job in it becomes their parent and cannot complete until close. An Error in a write stops the service and fails like an uncaught child coroutine, canceling a parent job that is not a supervisor and reaching the context's exception handler or the platform default.
How failed writes are retried, and whether a read cache serves getSession.
Constructors
Functions
Flushes every session and stops the writes, without closing delegate; like flush with a null key, it throws a SessionException for failures no session has reported. It blocks the calling thread, so do not call it on the Android main thread or on a thread the writes need.
Closes a session.
Creates a new session with the specified parameters.
Waits for the session's buffered writes, since its app: and user: changes outlive it, then deletes it from delegate. Like flush, it throws instead if one failed or a failure is unreported, so the caller can retry. Stop appending first: an append made after the delete starts is not waited for, and if it reaches the store after the delete the store may reject it, leaving a failure that flush reports.
Waits for the writes buffered for key, or for every session when key is null, and passes the flush on to delegate, then throws if a write of key it waited on failed or key has a failure unreported. With a null key, it throws every unreported failure, on each call until the session whose write failed reports it on an append, flush or delete.
Retrieves a specific session, optionally filtering the events included.
Lists the events within a specific session.
Lists sessions associated with a specific application and user.