public class SessionManager extends Object implements Closeable
In case of servlet engines, one session manager will be created per
ServletContext.
The manager provides following metrics:
| Modifier and Type | Field and Description |
|---|---|
protected SessionConfiguration |
configuration |
protected ExecutorFacade |
executors |
protected SessionFactory |
factory |
protected SessionNotifier |
notifier |
protected SessionRepository |
repository |
protected SerializerDeserializer |
serializerDeserializer |
protected SessionTracking |
tracking |
| Constructor and Description |
|---|
SessionManager(ExecutorFacade executors,
SessionFactory factory,
SessionRepository repository,
SessionTracking tracking,
SessionNotifier notifier,
SessionConfiguration configuration,
ClassLoader classLoader)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Called to shutdown the session manager and perform needed cleanup.
|
void |
delete(String sessionId,
boolean expired)
Deletes session from repository and performs orderly cleanup.
|
void |
deleteAsync(String sessionId,
boolean expired)
Deletes list of sessions.
|
String |
encodeUrl(RequestWithSession request,
String url)
Called to encode URL based on session tracking.
|
SessionConfiguration |
getConfiguration()
Configuration for this
SessionManager |
com.codahale.metrics.MetricRegistry |
getMetrics()
Retrieves metric registry for this session manager.
|
SessionNotifier |
getNotifier()
Returns
SessionNotifier used by this instance. |
SessionRepository |
getRepository()
Returns
SessionRepository used by this instance. |
SerializerDeserializer |
getSerializerDeserializer()
Serialiazer/deserializer to use when storing to repository.
|
RepositoryBackedSession |
getSession(RequestWithSession request,
boolean create,
String forceId)
Builds or retrieves session.
|
ClassLoader |
getSessionClassLoader()
Returns class loader to be used for session objects.
|
void |
invalidationConflict(RepositoryBackedSession session,
boolean onExpiry)
Called by
RepositoryBackedSession when a conflict occurs during
invalidation of session. |
void |
invokeCommit(RepositoryBackedSession session)
Calls
RepositoryBackedSession.Committer for the passed RepositoryBackedSession and
measures time of execution. |
void |
propagateSession(RequestWithSession request,
ResponseWithSessionId response)
Propagates the session id to the response.
|
void |
remove(SessionData sessionData) |
void |
requestFinished()
Called when request has been finished.
|
ScheduledFuture<?> |
schedule(String timer,
Runnable task,
long period)
Schedules the tasks to execute with a
ScheduledExecutorService with
the specified period. |
Future<?> |
submit(String timer,
Runnable task)
Executes task in separate thread.
|
void |
switchSessionId(RepositoryBackedSession session)
Changes session id of the passed session.
|
String |
toString() |
protected final SessionRepository repository
protected final SessionNotifier notifier
protected final SessionTracking tracking
protected final SessionFactory factory
protected final ExecutorFacade executors
protected final SessionConfiguration configuration
protected final SerializerDeserializer serializerDeserializer
public SessionManager(ExecutorFacade executors, SessionFactory factory, SessionRepository repository, SessionTracking tracking, SessionNotifier notifier, SessionConfiguration configuration, ClassLoader classLoader)
executors - thread schedulerfactory - creates memory representation of sessionrepository - repository should be namespace aware - if two
SessionManager from different namespaces request access to
session with same id, repository should give different sessions
(unless a special configuration overrides this).tracking - propagates session information to clientsnotifier - may trigger notifications for different session eventsconfiguration - the configurationclassLoader - the class loader to usepublic RepositoryBackedSession getSession(RequestWithSession request, boolean create, String forceId)
true, then a
new session is created. Session id is generated according to
SessionTracking implementation.
In some cases, in servlet engine, request can be forwarded from one web application to another one. In this case, the first web application that received request, is responsible for managing session id, and other web application down the chain will reuse this id.
request - the request being servetcreate - true if session should be createdforceId - forces usage of this session id.public void propagateSession(RequestWithSession request, ResponseWithSessionId response)
request - the current requestresponse - the current responsepublic void delete(String sessionId, boolean expired)
sessionId - the id of the session to deleteexpired - true if session is deleted because it has expiredpublic void requestFinished()
public Future<?> submit(String timer, Runnable task)
timer - if not null, the time to execute task will be measured and stored
under timer with given nametask - the task to runpublic ScheduledFuture<?> schedule(String timer, Runnable task, long period)
ScheduledExecutorService with
the specified period.timer - if not null, the time to execute task will be measured and stored
under timer with given nametask - the task to runperiod - period between invocations in secondspublic void deleteAsync(String sessionId, boolean expired)
sessionId - session id to deleteexpired - true if session is deleted because it has expiredpublic SessionRepository getRepository()
SessionRepository used by this instance.SessionRepository used by this instance.public SessionNotifier getNotifier()
SessionNotifier used by this instance.SessionNotifier used by this instance.public void invokeCommit(RepositoryBackedSession session)
RepositoryBackedSession.Committer for the passed RepositoryBackedSession and
measures time of execution.session - the session to commitpublic SessionConfiguration getConfiguration()
SessionManagerpublic ClassLoader getSessionClassLoader()
public SerializerDeserializer getSerializerDeserializer()
public void invalidationConflict(RepositoryBackedSession session, boolean onExpiry)
RepositoryBackedSession when a conflict occurs during
invalidation of session. Conflict may be due to fact that session is stil
used.session - the session to removeonExpiry - conflict occurred during expiration eventpublic com.codahale.metrics.MetricRegistry getMetrics()
public String encodeUrl(RequestWithSession request, String url)
request - the current requesturl - the URL to encodepublic void close()
close in interface Closeableclose in interface AutoCloseablepublic void switchSessionId(RepositoryBackedSession session)
session - the session whose id needs to changepublic void remove(SessionData sessionData)
Copyright © 2018 Amadeus s.a.s.. All rights reserved.