Search in sources :

Example 1 with DeltaSession

use of org.apache.catalina.ha.session.DeltaSession in project tomcat70 by apache.

the class ReplicationValve method resetReplicationRequest.

/**
 * Fix memory leak for long sessions with many changes, when no backup member exists!
 * @param request current request after response is generated
 * @param isCrossContext check crosscontext threadlocal
 */
protected void resetReplicationRequest(Request request, boolean isCrossContext) {
    Session contextSession = request.getSessionInternal(false);
    if (contextSession instanceof DeltaSession) {
        resetDeltaRequest(contextSession);
        ((DeltaSession) contextSession).setPrimarySession(true);
    }
    if (isCrossContext) {
        List<DeltaSession> sessions = crossContextSessions.get();
        if (sessions != null && sessions.size() > 0) {
            Iterator<DeltaSession> iter = sessions.iterator();
            for (; iter.hasNext(); ) {
                Session session = iter.next();
                resetDeltaRequest(session);
                if (session instanceof DeltaSession)
                    ((DeltaSession) contextSession).setPrimarySession(true);
            }
        }
    }
}
Also used : DeltaSession(org.apache.catalina.ha.session.DeltaSession) Session(org.apache.catalina.Session) ClusterSession(org.apache.catalina.ha.ClusterSession) DeltaSession(org.apache.catalina.ha.session.DeltaSession)

Example 2 with DeltaSession

use of org.apache.catalina.ha.session.DeltaSession in project tomcat70 by apache.

the class ReplicationValve method sendCrossContextSession.

/**
 * Send all changed cross context sessions to backups
 * @param containerCluster
 */
protected void sendCrossContextSession(CatalinaCluster containerCluster) {
    List<DeltaSession> sessions = crossContextSessions.get();
    if (sessions != null && sessions.size() > 0) {
        for (Iterator<DeltaSession> iter = sessions.iterator(); iter.hasNext(); ) {
            Session session = iter.next();
            if (log.isDebugEnabled())
                log.debug(sm.getString("ReplicationValve.crossContext.sendDelta", session.getManager().getContainer().getName()));
            sendMessage(session, (ClusterManager) session.getManager(), containerCluster);
            if (doStatistics()) {
                nrOfCrossContextSendRequests++;
            }
        }
    }
}
Also used : DeltaSession(org.apache.catalina.ha.session.DeltaSession) Session(org.apache.catalina.Session) ClusterSession(org.apache.catalina.ha.ClusterSession) DeltaSession(org.apache.catalina.ha.session.DeltaSession)

Example 3 with DeltaSession

use of org.apache.catalina.ha.session.DeltaSession in project tomcat by apache.

the class ReplicationValve method resetReplicationRequest.

/**
 * Fix memory leak for long sessions with many changes, when no backup member exists!
 * @param request current request after response is generated
 * @param isCrossContext check crosscontext threadlocal
 */
protected void resetReplicationRequest(Request request, boolean isCrossContext) {
    Session contextSession = request.getSessionInternal(false);
    if (contextSession instanceof DeltaSession) {
        resetDeltaRequest(contextSession);
        ((DeltaSession) contextSession).setPrimarySession(true);
    }
    if (isCrossContext) {
        List<DeltaSession> sessions = crossContextSessions.get();
        if (sessions != null && sessions.size() > 0) {
            Iterator<DeltaSession> iter = sessions.iterator();
            for (; iter.hasNext(); ) {
                Session session = iter.next();
                resetDeltaRequest(session);
                if (session instanceof DeltaSession) {
                    ((DeltaSession) contextSession).setPrimarySession(true);
                }
            }
        }
    }
}
Also used : DeltaSession(org.apache.catalina.ha.session.DeltaSession) ClusterSession(org.apache.catalina.ha.ClusterSession) Session(org.apache.catalina.Session) DeltaSession(org.apache.catalina.ha.session.DeltaSession)

Example 4 with DeltaSession

use of org.apache.catalina.ha.session.DeltaSession in project tomcat by apache.

the class ReplicationValve method sendCrossContextSession.

/**
     * Send all changed cross context sessions to backups
     */
protected void sendCrossContextSession() {
    List<DeltaSession> sessions = crossContextSessions.get();
    if (sessions != null && sessions.size() > 0) {
        for (Iterator<DeltaSession> iter = sessions.iterator(); iter.hasNext(); ) {
            Session session = iter.next();
            if (log.isDebugEnabled()) {
                log.debug(sm.getString("ReplicationValve.crossContext.sendDelta", session.getManager().getContext().getName()));
            }
            sendMessage(session, (ClusterManager) session.getManager());
            if (doStatistics()) {
                nrOfCrossContextSendRequests++;
            }
        }
    }
}
Also used : DeltaSession(org.apache.catalina.ha.session.DeltaSession) ClusterSession(org.apache.catalina.ha.ClusterSession) Session(org.apache.catalina.Session) DeltaSession(org.apache.catalina.ha.session.DeltaSession)

Example 5 with DeltaSession

use of org.apache.catalina.ha.session.DeltaSession in project tomcat70 by apache.

the class ReplicationValve method invoke.

/**
 * Log the interesting request parameters, invoke the next Valve in the
 * sequence, and log the interesting response parameters.
 *
 * @param request The servlet request to be processed
 * @param response The servlet response to be created
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet error occurs
 */
@Override
public void invoke(Request request, Response response) throws IOException, ServletException {
    long totalstart = 0;
    // this happens before the request
    if (doStatistics()) {
        totalstart = System.currentTimeMillis();
    }
    if (primaryIndicator) {
        createPrimaryIndicator(request);
    }
    Context context = request.getContext();
    boolean isCrossContext = context != null && context instanceof StandardContext && ((StandardContext) context).getCrossContext();
    try {
        if (isCrossContext) {
            if (log.isDebugEnabled())
                log.debug(sm.getString("ReplicationValve.crossContext.add"));
            // FIXME add Pool of Arraylists
            crossContextSessions.set(new ArrayList<DeltaSession>());
        }
        getNext().invoke(request, response);
        if (context != null && cluster != null && context.getManager() instanceof ClusterManager) {
            ClusterManager clusterManager = (ClusterManager) context.getManager();
            // at host level - hopefully!
            if (cluster.getManager(clusterManager.getName()) == null)
                return;
            if (cluster.hasMembers()) {
                sendReplicationMessage(request, totalstart, isCrossContext, clusterManager, cluster);
            } else {
                resetReplicationRequest(request, isCrossContext);
            }
        }
    } finally {
        // Don't register this request session again!
        if (isCrossContext) {
            if (log.isDebugEnabled())
                log.debug(sm.getString("ReplicationValve.crossContext.remove"));
            // crossContextSessions.remove() only exist at Java 5
            // register ArrayList at a pool
            crossContextSessions.set(null);
        }
    }
}
Also used : Context(org.apache.catalina.Context) StandardContext(org.apache.catalina.core.StandardContext) StandardContext(org.apache.catalina.core.StandardContext) DeltaSession(org.apache.catalina.ha.session.DeltaSession) ClusterManager(org.apache.catalina.ha.ClusterManager)

Aggregations

DeltaSession (org.apache.catalina.ha.session.DeltaSession)5 Session (org.apache.catalina.Session)4 ClusterSession (org.apache.catalina.ha.ClusterSession)4 Context (org.apache.catalina.Context)1 StandardContext (org.apache.catalina.core.StandardContext)1 ClusterManager (org.apache.catalina.ha.ClusterManager)1