Package ome.services.sessions.state
Class SessionCache
- java.lang.Object
-
- ome.services.sessions.state.SessionCache
-
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware
public class SessionCache extends java.lang.Object implements org.springframework.context.ApplicationContextAwareSynchronized and lockable state for theSessionManager. Maps fromSessionuuid toSessionContextin memory, with each mapping also having an additional cache which may spill over to disk,listeners. UsesMapMakerand various implementations from java.util.concurrent.atomic to provide a lock-free implementation.- Since:
- 4.2.1
- See Also:
- ticket:3173
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceSessionCache.StaleCacheListenerObserver pattern used to refresh sessions in doUpdate.
-
Constructor Summary
Constructors Constructor Description SessionCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddSessionCallback(java.lang.String session, SessionCallback cb)protected net.sf.ehcache.EhcachecreateCache(java.lang.String key, boolean inMemory, int maxInMemory)voiddoUpdate()Will only ever be accessed by a single thread.java.util.Set<java.lang.String>getIds()Since all methods which usegetIds()will subsequently check for the existing session, we do not block here.longgetLastUpdated()SessionContextgetSessionContext(java.lang.String uuid)Retrieve a session possibly raising eitherRemovedSessionExceptionorSessionTimeoutException.SessionContextgetSessionContext(java.lang.String uuid, boolean quietly)Retrieve a session possibly raising eitherRemovedSessionExceptionorSessionTimeoutException.java.util.Map<java.lang.String,java.lang.Object>getSessionData(java.lang.String uuid, boolean quietly)Returns all the data contained in the internal implementation of this manager.net.sf.ehcache.EhcacheinMemoryCache(java.lang.String uuid)net.sf.ehcache.EhcacheonDiskCache(java.lang.String uuid)voidputSession(java.lang.String uuid, SessionContext sessionContext)Puts a session blindly into the context.voidrefresh(java.lang.String uuid, SessionContext replacement)Used externally to refresh theSessionContextinstance associated with the session uuidvoidreload(java.lang.String id)Provides the reloading logic of theSessionCachefor theSessionManagerImplto use.voidremoveSession(java.lang.String uuid)booleanremoveSessionCallback(java.lang.String session, SessionCallback cb)voidsetApplicationContext(org.springframework.context.ApplicationContext ctx)Context injector.voidsetCacheManager(net.sf.ehcache.CacheManager manager)Injection method, also performs the creation ofsessionsvoidsetStaleCacheListener(SessionCache.StaleCacheListener staleCacheListener)voidsetUpdateInterval(long milliseconds)Inject time in milliseconds between updates.voidupdateEvent(UserGroupUpdateEvent ugue)Adds a new entry tostate.
-
-
-
Method Detail
-
setCacheManager
public void setCacheManager(net.sf.ehcache.CacheManager manager)
Injection method, also performs the creation ofsessions
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext ctx) throws org.springframework.beans.BeansExceptionContext injector.- Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-
setUpdateInterval
public void setUpdateInterval(long milliseconds)
Inject time in milliseconds between updates.
-
setStaleCacheListener
public void setStaleCacheListener(SessionCache.StaleCacheListener staleCacheListener)
-
addSessionCallback
public boolean addSessionCallback(java.lang.String session, SessionCallback cb)
-
removeSessionCallback
public boolean removeSessionCallback(java.lang.String session, SessionCallback cb)
-
putSession
public void putSession(java.lang.String uuid, SessionContext sessionContext)Puts a session blindly into the context. This does nothing to a context which was previously present (e.g. call internalRemove, etc.) and therefore usage should be proceeded by a check.
-
refresh
public void refresh(java.lang.String uuid, SessionContext replacement)Used externally to refresh theSessionContextinstance associated with the session uuid- Parameters:
uuid-replacement-
-
getSessionContext
public SessionContext getSessionContext(java.lang.String uuid)
Retrieve a session possibly raising eitherRemovedSessionExceptionorSessionTimeoutException.
-
getSessionContext
public SessionContext getSessionContext(java.lang.String uuid, boolean quietly)
Retrieve a session possibly raising eitherRemovedSessionExceptionorSessionTimeoutException.- Parameters:
quietly- If true, then the access time for the given UUID will not be updated.
-
getSessionData
public java.util.Map<java.lang.String,java.lang.Object> getSessionData(java.lang.String uuid, boolean quietly)Returns all the data contained in the internal implementation of this manager.- Parameters:
quietly- If true, then the access time for the given UUID will not be updated.
-
removeSession
public void removeSession(java.lang.String uuid)
-
getIds
public java.util.Set<java.lang.String> getIds()
Since all methods which usegetIds()will subsequently check for the existing session, we do not block here. Blocking is primarily useful for post-admintype changes which can add or remove a user from a group. The existence of a session (which is what getIds specifies) is not significantly effected.
-
inMemoryCache
public net.sf.ehcache.Ehcache inMemoryCache(java.lang.String uuid)
-
onDiskCache
public net.sf.ehcache.Ehcache onDiskCache(java.lang.String uuid)
-
createCache
protected net.sf.ehcache.Ehcache createCache(java.lang.String key, boolean inMemory, int maxInMemory)
-
getLastUpdated
public long getLastUpdated()
-
updateEvent
public void updateEvent(UserGroupUpdateEvent ugue)
Adds a new entry tostate. If the timestamp on the event is invalid, thenSystem.currentTimeMillis()will be used.
-
doUpdate
public void doUpdate()
Will only ever be accessed by a single thread. Rechecks the target update time again in case a second write thread was blocking the current one.activegets set totruevalue to specify that this method is currently running.
-
reload
public void reload(java.lang.String id)
Provides the reloading logic of theSessionCachefor theSessionManagerImplto use.- See Also:
- ticket:4011, ticket:5849
-
-