Class InMemorySessionRecordRepository
java.lang.Object
org.jwcarman.who.test.InMemorySessionRecordRepository
- All Implemented Interfaces:
SessionRecordRepository
public final class InMemorySessionRecordRepository
extends Object
implements SessionRecordRepository
who's record of sessions kept in memory, for tests that do not run a database. Thread-safe.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintdeleteDead(Instant seenBefore, int limit) Deletes up tolimitdead sessions: ended ones, and ones last seen beforeseenBefore.booleanEnds a session that is not already ended.Finds a session, ended or not.findLiveByIdentity(UUID identityId, Instant seenSince) Finds an identity's sessions that are not ended and were seen at or afterseenSince, most recently signed in first.voidinsert(SessionRecord session) Saves a new session.booleanRecords that a session made a request, unless it is ended or was already seen at or afternotSince.static WhoSessionswhoSessions(Clock clock, WhoEventPublisher events) Creates aWhoSessionsover a fresh in-memory store, with Spring Boot's default 30 minute idle timeout, a 5 minute last-seen interval and no auto-purge.
-
Constructor Details
-
InMemorySessionRecordRepository
public InMemorySessionRecordRepository()Creates an empty store.
-
-
Method Details
-
whoSessions
Creates aWhoSessionsover a fresh in-memory store, with Spring Boot's default 30 minute idle timeout, a 5 minute last-seen interval and no auto-purge.- Parameters:
clock- the current timeevents- receives ended and purged sessions- Returns:
- the sessions
-
insert
Description copied from interface:SessionRecordRepositorySaves a new session.- Specified by:
insertin interfaceSessionRecordRepository- Parameters:
session- the session
-
findById
Description copied from interface:SessionRecordRepositoryFinds a session, ended or not.- Specified by:
findByIdin interfaceSessionRecordRepository- Parameters:
id- the session's id- Returns:
- the session, or empty
-
findLiveByIdentity
Description copied from interface:SessionRecordRepositoryFinds an identity's sessions that are not ended and were seen at or afterseenSince, most recently signed in first.- Specified by:
findLiveByIdentityin interfaceSessionRecordRepository- Parameters:
identityId- the identityseenSince- the oldest last-seen time that still counts as live- Returns:
- the sessions
-
touch
Description copied from interface:SessionRecordRepositoryRecords that a session made a request, unless it is ended or was already seen at or afternotSince.- Specified by:
touchin interfaceSessionRecordRepository- Parameters:
id- the session's idnow- the time to recordnotSince- write only when the session was last seen before this- Returns:
- whether it was written
-
end
Description copied from interface:SessionRecordRepositoryEnds a session that is not already ended.- Specified by:
endin interfaceSessionRecordRepository- Parameters:
id- the session's idnow- when it ended- Returns:
- whether it was ended by this call
-
deleteDead
Description copied from interface:SessionRecordRepositoryDeletes up tolimitdead sessions: ended ones, and ones last seen beforeseenBefore.- Specified by:
deleteDeadin interfaceSessionRecordRepository- Parameters:
seenBefore- a session last seen before this is deadlimit- the most rows to delete- Returns:
- how many were deleted
-