Methods Summary |
---|
protected org.apache.catalina.Session | getSession(org.apache.catalina.Request request)get the session associated with this request
ServletRequest servletReq = request.getRequest();
HttpServletRequest httpReq =
(HttpServletRequest) servletReq;
HttpSession httpSess = httpReq.getSession(false);
if(httpSess == null)
//need to null out session
//httpReq.setSession(null);
return null;
String id = httpSess.getId();
if(_logger.isLoggable(Level.FINEST)) {
_logger.finest("SESSION_ID=" + id);
}
Manager mgr = this.getContainer().getManager();
PersistentManagerBase pmb = (PersistentManagerBase)mgr;
Session sess = null;
try {
sess = pmb.findSession(id);
} catch (java.io.IOException ex) {}
if(_logger.isLoggable(Level.FINEST)) {
_logger.finest("RETRIEVED_SESSION=" + sess);
}
return sess;
|
public void | invoke(org.apache.catalina.Request request, org.apache.catalina.Response response)Cause the specified request and response to be processed by the Valves
associated with this pipeline, until one of these valves causes the
response to be created and returned. The implementation must ensure
that multiple simultaneous requests (on different threads) can be
processed through the same Pipeline without interfering with each
other's control flow.
this.lockSession(request);
try {
super.invoke(request, response);
} finally {
this.unlockSession(request);
}
|
protected boolean | lockSession(org.apache.catalina.Request request)lock the session associated with this request
this will be a foreground lock
checks for background lock to clear
and does a decay poll loop to wait until
it is clear; after 5 times it takes control for
the foreground
boolean result = false;
Session sess = this.getSession(request);
if(_logger.isLoggable(Level.FINEST)) {
_logger.finest("IN LOCK_SESSION: sess =" + sess);
}
//now lock the session
if(sess != null) {
long pollTime = 200L;
int maxNumberOfRetries = 7;
int tryNumber = 0;
boolean keepTrying = true;
boolean lockResult = false;
if(_logger.isLoggable(Level.FINEST)) {
_logger.finest("locking session: sess =" + sess);
}
StandardSession haSess = (StandardSession) sess;
//try to lock up to maxNumberOfRetries times
//poll and wait starting with 200 ms
while(keepTrying) {
lockResult = haSess.lockForeground();
if(lockResult) {
keepTrying = false;
result = true;
break;
}
tryNumber++;
if(tryNumber < maxNumberOfRetries) {
pollTime = pollTime * 2L;
threadSleep(pollTime);
} else {
//tried to wait and lock maxNumberOfRetries times; throw an exception
//throw new ServletException("unable to acquire session lock");
//instead of above; unlock the background so we can take over
_logger.warning("this should not happen-breaking background lock: sess =" + sess);
haSess.unlockBackground();
}
}
if(_logger.isLoggable(Level.FINEST)) {
_logger.finest("finished locking session: sess =" + sess);
_logger.finest("LOCK = " + haSess.getSessionLock());
}
}
return result;
|
protected void | threadSleep(long sleepTime)
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
;
}
|
protected void | unlockSession(org.apache.catalina.Request request)unlock the session associated with this request
Session sess = this.getSession(request);
if(_logger.isLoggable(Level.FINEST)) {
_logger.finest("IN UNLOCK_SESSION: sess = " + sess);
}
//now unlock the session
if(sess != null) {
if(_logger.isLoggable(Level.FINEST)) {
_logger.finest("unlocking session: sess =" + sess);
}
StandardSession haSess = (StandardSession) sess;
haSess.unlockForeground();
if(_logger.isLoggable(Level.FINEST)) {
_logger.finest("finished unlocking session: sess =" + sess);
_logger.finest("LOCK = " + haSess.getSessionLock());
}
}
|