use of org.apache.catalina.Session in project tomcat by apache.
the class ManagerBase method getSessionAttribute.
/**
* For debugging.
*
* @param sessionId The ID for the session of interest
* @param key The key for the attribute to obtain
*
* @return The attribute value for the specified session, if found, null
* otherwise
*/
public String getSessionAttribute(String sessionId, String key) {
Session s = sessions.get(sessionId);
if (s == null) {
if (log.isInfoEnabled()) {
log.info(sm.getString("managerBase.sessionNotFound", sessionId));
}
return null;
}
Object o = s.getSession().getAttribute(key);
if (o == null) {
return null;
}
return o.toString();
}
use of org.apache.catalina.Session in project tomcat by apache.
the class PersistentManagerBase method processExpires.
/**
* {@inheritDoc}
* <p>
* Direct call to processExpires and processPersistenceChecks
*/
@Override
public void processExpires() {
long timeNow = System.currentTimeMillis();
Session[] sessions = findSessions();
int expireHere = 0;
if (log.isDebugEnabled()) {
log.debug("Start expire sessions " + getName() + " at " + timeNow + " sessioncount " + sessions.length);
}
for (Session session : sessions) {
if (!session.isValid()) {
expiredSessions.incrementAndGet();
expireHere++;
}
}
processPersistenceChecks();
if (getStore() instanceof StoreBase) {
((StoreBase) getStore()).processExpires();
}
long timeEnd = System.currentTimeMillis();
if (log.isDebugEnabled()) {
log.debug("End expire sessions " + getName() + " processingTime " + (timeEnd - timeNow) + " expired sessions: " + expireHere);
}
processingTime += (timeEnd - timeNow);
}
use of org.apache.catalina.Session in project tomcat by apache.
the class PersistentManagerBase method stopInternal.
/**
* Stop this component and implement the requirements
* of {@link org.apache.catalina.util.LifecycleBase#stopInternal()}.
*
* @exception LifecycleException if this component detects a fatal error
* that prevents this component from being used
*/
@Override
protected synchronized void stopInternal() throws LifecycleException {
if (log.isDebugEnabled()) {
log.debug("Stopping");
}
setState(LifecycleState.STOPPING);
if (getStore() != null && saveOnRestart) {
unload();
} else {
// Expire all active sessions
Session[] sessions = findSessions();
for (Session value : sessions) {
StandardSession session = (StandardSession) value;
if (!session.isValid()) {
continue;
}
session.expire();
}
}
if (getStore() instanceof Lifecycle) {
((Lifecycle) getStore()).stop();
}
// Require a new random number generator if we are restarted
super.stopInternal();
}
use of org.apache.catalina.Session in project tomcat by apache.
the class PersistentManagerBase method findSession.
/**
* {@inheritDoc}
* <p>
* This method checks the persistence store if persistence is enabled,
* otherwise just uses the functionality from ManagerBase.
*/
@Override
public Session findSession(String id) throws IOException {
Session session = super.findSession(id);
// safely.
if (session != null) {
synchronized (session) {
session = super.findSession(session.getIdInternal());
if (session != null) {
// To keep any external calling code from messing up the
// concurrency.
session.access();
session.endAccess();
}
}
}
if (session != null) {
return session;
}
// See if the Session is in the Store
session = swapIn(id);
return session;
}
use of org.apache.catalina.Session in project tomcat by apache.
the class PersistentManagerBase method unload.
/**
* Save all currently active sessions in the appropriate persistence
* mechanism, if any. If persistence is not supported, this method
* returns without doing anything.
* <p>
* Note that by default, this method is not called by the MiddleManager
* class. In order to use it, a subclass must specifically call it,
* for example in the stop() and/or processPersistenceChecks() methods.
*/
@Override
public void unload() {
if (store == null) {
return;
}
Session[] sessions = findSessions();
int n = sessions.length;
if (n == 0) {
return;
}
if (log.isDebugEnabled()) {
log.debug(sm.getString("persistentManager.unloading", String.valueOf(n)));
}
for (Session session : sessions) {
try {
swapOut(session);
} catch (IOException e) {
// This is logged in writeSession()
}
}
}
Aggregations