Search in sources :

Example 91 with Session

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();
}
Also used : Session(org.apache.catalina.Session)

Example 92 with Session

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);
}
Also used : Session(org.apache.catalina.Session)

Example 93 with Session

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();
}
Also used : Lifecycle(org.apache.catalina.Lifecycle) Session(org.apache.catalina.Session)

Example 94 with Session

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;
}
Also used : Session(org.apache.catalina.Session)

Example 95 with 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()
        }
    }
}
Also used : IOException(java.io.IOException) Session(org.apache.catalina.Session)

Aggregations

Session (org.apache.catalina.Session)106 IOException (java.io.IOException)24 Manager (org.apache.catalina.Manager)22 Context (org.apache.catalina.Context)16 HttpSession (javax.servlet.http.HttpSession)13 StringManager (org.apache.tomcat.util.res.StringManager)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 HttpSession (jakarta.servlet.http.HttpSession)7 GenericPrincipal (org.apache.catalina.realm.GenericPrincipal)7 Principal (java.security.Principal)6 Realm (org.apache.catalina.Realm)6 StandardContext (org.apache.catalina.core.StandardContext)6 ClusterSession (org.apache.catalina.ha.ClusterSession)6 DeltaSession (org.apache.catalina.ha.session.DeltaSession)6 Container (org.apache.catalina.Container)5 ArrayList (java.util.ArrayList)4 StandardSession (org.apache.catalina.session.StandardSession)4 BufferedOutputStream (java.io.BufferedOutputStream)3 File (java.io.File)3 ObjectOutputStream (java.io.ObjectOutputStream)3