📄 replicationvalve.java
字号:
/* * Copyright 1999,2004-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.catalina.ha.tcp;import java.io.IOException;import java.util.StringTokenizer;import java.util.regex.Pattern;import java.util.ArrayList;import java.util.List;import java.util.Iterator;import javax.servlet.ServletException;import org.apache.catalina.Manager;import org.apache.catalina.Session;import org.apache.catalina.Context;import org.apache.catalina.core.StandardContext;import org.apache.catalina.ha.CatalinaCluster;import org.apache.catalina.ha.ClusterManager;import org.apache.catalina.ha.ClusterMessage;import org.apache.catalina.ha.ClusterSession;import org.apache.catalina.ha.ClusterValve;import org.apache.catalina.ha.session.DeltaManager;import org.apache.catalina.ha.session.DeltaSession;import org.apache.catalina.connector.Request;import org.apache.catalina.connector.Response;import org.apache.catalina.util.StringManager;import org.apache.catalina.valves.ValveBase;/** * <p>Implementation of a Valve that logs interesting contents from the * specified Request (before processing) and the corresponding Response * (after processing). It is especially useful in debugging problems * related to headers and cookies.</p> * * <p>This Valve may be attached to any Container, depending on the granularity * of the logging you wish to perform.</p> * * <p>primaryIndicator=true, then the request attribute <i>org.apache.catalina.ha.tcp.isPrimarySession.</i> * is set true, when request processing is at sessions primary node. * </p> * * @author Craig R. McClanahan * @author Filip Hanik * @author Peter Rossbach * @version $Revision: 375709 $ $Date: 2006-02-07 15:13:25 -0600 (Tue, 07 Feb 2006) $ */public class ReplicationValve extends ValveBase implements ClusterValve { private static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog( ReplicationValve.class ); // ----------------------------------------------------- Instance Variables /** * The descriptive information related to this implementation. */ private static final String info = "org.apache.catalina.ha.tcp.ReplicationValve/2.0"; /** * The StringManager for this package. */ protected static StringManager sm = StringManager.getManager(Constants.Package); private CatalinaCluster cluster = null ; /** * holds file endings to not call for like images and others */ protected java.util.regex.Pattern[] reqFilters = new java.util.regex.Pattern[0]; /** * Orginal filter */ protected String filter ; /** * crossContext session container */ protected ThreadLocal crossContextSessions = new ThreadLocal() ; /** * doProcessingStats (default = off) */ protected boolean doProcessingStats = false; protected long totalRequestTime = 0; protected long totalSendTime = 0; protected long nrOfRequests = 0; protected long lastSendTime = 0; protected long nrOfFilterRequests = 0; protected long nrOfSendRequests = 0; protected long nrOfCrossContextSendRequests = 0; /** * must primary change indicator set */ protected boolean primaryIndicator = false ; /** * Name of primary change indicator as request attribute */ protected String primaryIndicatorName = "org.apache.catalina.ha.tcp.isPrimarySession"; // ------------------------------------------------------------- Properties public ReplicationValve() { } /** * Return descriptive information about this Valve implementation. */ public String getInfo() { return (info); } /** * @return Returns the cluster. */ public CatalinaCluster getCluster() { return cluster; } /** * @param cluster The cluster to set. */ public void setCluster(CatalinaCluster cluster) { this.cluster = cluster; } /** * @return Returns the filter */ public String getFilter() { return filter ; } /** * compile filter string to regular expressions * @see Pattern#compile(java.lang.String) * @param filter * The filter to set. */ public void setFilter(String filter) { if (log.isDebugEnabled()) log.debug(sm.getString("ReplicationValve.filter.loading", filter)); this.filter = filter; StringTokenizer t = new StringTokenizer(filter, ";"); this.reqFilters = new Pattern[t.countTokens()]; int i = 0; while (t.hasMoreTokens()) { String s = t.nextToken(); if (log.isTraceEnabled()) log.trace(sm.getString("ReplicationValve.filter.token", s)); try { reqFilters[i++] = Pattern.compile(s); } catch (Exception x) { log.error(sm.getString("ReplicationValve.filter.token.failure", s), x); } } } /** * @return Returns the primaryIndicator. */ public boolean isPrimaryIndicator() { return primaryIndicator; } /** * @param primaryIndicator The primaryIndicator to set. */ public void setPrimaryIndicator(boolean primaryIndicator) { this.primaryIndicator = primaryIndicator; } /** * @return Returns the primaryIndicatorName. */ public String getPrimaryIndicatorName() { return primaryIndicatorName; } /** * @param primaryIndicatorName The primaryIndicatorName to set. */ public void setPrimaryIndicatorName(String primaryIndicatorName) { this.primaryIndicatorName = primaryIndicatorName; } /** * Calc processing stats */ public boolean isDoProcessingStats() { return doProcessingStats; } /** * Set Calc processing stats * @see #resetStatistics() */ public void setDoProcessingStats(boolean doProcessingStats) { this.doProcessingStats = doProcessingStats; } /** * @return Returns the lastSendTime. */ public long getLastSendTime() { return lastSendTime; } /** * @return Returns the nrOfRequests. */ public long getNrOfRequests() { return nrOfRequests; } /** * @return Returns the nrOfFilterRequests. */ public long getNrOfFilterRequests() { return nrOfFilterRequests; } /** * @return Returns the nrOfCrossContextSendRequests. */ public long getNrOfCrossContextSendRequests() { return nrOfCrossContextSendRequests; } /** * @return Returns the nrOfSendRequests. */ public long getNrOfSendRequests() { return nrOfSendRequests; } /** * @return Returns the totalRequestTime. */ public long getTotalRequestTime() { return totalRequestTime; } /** * @return Returns the totalSendTime. */ public long getTotalSendTime() { return totalSendTime; } /** * @return Returns the reqFilters. */ protected java.util.regex.Pattern[] getReqFilters() { return reqFilters; } /** * @param reqFilters The reqFilters to set. */ protected void setReqFilters(java.util.regex.Pattern[] reqFilters) { this.reqFilters = reqFilters; } // --------------------------------------------------------- Public Methods /** * Register all cross context sessions inside endAccess. * Use a list with contains check, that the Portlet API can include a lot of fragments from same or * different applications with session changes. * * @param session cross context session */ public void registerReplicationSession(DeltaSession session) { List sessions = (List)crossContextSessions.get(); if(sessions != null) { if(!sessions.contains(session)) { if(log.isDebugEnabled()) log.debug(sm.getString("ReplicationValve.crossContext.registerSession", session.getIdInternal(), session.getManager().getContainer().getName())); sessions.add(session); } } } /** * 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 */ public void invoke(Request request, Response response) throws IOException, ServletException { long totalstart = 0; //this happens before the request if(isDoProcessingStats()) { totalstart = System.currentTimeMillis();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -