Package org.springframework.ai.session
Class DefaultSessionService
java.lang.Object
org.springframework.ai.session.DefaultSessionService
- All Implemented Interfaces:
SessionService
The
SessionService on a SessionRepository.- Since:
- 2.1.0
- Author:
- Christian Tzolov
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionvoidappendEvent(SessionEvent event) Appends an event to the session named bySessionEvent.getSessionId().builder()compact(String sessionId, CompactionTrigger trigger, CompactionStrategy strategy) Evaluates the trigger on the active view and, when it fires, runs the strategy and records its result: oneEventType.COMPACTIONboundary event followed by the summary events, in one version-checked append.create(CreateSessionRequest request) Creates a session with the request's id, a random UUID when it has none, its time to live and its metadata.voidDeletes the session and its events.intdeleteExpiredSessions(Instant before) Deletes every session that expired before the given instant, with their events, and returns how many.@Nullable SessionfindByMetadata(String name, String value) The sessions whose metadata holdsvalueundername, oldest first, for the keys the store indexes; seeSessionRepository.findByMetadata(java.lang.String, java.lang.String).getEvents(String sessionId, EventFilter filter) The events the filter selects, oldest first; seeEventFilter.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.ai.session.SessionService
appendMessage, findOrCreate, getActiveMessages, getEvents, getMessages
-
Method Details
-
create
Description copied from interface:SessionServiceCreates a session with the request's id, a random UUID when it has none, its time to live and its metadata.- Specified by:
createin interfaceSessionService
-
findById
- Specified by:
findByIdin interfaceSessionService
-
findByMetadata
Description copied from interface:SessionServiceThe sessions whose metadata holdsvalueundername, oldest first, for the keys the store indexes; seeSessionRepository.findByMetadata(java.lang.String, java.lang.String). The sessions of a principal arefindByMetadata(SessionAttributes.PRINCIPAL_NAME, name).- Specified by:
findByMetadatain interfaceSessionService
-
delete
Description copied from interface:SessionServiceDeletes the session and its events.- Specified by:
deletein interfaceSessionService
-
deleteExpiredSessions
Description copied from interface:SessionServiceDeletes every session that expired before the given instant, with their events, and returns how many. Nothing calls this on its own: call it from a scheduler, every hour for example.- Specified by:
deleteExpiredSessionsin interfaceSessionService
-
appendEvent
Description copied from interface:SessionServiceAppends an event to the session named bySessionEvent.getSessionId().- Specified by:
appendEventin interfaceSessionService
-
getEvents
Description copied from interface:SessionServiceThe events the filter selects, oldest first; seeEventFilter.- Specified by:
getEventsin interfaceSessionService
-
compact
public CompactionResult compact(String sessionId, CompactionTrigger trigger, CompactionStrategy strategy) Description copied from interface:SessionServiceEvaluates the trigger on the active view and, when it fires, runs the strategy and records its result: oneEventType.COMPACTIONboundary event followed by the summary events, in one version-checked append. The log is never changed; the boundary defines the view from then on. An append that lands in between does not waste the summary: the new events join the view verbatim and the write is retried, a bounded number of times. Passrequest -> trueto compact unconditionally.- Specified by:
compactin interfaceSessionService- Returns:
- the result as written, the events appended meanwhile added to its preserved
tail;
CompactionResult.isUnchanged()when nothing was written: the trigger did not fire, the strategy covered nothing, another compaction landed first, or appends kept overtaking the write
-
builder
-