Class LocalSessionStore
- All Implemented Interfaces:
Closeable
,AutoCloseable
This store makes sure the given session is a copy of the original session object in order to avoid a situation where 2 concurrent requests edit the same session leading to an unexpected behaviour for the user. That also means that when a session is used by multiple requests, if they both modify the session content, only the session content (of the last save operation) is going to be "persisted".
This store must be closed after use.
-
Constructor Summary
ConstructorDescriptionLocalSessionStore
(Duration idleTimeout, Clock clock) Create an instance of aLocalSessionStore
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Create a new session.getSession
(String sessionId) Retrieve the session from the session store.void
Save the session into the session store.
-
Constructor Details
-
LocalSessionStore
Create an instance of aLocalSessionStore
.- Parameters:
idleTimeout
- the Idle timeout of sessionsclock
- the Clock to use
-
-
Method Details
-
getSession
Retrieve the session from the session store.The session retrieved is a copy of the stored session, so it must be saved back into the store after use.
- Parameters:
sessionId
- The session ID to look for.- Returns:
- the session when found, otherwise an empty
Optional
.
-
saveSession
Save the session into the session store. Will replace existing session with the same ID if any.This method will compute a session ID if the session has no session ID already. This computation impacts the performances and thus must be done lazily.
- Parameters:
session
- The session to save.
-
createNewSession
Create a new session.A newly created session has no ID (ie:
TrackedSession.id()
returnsnull
). This is for performance reasons: computing an ID takes time, so we must only do this computation when we know the session will actually be saved.- Returns:
- The new session.
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-