createSession

open suspend override fun createSession(key: SessionKey, state: Map<String, Any>? = null): Session

Creates a new session with the specified parameters.

Return

The newly created Session instance.

Parameters

key

The composite identifier of the session. If SessionKey.id is null, the service generates a unique session id and the returned Session will reflect it.

state

An optional map representing the initial state of the session.

Throws

with SessionException.SESSION_ALREADY_EXISTS if a session already exists under SessionKey.id for this app and user. An existing session is never overwritten. A service backed by a managed remote store may surface that backend's own error instead.


suspend fun createSession(key: SessionKey, state: Map<String, Any>? = null, ttl: Duration? = null, expireTime: Instant? = null): Session

Creates a session that expires, addressing the reasoning engine fixed at construction.

At most one of ttl and expireTime may be set, because the backend models them as a single choice; setting both is rejected. The backend also requires the expiry to be at least 24 hours out. When neither is given, the service-wide sessionTtl applies if one was configured.

Return

The newly created Session.

Parameters

key

The composite identifier of the session; SessionKey.appName is only a label, and SessionKey.id, when non-empty, is the requested id and must match [a-zA-Z0-9_-]+. The backend's own rule is narrower, so it can still reject an id this class accepts.

state

An optional map representing the initial state of the session.

ttl

How long the session lives, measured from creation. Sub-second precision is dropped.

expireTime

The absolute instant at which the session expires.