Search in sources :

Example 16 with ClusterManager

use of org.apache.catalina.ha.ClusterManager 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

ClusterManager (org.apache.catalina.ha.ClusterManager)16 Map (java.util.Map)2 Context (org.apache.catalina.Context)2 LifecycleException (org.apache.catalina.LifecycleException)2 StandardContext (org.apache.catalina.core.StandardContext)2 CatalinaCluster (org.apache.catalina.ha.CatalinaCluster)2 DeltaManager (org.apache.catalina.ha.session.DeltaManager)2 ObjectInputStream (java.io.ObjectInputStream)1 ArrayList (java.util.ArrayList)1 LifecycleListener (org.apache.catalina.LifecycleListener)1 Valve (org.apache.catalina.Valve)1 ClusterDeployer (org.apache.catalina.ha.ClusterDeployer)1 ClusterListener (org.apache.catalina.ha.ClusterListener)1 ClusterMessage (org.apache.catalina.ha.ClusterMessage)1 DeltaSession (org.apache.catalina.ha.session.DeltaSession)1 SimpleTcpCluster (org.apache.catalina.ha.tcp.SimpleTcpCluster)1 Channel (org.apache.catalina.tribes.Channel)1 ReplicationStream (org.apache.catalina.tribes.io.ReplicationStream)1