Class SessionRegistry
- All Implemented Interfaces:
EventListener,HttpSessionListener,ServletContextListener
As ServletContextListener, receives "contextInitialized" event, and sets servletContext attribute.
As HttpSessionListener, receives "sessionCreated" and "sessionDestroyed" events. SessionBeans are created when the session is created, and destroyed when the
session is destroyed.
- Author:
- ostwald
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidMethod called when a context is destroyed.voidCalled when context is initialized, sets ServletContext as class attribute.voiddestroy()Release locked recordsbooleanGets the lock attribute of the SessionRegistry object.Gets the lockedRecords attribute of the SessionRegistry object, which stores all locked records and the sessions that owns the lock.getSession(String id) Returns active session corresponding to given Id.getSessionBean(HttpServletRequest request) Return the SessionBean associated with the HttpSession for the provided request.Returns a list of all active SessionBean instances.booleangetUniqueLock(String recId, String sessionId) A version of getLock that only allows a single record to be locked by a single session at a timegetUserSessionBeans(User user) booleanReturns true if there is a lock for the given record.myLockedRecords(String sessionId) Find records locked by a given session.booleanIs a record locked by the given session?voidregisterSessionBean(SessionBean sessionBean) Register a sessionBean by putting it into the sessionBeanMap.voidRelease all locked records.voidreleaseAllLocks(String sessionId) Release all the locks owned by a particluar session.booleanreleaseLock(String recId) Releases the lock for given record, regardless of what session owns the lock.booleanreleaseLock(String recId, String sessionId) Release lock held by specified sesssionvoidCalled when a session is created with sole effect of putting the created session into the activeSessions map.voidNotified when a session is about to be destroyed - removes the session from the activeSessions map and unregisteres sessionBean.voidunregisterSessionBean(String sessionId) Unregister a sessionBean by calling itsdestroymethod (releasing all held locks), and removing its entry from the sessionBeanMap.
-
Constructor Details
-
SessionRegistry
public SessionRegistry()Constructor for the SessionRegistry object.activeSessionsMap map maintains the set of ALL active sessions, and is only modified by
sessionCreated(HttpSessionEvent)andsessionDestroyed(HttpSessionEvent)listeners.sessionBeanMap maintains the set of sessionBean instances, which are created only for interactive sessions - which excludes sessions created by webservice requests.
-
-
Method Details
-
contextDestroyed
Method called when a context is destroyed. Unregisters all sessions and empties lockedRecords.- Specified by:
contextDestroyedin interfaceServletContextListener- Parameters:
event- Description of the Parameter- See Also:
-
contextInitialized
Called when context is initialized, sets ServletContext as class attribute.- Specified by:
contextInitializedin interfaceServletContextListener- Parameters:
event- Description of the Parameter
-
getLockedRecords
Gets the lockedRecords attribute of the SessionRegistry object, which stores all locked records and the sessions that owns the lock.- Returns:
- The lockedRecords value
-
sessionCreated
Called when a session is created with sole effect of putting the created session into the activeSessions map. Items are removed from the activeSessionsMap wehn sessions are destroyed.- Specified by:
sessionCreatedin interfaceHttpSessionListener- Parameters:
se- notification event
-
sessionDestroyed
Notified when a session is about to be destroyed - removes the session from the activeSessions map and unregisteres sessionBean.- Specified by:
sessionDestroyedin interfaceHttpSessionListener- Parameters:
se- notification event- See Also:
-
isLocked
Returns true if there is a lock for the given record.- Parameters:
recId- Description of the Parameter- Returns:
- The locked value
-
ownsLock
Is a record locked by the given session?- Parameters:
recId- Description of the ParametersessionId- Id of given session- Returns:
- true if session owns lock to record
-
myLockedRecords
Find records locked by a given session. Should never be more than one!- Parameters:
sessionId- Description of the Parameter- Returns:
- list of record Ids
-
releaseAllLocks
public void releaseAllLocks()Release all locked records. -
releaseAllLocks
Release all the locks owned by a particluar session.- Parameters:
sessionId- Id of session that is releasing records.
-
getLock
Gets the lock attribute of the SessionRegistry object.- Parameters:
recId- Description of the ParametersessionId- Description of the Parameter- Returns:
- true if lock is obtained by requesting session
-
getUniqueLock
A version of getLock that only allows a single record to be locked by a single session at a time- Parameters:
recId- Description of the ParametersessionId- Description of the Parameter- Returns:
- The uniqueLock value
-
releaseLock
Releases the lock for given record, regardless of what session owns the lock.- Parameters:
recId- Description of the Parameter- Returns:
- true if there was a lock for given record ID
-
releaseLock
Release lock held by specified sesssion- Parameters:
recId- Description of the ParametersessionId- Description of the Parameter- Returns:
- true if specified session owned lock on record
-
registerSessionBean
Register a sessionBean by putting it into the sessionBeanMap.- Parameters:
sessionBean- Description of the Parameter
-
unregisterSessionBean
Unregister a sessionBean by calling itsdestroymethod (releasing all held locks), and removing its entry from the sessionBeanMap.- Parameters:
sessionId- Description of the Parameter
-
getSession
Returns active session corresponding to given Id.- Parameters:
id- session id- Returns:
- a HttpSession instance, or null if none was found for given id.
-
getSessionBean
Return the SessionBean associated with the HttpSession for the provided request.If a sessionBean does not yet exist for a valid session, then it is created and bound to the session context. This method is the standard way of obtaining of obtaining a sessionBean from within a Controller or FormBean.
- Parameters:
request- A request instance that is associated with a session- Returns:
- The sessionBean value for the request's session.
-
getUserSessionBeans
-
getSessionBeans
Returns a list of all active SessionBean instances.Unregisters sessionBeans corresponding to sessions that have been invalidated.
- Returns:
- list of
SessionBean
-
destroy
public void destroy()Release locked records
-