Class ReplicationValve

All Implemented Interfaces:
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.

Craig R. McClanahan, Peter Rossbach
  • Field Details

    • sm

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

      protected Pattern filter
      Filter expression
    • crossContextSessions

      protected final ThreadLocal<ArrayList<DeltaSession>> crossContextSessions
      crossContext session container
    • doProcessingStats

      protected boolean doProcessingStats
      doProcessingStats (default = off)
    • totalRequestTime

      protected LongAdder totalRequestTime
    • totalSendTime

      protected LongAdder totalSendTime
    • nrOfRequests

      protected LongAdder nrOfRequests
    • lastSendTime

      protected AtomicLong lastSendTime
    • nrOfFilterRequests

      protected LongAdder nrOfFilterRequests
    • nrOfSendRequests

      protected LongAdder nrOfSendRequests
    • nrOfCrossContextSendRequests

      protected LongAdder nrOfCrossContextSendRequests
    • primaryIndicator

      protected boolean primaryIndicator
      must primary change indicator set
    • primaryIndicatorName

      protected String primaryIndicatorName
      Name of primary change indicator as request attribute
  • Constructor Details

    • ReplicationValve

      public ReplicationValve()
  • Method Details

    • getCluster

      public CatalinaCluster getCluster()
      Description copied from interface: ClusterValve
      Returns the cluster the cluster deployer is associated with
      Specified by:
      getCluster in interface ClusterValve
      the cluster.
    • setCluster

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

      public String getFilter()
      the filter
    • setFilter

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

      public boolean isPrimaryIndicator()
      the primaryIndicator.
    • setPrimaryIndicator

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

      public String getPrimaryIndicatorName()
      the primaryIndicatorName.
    • setPrimaryIndicatorName

      public void setPrimaryIndicatorName(String primaryIndicatorName)
      primaryIndicatorName - The primaryIndicatorName to set.
    • doStatistics

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

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

      public long getLastSendTime()
      the lastSendTime.
    • getNrOfRequests

      public long getNrOfRequests()
      the nrOfRequests.
    • getNrOfFilterRequests

      public long getNrOfFilterRequests()
      the nrOfFilterRequests.
    • getNrOfCrossContextSendRequests

      public long getNrOfCrossContextSendRequests()
      the nrOfCrossContextSendRequests.
    • getNrOfSendRequests

      public long getNrOfSendRequests()
      the nrOfSendRequests.
    • getTotalRequestTime

      public long getTotalRequestTime()
      the totalRequestTime.
    • getTotalSendTime

      public long getTotalSendTime()
      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.
      session - cross context session
    • invoke

      public void invoke(Request request, Response response) throws IOException, ServletException
      Description copied from interface: Valve

      Perform request processing as required by this Valve.

      An individual Valve MAY perform the following actions, in the specified order:

      • Examine and/or modify the properties of the specified Request and Response.
      • Examine the properties of the specified Request, completely generate the corresponding Response, and return control to the caller.
      • Examine the properties of the specified Request and Response, wrap either or both of these objects to supplement their functionality, and pass them on.
      • If the corresponding Response was not generated (and control was not returned, call the next Valve in the pipeline (if there is one) by executing getNext().invoke().
      • Examine, but not modify, the properties of the resulting Response (which was created by a subsequently invoked Valve or Container).

      A Valve MUST NOT do any of the following things:

      • Change request properties that have already been used to direct the flow of processing control for this request (for instance, trying to change the virtual host to which a Request should be sent from a pipeline attached to a Host or Context in the standard implementation).
      • Create a completed Response AND pass this Request and Response on to the next Valve in the pipeline.
      • Consume bytes from the input stream associated with the Request, unless it is completely generating the response, or wrapping the request before passing it on.
      • Modify the HTTP headers included with the Response after the getNext().invoke() method has returned.
      • Perform any actions on the output stream associated with the specified Response after the getNext().invoke() method has returned.
      Specified by:
      invoke in interface Valve
      request - The servlet request to be processed
      response - The servlet response to be created
      IOException - if an input/output error occurs, or is thrown by a subsequently invoked Valve, Filter, or Servlet
      ServletException - if a servlet error occurs, or is thrown by a subsequently invoked Valve, Filter, or Servlet
    • resetStatistics

      public void resetStatistics()
      reset the active statistics
    • startInternal

      protected void startInternal() throws LifecycleException
      Description copied from class: ValveBase
      Start this component and implement the requirements of LifecycleBase.startInternal().
      startInternal in class ValveBase
      LifecycleException - if this component detects a fatal error that prevents this component from being used
    • sendReplicationMessage

      protected void sendReplicationMessage(Request request, long totalstart, boolean isCrossContext, boolean isAsync, 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!
      request - current request after response is generated
      isCrossContext - check crosscontext threadlocal
    • resetDeltaRequest

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

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

      protected void sendMessage(Session session, ClusterManager manager)
      Send message delta message from request session
      session - current session
      manager - session manager
    • send

      protected void send(ClusterManager manager, String sessionId)
      send manager requestCompleted message to cluster
      manager - SessionManager
      sessionId - sessionid from the manager
      See Also:
    • sendInvalidSessions

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

      protected boolean isRequestWithoutSessionChange(String uri)
      is request without possible session change
      uri - The request uri
      True if no session change
    • updateStats

      protected void updateStats(long requestTime, long clusterTime, boolean isAsync)
      Protocol cluster replications stats
      requestTime - Request time
      clusterTime - Cluster time
      isAsync - if the request was in async mode
    • createPrimaryIndicator

      protected void createPrimaryIndicator(Request request) throws IOException
      Mark Request that processed at primary node with attribute primaryIndicatorName
      request - The Servlet request
      IOException - IO error finding session