Class ReplicationValve

  • All Implemented Interfaces:
    javax.management.MBeanRegistration, Contained, ClusterValve, JmxEnabled, Lifecycle, Valve

    public class ReplicationValve
    extends ValveBase
    implements ClusterValve

    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.

    This Valve may be attached to any Container, depending on the granularity of the logging you wish to perform.

    primaryIndicator=true, then the request attribute org.apache.catalina.ha.tcp.isPrimarySession. is set true, when request processing is at sessions primary node.

    Author:
    Craig R. McClanahan, Peter Rossbach
    • Field Detail

      • sm

        protected static final StringManager sm
        The StringManager for this package.
      • filter

        protected java.util.regex.Pattern filter
        Filter expression
      • crossContextSessions

        protected final java.lang.ThreadLocal<java.util.ArrayList<DeltaSession>> crossContextSessions
        crossContext session container
      • doProcessingStats

        protected boolean doProcessingStats
        doProcessingStats (default = off)
      • totalRequestTime

        protected volatile long totalRequestTime
      • totalSendTime

        protected volatile long totalSendTime
      • nrOfRequests

        protected volatile long nrOfRequests
      • lastSendTime

        protected volatile long lastSendTime
      • nrOfFilterRequests

        protected volatile long nrOfFilterRequests
      • nrOfSendRequests

        protected volatile long nrOfSendRequests
      • nrOfCrossContextSendRequests

        protected volatile long nrOfCrossContextSendRequests
      • primaryIndicator

        protected boolean primaryIndicator
        must primary change indicator set
      • primaryIndicatorName

        protected java.lang.String primaryIndicatorName
        Name of primary change indicator as request attribute
    • Constructor Detail

      • ReplicationValve

        public ReplicationValve()
    • Method Detail

      • setCluster

        public void setCluster​(CatalinaCluster cluster)
        Description copied from interface: ClusterValve
        Associates the cluster deployer with a cluster
        Specified by:
        setCluster in interface ClusterValve
        Parameters:
        cluster - The cluster to set.
      • getFilter

        public java.lang.String getFilter()
        Returns:
        the filter
      • setFilter

        public void setFilter​(java.lang.String filter)
        compile filter string to regular expression
        Parameters:
        filter - The filter to set.
        See Also:
        Pattern.compile(java.lang.String)
      • isPrimaryIndicator

        public boolean isPrimaryIndicator()
        Returns:
        the primaryIndicator.
      • setPrimaryIndicator

        public void setPrimaryIndicator​(boolean primaryIndicator)
        Parameters:
        primaryIndicator - The primaryIndicator to set.
      • getPrimaryIndicatorName

        public java.lang.String getPrimaryIndicatorName()
        Returns:
        the primaryIndicatorName.
      • setPrimaryIndicatorName

        public void setPrimaryIndicatorName​(java.lang.String primaryIndicatorName)
        Parameters:
        primaryIndicatorName - The primaryIndicatorName to set.
      • doStatistics

        public boolean doStatistics()
        Calc processing stats
        Returns:
        true if statistics are enabled
      • setStatistics

        public void setStatistics​(boolean doProcessingStats)
        Set Calc processing stats
        Parameters:
        doProcessingStats - New flag value
        See Also:
        resetStatistics()
      • getLastSendTime

        public long getLastSendTime()
        Returns:
        the lastSendTime.
      • getNrOfRequests

        public long getNrOfRequests()
        Returns:
        the nrOfRequests.
      • getNrOfFilterRequests

        public long getNrOfFilterRequests()
        Returns:
        the nrOfFilterRequests.
      • getNrOfCrossContextSendRequests

        public long getNrOfCrossContextSendRequests()
        Returns:
        the nrOfCrossContextSendRequests.
      • getNrOfSendRequests

        public long getNrOfSendRequests()
        Returns:
        the nrOfSendRequests.
      • getTotalRequestTime

        public long getTotalRequestTime()
        Returns:
        the totalRequestTime.
      • getTotalSendTime

        public long getTotalSendTime()
        Returns:
        the totalSendTime.
      • registerReplicationSession

        public void registerReplicationSession​(DeltaSession session)
        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.
        Parameters:
        session - cross context session
      • invoke

        public void invoke​(Request request,
                           Response response)
                    throws java.io.IOException,
                           ServletException
        Log the interesting request parameters, invoke the next Valve in the sequence, and log the interesting response parameters.
        Specified by:
        invoke in interface Valve
        Parameters:
        request - The servlet request to be processed
        response - The servlet response to be created
        Throws:
        java.io.IOException - if an input/output error occurs
        ServletException - if a servlet error occurs
      • resetStatistics

        public void resetStatistics()
        reset the active statistics
      • sendReplicationMessage

        protected void sendReplicationMessage​(Request request,
                                              long totalstart,
                                              boolean isCrossContext,
                                              ClusterManager clusterManager)
      • sendCrossContextSession

        protected void sendCrossContextSession()
        Send all changed cross context sessions to backups
      • resetReplicationRequest

        protected void resetReplicationRequest​(Request request,
                                               boolean isCrossContext)
        Fix memory leak for long sessions with many changes, when no backup member exists!
        Parameters:
        request - current request after response is generated
        isCrossContext - check crosscontext threadlocal
      • resetDeltaRequest

        protected void resetDeltaRequest​(Session session)
        Reset DeltaRequest from session
        Parameters:
        session - HttpSession from current request or cross context session
      • sendSessionReplicationMessage

        protected void sendSessionReplicationMessage​(Request request,
                                                     ClusterManager manager)
        Send Cluster Replication Request
        Parameters:
        request - current request
        manager - session manager
      • sendMessage

        protected void sendMessage​(Session session,
                                   ClusterManager manager)
        Send message delta message from request session
        Parameters:
        session - current session
        manager - session manager
      • sendInvalidSessions

        protected void sendInvalidSessions​(ClusterManager manager)
        check for session invalidations
        Parameters:
        manager - Associated manager
      • isRequestWithoutSessionChange

        protected boolean isRequestWithoutSessionChange​(java.lang.String uri)
        is request without possible session change
        Parameters:
        uri - The request uri
        Returns:
        True if no session change
      • updateStats

        protected void updateStats​(long requestTime,
                                   long clusterTime)
        Protocol cluster replications stats
        Parameters:
        requestTime - Request time
        clusterTime - Cluster time
      • createPrimaryIndicator

        protected void createPrimaryIndicator​(Request request)
                                       throws java.io.IOException
        Mark Request that processed at primary node with attribute primaryIndicatorName
        Parameters:
        request - The Servlet request
        Throws:
        java.io.IOException - IO error finding session