public class SessionRegistry
extends java.lang.Object
implements javax.servlet.ServletContextListener, javax.servlet.http.HttpSessionListener
As ServletContextListener, receives "contextInitialized" event, and sets servletContext attribute.
As HttpSessionListener, receives "sessionCreated" and "sessionDestroyed" events. SessionBean
s are created when the session is created, and destroyed when the
session is destroyed.
Constructor and Description |
---|
SessionRegistry()
Constructor for the SessionRegistry object.
|
Modifier and Type | Method and Description |
---|---|
void |
contextDestroyed(javax.servlet.ServletContextEvent event)
Method called when a context is destroyed.
|
void |
contextInitialized(javax.servlet.ServletContextEvent event)
Called when context is initialized, sets ServletContext as class attribute.
|
void |
destroy()
Release locked records
|
boolean |
getLock(java.lang.String recId,
java.lang.String sessionId)
Gets the lock attribute of the SessionRegistry object.
|
java.util.Map |
getLockedRecords()
Gets the lockedRecords attribute of the SessionRegistry object, which stores all locked records and the
sessions that owns the lock.
|
javax.servlet.http.HttpSession |
getSession(java.lang.String id)
Returns active session corresponding to given Id.
|
SessionBean |
getSessionBean(javax.servlet.http.HttpServletRequest request)
Return the SessionBean associated with the HttpSession for the provided request.
|
java.util.List |
getSessionBeans()
Returns a list of all active SessionBean instances.
|
boolean |
getUniqueLock(java.lang.String recId,
java.lang.String sessionId)
A version of getLock that only allows a single record to be locked by a single session at a time
|
java.util.List |
getUserSessionBeans(User user) |
boolean |
isLocked(java.lang.String recId)
Returns true if there is a lock for the given record.
|
java.util.List |
myLockedRecords(java.lang.String sessionId)
Find records locked by a given session.
|
boolean |
ownsLock(java.lang.String recId,
java.lang.String sessionId)
Is a record locked by the given session?
|
void |
registerSessionBean(SessionBean sessionBean)
Register a sessionBean by putting it into the sessionBeanMap.
|
void |
releaseAllLocks()
Release all locked records.
|
void |
releaseAllLocks(java.lang.String sessionId)
Release all the locks owned by a particluar session.
|
boolean |
releaseLock(java.lang.String recId)
Releases the lock for given record, regardless of what session owns the lock.
|
boolean |
releaseLock(java.lang.String recId,
java.lang.String sessionId)
Release lock held by specified sesssion
|
void |
sessionCreated(javax.servlet.http.HttpSessionEvent se)
Called when a session is created with sole effect of putting the created session into the activeSessions
map.
|
void |
sessionDestroyed(javax.servlet.http.HttpSessionEvent se)
Notified when a session is about to be destroyed - removes the session from the activeSessions map and
unregisteres sessionBean.
|
void |
unregisterSessionBean(java.lang.String sessionId)
Unregister a sessionBean by calling its
destroy
method (releasing all held locks), and removing its entry from the sessionBeanMap. |
public SessionRegistry()
activeSessionsMap map maintains the set of ALL active sessions, and is only modified by sessionCreated(HttpSessionEvent)
and sessionDestroyed(HttpSessionEvent)
listeners.
sessionBeanMap maintains the set of sessionBean instances, which are created only for interactive sessions - which excludes sessions created by webservice requests.
public void contextDestroyed(javax.servlet.ServletContextEvent event)
contextDestroyed
in interface javax.servlet.ServletContextListener
event
- Description of the ParameterunregisterSessionBean(String)
public void contextInitialized(javax.servlet.ServletContextEvent event)
contextInitialized
in interface javax.servlet.ServletContextListener
event
- Description of the Parameterpublic java.util.Map getLockedRecords()
public void sessionCreated(javax.servlet.http.HttpSessionEvent se)
sessionCreated
in interface javax.servlet.http.HttpSessionListener
se
- notification eventpublic void sessionDestroyed(javax.servlet.http.HttpSessionEvent se)
sessionDestroyed
in interface javax.servlet.http.HttpSessionListener
se
- notification eventunregisterSessionBean(String)
public boolean isLocked(java.lang.String recId)
recId
- Description of the Parameterpublic boolean ownsLock(java.lang.String recId, java.lang.String sessionId)
recId
- Description of the ParametersessionId
- Id of given sessionpublic java.util.List myLockedRecords(java.lang.String sessionId)
sessionId
- Description of the Parameterpublic void releaseAllLocks()
public void releaseAllLocks(java.lang.String sessionId)
sessionId
- Id of session that is releasing records.public boolean getLock(java.lang.String recId, java.lang.String sessionId)
recId
- Description of the ParametersessionId
- Description of the Parameterpublic boolean getUniqueLock(java.lang.String recId, java.lang.String sessionId)
recId
- Description of the ParametersessionId
- Description of the Parameterpublic boolean releaseLock(java.lang.String recId)
recId
- Description of the Parameterpublic boolean releaseLock(java.lang.String recId, java.lang.String sessionId)
recId
- Description of the ParametersessionId
- Description of the Parameterpublic void registerSessionBean(SessionBean sessionBean)
sessionBean
- Description of the Parameterpublic void unregisterSessionBean(java.lang.String sessionId)
destroy
method (releasing all held locks), and removing its entry from the sessionBeanMap.sessionId
- Description of the Parameterpublic javax.servlet.http.HttpSession getSession(java.lang.String id)
id
- session idpublic SessionBean getSessionBean(javax.servlet.http.HttpServletRequest 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.
request
- A request instance that is associated with a sessionpublic java.util.List getUserSessionBeans(User user)
public java.util.List getSessionBeans()
Unregisters sessionBeans corresponding to sessions that have been invalidated.
SessionBean
public void destroy()