|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.shiro.session.mgt.eis.AbstractSessionDAO org.apache.shiro.session.mgt.eis.CachingSessionDAO
public abstract class CachingSessionDAO
An CachingSessionDAO is a SessionDAO that provides a transparent caching layer between the components that use it and the underlying EIS (Enterprise Information System) session backing store (for example, filesystem, database, enterprise grid/cloud, etc).
This implementation caches all active sessions in a configuredactiveSessionsCache
. This property is null
by default and if one is
not explicitly set, a cacheManager
is expected to be configured which will in turn be used
to acquire the Cache
instance to use for the activeSessionsCache
.
All SessionDAO
methods are implemented by this class to employ
caching behavior and delegates the actual EIS operations to respective do* methods to be implemented by
subclasses (doCreate, doRead, etc).
Field Summary | |
---|---|
static String |
ACTIVE_SESSION_CACHE_NAME
The default active sessions cache name, equal to shiro-activeSessionCache . |
Constructor Summary | |
---|---|
CachingSessionDAO()
Default no-arg constructor. |
Method Summary | |
---|---|
protected void |
cache(Session session,
Serializable sessionId)
Caches the specified session under the cache entry key of sessionId . |
protected void |
cache(Session session,
Serializable sessionId,
Cache<Serializable,Session> cache)
Caches the specified session in the given cache under the key of sessionId . |
Serializable |
create(Session session)
Calls super.create(session) , then caches the session keyed by the returned sessionId , and then
returns this sessionId . |
protected Cache<Serializable,Session> |
createActiveSessionsCache()
Creates a cache instance used to store active sessions. |
void |
delete(Session session)
Removes the specified session from any cache and then permanently deletes the session from the EIS by delegating to doDelete(org.apache.shiro.session.Session) . |
protected abstract void |
doDelete(Session session)
Subclass implementation hook to permanently delete the given Session from the underlying EIS. |
protected abstract void |
doUpdate(Session session)
Subclass implementation hook to actually persist the Session 's state to the underlying EIS. |
Collection<Session> |
getActiveSessions()
Returns all active sessions in the system. |
Cache<Serializable,Session> |
getActiveSessionsCache()
Returns the cache instance to use for storing active sessions. |
String |
getActiveSessionsCacheName()
Returns the name of the actives sessions cache to be returned by the CacheManager . |
protected Session |
getCachedSession(Serializable sessionId)
Returns the cached session with the corresponding sessionId or null if there is
no session cached under that id (or if there is no Cache). |
protected Session |
getCachedSession(Serializable sessionId,
Cache<Serializable,Session> cache)
Returns the Session with the specified id from the specified cache. |
CacheManager |
getCacheManager()
Returns the CacheManager to use for acquiring the activeSessionsCache if
one is not configured. |
Session |
readSession(Serializable sessionId)
Attempts to acquire the Session from the cache first using the session ID as the cache key. |
void |
setActiveSessionsCache(Cache<Serializable,Session> cache)
Sets the cache instance to use for storing active sessions. |
void |
setActiveSessionsCacheName(String activeSessionsCacheName)
Sets the name of the active sessions cache to be returned by the CacheManager . |
void |
setCacheManager(CacheManager cacheManager)
Sets the cacheManager to use for acquiring the activeSessionsCache if
one is not configured. |
protected void |
uncache(Session session)
Removes the specified Session from the cache. |
void |
update(Session session)
Updates the state of the given session to the EIS by first delegating to doUpdate(org.apache.shiro.session.Session) . |
Methods inherited from class org.apache.shiro.session.mgt.eis.AbstractSessionDAO |
---|
assignSessionId, doCreate, doReadSession, generateSessionId, getSessionIdGenerator, setSessionIdGenerator |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String ACTIVE_SESSION_CACHE_NAME
shiro-activeSessionCache
.
Constructor Detail |
---|
public CachingSessionDAO()
Method Detail |
---|
public void setCacheManager(CacheManager cacheManager)
activeSessionsCache
if
one is not configured.
setCacheManager
in interface CacheManagerAware
cacheManager
- the manager to use for constructing the session cache.public CacheManager getCacheManager()
activeSessionsCache
if
one is not configured. That is, the CacheManager
will only be used if the
activeSessionsCache
property is null
.
public String getActiveSessionsCacheName()
CacheManager
. Unless
overridden by setActiveSessionsCacheName(String)
, defaults to ACTIVE_SESSION_CACHE_NAME
.
public void setActiveSessionsCacheName(String activeSessionsCacheName)
CacheManager
. Defaults to
ACTIVE_SESSION_CACHE_NAME
.
activeSessionsCacheName
- the name of the active sessions cache to be returned by the CacheManager
.public Cache<Serializable,Session> getActiveSessionsCache()
null
),
it will be acquired
from the configured
CacheManager
using the activeSessionsCacheName
.
null
if the Cache
instance
should be retrieved from thepublic void setActiveSessionsCache(Cache<Serializable,Session> cache)
null
),
it will be acquired
from the configured
CacheManager
using the activeSessionsCacheName
.
cache
- the cache instance to use for storing active sessions or null
if the cache is to be
acquired from the configured
CacheManager
.protected Cache<Serializable,Session> createActiveSessionsCache()
acquiring
the CacheManager
. If the cache manager is not null, the
cache returned is that resulting from the following call:
String name = getActiveSessionsCacheName()
;
cacheManager.getCache(name);
null
if the CacheManager
has
not been set.public Serializable create(Session session)
super.create(session)
, then caches the session keyed by the returned sessionId
, and then
returns this sessionId
.
create
in interface SessionDAO
create
in class AbstractSessionDAO
session
- Session object to create in the EIS and then cache.
Session
object.protected Session getCachedSession(Serializable sessionId)
sessionId
or null
if there is
no session cached under that id (or if there is no Cache).
sessionId
- the id of the cached session to acquire.
sessionId
, or null
if the session
does not exist or is not cached.protected Session getCachedSession(Serializable sessionId, Cache<Serializable,Session> cache)
cache.get(sessionId)
and can be overridden by subclasses for custom acquisition behavior.
sessionId
- the id of the session to acquire.cache
- the cache to acquire the session from
null
if the session wasn't in the cache.protected void cache(Session session, Serializable sessionId)
sessionId
.
session
- the session to cachesessionId
- the session id, to be used as the cache entry key.protected void cache(Session session, Serializable sessionId, Cache<Serializable,Session> cache)
sessionId
. This implementation
simply calls cache.put(sessionId,session)
and can be overridden for custom behavior.
session
- the session to cachesessionId
- the id of the session, expected to be the cache key.cache
- the cache to store the sessionpublic Session readSession(Serializable sessionId) throws UnknownSessionException
super.readSession(sessionId)
is called to perform the actual retrieval.
readSession
in interface SessionDAO
readSession
in class AbstractSessionDAO
sessionId
- the id of the session to retrieve from the EIS.
sessionId
in the EIS.
UnknownSessionException
- if the id specified does not correspond to any session in the cache or EIS.public void update(Session session) throws UnknownSessionException
doUpdate(org.apache.shiro.session.Session)
. If the session is a ValidatingSession
, it will
be added to the cache only if it is ValidatingSession.isValid()
and if invalid, will be removed from the
cache. If it is not a ValidatingSession
instance, it will be added to the cache in any event.
update
in interface SessionDAO
session
- the session object to update in the EIS.
UnknownSessionException
- if no existing EIS session record exists with the
identifier of session.getId()
protected abstract void doUpdate(Session session)
Session
's state to the underlying EIS.
session
- the session object whose state will be propagated to the EIS.public void delete(Session session)
doDelete(org.apache.shiro.session.Session)
.
delete
in interface SessionDAO
session
- the session to remove from caches and permanently delete from the EIS.protected abstract void doDelete(Session session)
session
- the session instance to permanently delete from the EIS.protected void uncache(Session session)
session
- the session to remove from the cache.public Collection<Session> getActiveSessions()
This implementation merely returns the sessions found in the activeSessions cache. Subclass implementations may wish to override this method to retrieve them in a different way, perhaps by an RDBMS query or by other means.
getActiveSessions
in interface SessionDAO
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |