* @return the cached session.
*
*/
public SessionArrayValue getSession(Env env, String key, long now)
{
SessionArrayValue session;
boolean isNew = false;
boolean killSession = false;
if (_sessions == null)
return null;
// Check the cache first
session = _sessions.get(key);
if (session != null && ! session.getId().equals(key))
throw new IllegalStateException(key + " != " + session.getId());
if (session != null) {
if (session.inUse()) {
return (SessionArrayValue)session.copy(env);
}
}
if (session == null)
return null;
if (isNew) {
isNew = ! load(env, session, now);
}
else if (! getSaveOnlyOnShutdown() && ! session.load()) {
// if the load failed, then the session died out from underneath
session.reset(now);
isNew = true;
}
if (! isNew)
session.setAccess(now);
return (SessionArrayValue)session.copy(env);
}