public class InMemoryRepository extends Object implements SessionRepository
We are storing session in memory in ConcurrentHashMap. For each
session we store SessionData and session attributes. Multiple threads
can access both separate session and same session id, and while repository is
thread safe, functional concurrency when using same session id from different
threads must be assured in application code (as is general case for
HttpSession.
Sessions are cleaned-up by a special task running in separate thread every 60
seconds. Only one task is running at the given time and this is assured by
SessionManager.schedule(String, Runnable, long) method.
SessionRepository.CommitTransaction| Constructor and Description |
|---|
InMemoryRepository(String namespace)
Constructor for in-memory repository.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
cleanSessionsOnShutdown()
If repository supports cleaning of sessions on application shutdown, it
should return
true from this method. |
void |
close()
Called to shutdown the repository and release resources.
|
Set<String> |
getAllKeys(SessionData session)
Get all attribute keys stored in the session.
|
Collection<String> |
getOwnedSessionIds()
Returns session ids stored in repository and owned by current application
node.
|
Object |
getSessionAttribute(SessionData session,
String attribute)
Returns value of the attribute or
null if attribute or session
have not been found |
SessionData |
getSessionData(String id)
Retrieves global session data from repository.
|
boolean |
prepareRemove(SessionData session)
Prepares session repository for removal of session.
|
void |
remove(SessionData session)
Removes session from the repository.
|
void |
removeSessionAttribute(SessionData session,
String name)
The attribute for the session will be removed from the repository.
|
void |
requestFinished()
Called to clean up resources after the request has been completed and the
session will no longer be used in the current thread.
|
void |
sessionIdChange(SessionData sessionData)
Called by session manager to notify repository that session id has changed.
|
void |
setSessionAttribute(SessionData session,
String name,
Object value)
Sets the value of the attribute for the session in the repository.
|
void |
setSessionManager(SessionManager sessionManager)
Links repository with the session management.
|
SessionRepository.CommitTransaction |
startCommit(SessionData session)
Starts transaction on remote session.
|
void |
storeSessionData(SessionData sessionData)
Stores global session data into repository
|
public InMemoryRepository(String namespace)
namespace - the namespace of sessions stored in this repositorypublic SessionData getSessionData(String id)
SessionRepositorygetSessionData in interface SessionRepositoryid - the session idnull
if data wasn't found in repository.public void storeSessionData(SessionData sessionData)
SessionRepositorystoreSessionData in interface SessionRepositorysessionData - the session informationpublic Set<String> getAllKeys(SessionData session)
SessionRepositorygetAllKeys in interface SessionRepositorysession - the session informationpublic Object getSessionAttribute(SessionData session, String attribute)
SessionRepositorynull if attribute or session
have not been foundgetSessionAttribute in interface SessionRepositorysession - the session informationattribute - the key of the attribute to retrievenull if attribute or session
have not been foundpublic void remove(SessionData session)
SessionRepositoryremove in interface SessionRepositorysession - the session informationpublic boolean prepareRemove(SessionData session)
SessionRepositorytrue if caller can proceed with session
removal.prepareRemove in interface SessionRepositorysession - the session informationtrue if caller can proceed with session removalpublic SessionRepository.CommitTransaction startCommit(SessionData session)
SessionRepositorySessionRepository.CommitTransaction for more information.startCommit in interface SessionRepositorysession - the session informationpublic void setSessionManager(SessionManager sessionManager)
SessionRepositorySessionManager.setSessionManager in interface SessionRepositorysessionManager - the session manager to associatepublic void requestFinished()
SessionRepositoryrequestFinished in interface SessionRepositorypublic void setSessionAttribute(SessionData session, String name, Object value)
SessionRepositorysetSessionAttribute in interface SessionRepositorysession - the session informationname - attribute namevalue - attribute value. If session is stored remotely, attribute should
be Serializable.public void removeSessionAttribute(SessionData session, String name)
SessionRepositoryremoveSessionAttribute in interface SessionRepositorysession - the session informationname - attribute namepublic boolean cleanSessionsOnShutdown()
SessionRepositorytrue from this method.cleanSessionsOnShutdown in interface SessionRepositorytrue if repository supports cleaning of sessions on
application shutdownpublic Collection<String> getOwnedSessionIds()
SessionRepositoryUnsupportedOperationException if repository
doesn't offer this functionality.getOwnedSessionIds in interface SessionRepositorypublic void close()
SessionRepositoryclose in interface SessionRepositoryclose in interface Closeableclose in interface AutoCloseablepublic void sessionIdChange(SessionData sessionData)
SessionRepositorysessionIdChange in interface SessionRepositorysessionData - the session informationCopyright © 2018 Amadeus s.a.s.. All rights reserved.