Apache Tomcat 7.0.28

org.apache.catalina.ha.tcp
Class ReplicationValve

java.lang.Object
  extended by org.apache.catalina.util.LifecycleBase
      extended by org.apache.catalina.util.LifecycleMBeanBase
          extended by org.apache.catalina.valves.ValveBase
              extended by org.apache.catalina.ha.tcp.ReplicationValve
All Implemented Interfaces:
MBeanRegistration, Contained, ClusterValve, 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.

Version:
$Id: ReplicationValve.java 1133197 2011-06-07 23:37:29Z markt $
Author:
Craig R. McClanahan, Filip Hanik, Peter Rossbach

Field Summary
protected  ThreadLocal<ArrayList<DeltaSession>> crossContextSessions
          crossContext session container
protected  boolean doProcessingStats
          doProcessingStats (default = off)
protected  Pattern filter
          Filter expression
protected  long lastSendTime
           
protected  long nrOfCrossContextSendRequests
           
protected  long nrOfFilterRequests
           
protected  long nrOfRequests
           
protected  long nrOfSendRequests
           
protected  boolean primaryIndicator
          must primary change indicator set
protected  String primaryIndicatorName
          Name of primary change indicator as request attribute
protected static StringManager sm
          The StringManager for this package.
protected  long totalRequestTime
           
protected  long totalSendTime
           
 
Fields inherited from class org.apache.catalina.valves.ValveBase
asyncSupported, container, containerLog, next
 
Fields inherited from class org.apache.catalina.util.LifecycleMBeanBase
mserver
 
Fields inherited from interface org.apache.catalina.Lifecycle
AFTER_DESTROY_EVENT, AFTER_INIT_EVENT, AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_DESTROY_EVENT, BEFORE_INIT_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, CONFIGURE_START_EVENT, CONFIGURE_STOP_EVENT, PERIODIC_EVENT, START_EVENT, STOP_EVENT
 
Constructor Summary
ReplicationValve()
           
 
Method Summary
protected  void createPrimaryIndicator(Request request)
          Mark Request that processed at primary node with attribute primaryIndicatorName
 boolean doStatistics()
          Calc processing stats
 CatalinaCluster getCluster()
          Returns the cluster the cluster deployer is associated with
 String getFilter()
           
 String getInfo()
          Return descriptive information about this Valve implementation.
 long getLastSendTime()
           
 long getNrOfCrossContextSendRequests()
           
 long getNrOfFilterRequests()
           
 long getNrOfRequests()
           
 long getNrOfSendRequests()
           
 String getPrimaryIndicatorName()
           
 long getTotalRequestTime()
           
 long getTotalSendTime()
           
 void invoke(Request request, Response response)
          Log the interesting request parameters, invoke the next Valve in the sequence, and log the interesting response parameters.
 boolean isPrimaryIndicator()
           
protected  boolean isRequestWithoutSessionChange(String uri)
          is request without possible session change
 void registerReplicationSession(DeltaSession session)
          Register all cross context sessions inside endAccess.
protected  void resetDeltaRequest(Session session)
          Reset DeltaRequest from session
protected  void resetReplicationRequest(Request request, boolean isCrossContext)
          Fix memory leak for long sessions with many changes, when no backup member exists!
 void resetStatistics()
          reset the active statistics
protected  void send(ClusterManager manager, CatalinaCluster cluster, String sessionId)
          send manager requestCompleted message to cluster
protected  void sendCrossContextSession(CatalinaCluster containerCluster)
          Send all changed cross context sessions to backups
protected  void sendInvalidSessions(ClusterManager manager, CatalinaCluster cluster)
          check for session invalidations
protected  void sendMessage(Session session, ClusterManager manager, CatalinaCluster cluster)
          Send message delta message from request session
protected  void sendReplicationMessage(Request request, long totalstart, boolean isCrossContext, ClusterManager clusterManager, CatalinaCluster containerCluster)
           
protected  void sendSessionReplicationMessage(Request request, ClusterManager manager, CatalinaCluster cluster)
          Send Cluster Replication Request
 void setCluster(CatalinaCluster cluster)
          Associates the cluster deployer with a cluster
 void setFilter(String filter)
          compile filter string to regular expression
 void setPrimaryIndicator(boolean primaryIndicator)
           
 void setPrimaryIndicatorName(String primaryIndicatorName)
           
 void setStatistics(boolean doProcessingStats)
          Set Calc processing stats
protected  void updateStats(long requestTime, long clusterTime)
          Protocol cluster replications stats
 
Methods inherited from class org.apache.catalina.valves.ValveBase
backgroundProcess, event, getContainer, getDomainInternal, getNext, getObjectNameKeyProperties, initInternal, isAsyncSupported, setAsyncSupported, setContainer, setNext, startInternal, stopInternal, toString
 
Methods inherited from class org.apache.catalina.util.LifecycleMBeanBase
destroyInternal, getDomain, getObjectName, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister
 
Methods inherited from class org.apache.catalina.util.LifecycleBase
addLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, init, removeLifecycleListener, setState, setState, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.catalina.Valve
backgroundProcess, event, getNext, isAsyncSupported, setNext
 

Field Detail

sm

protected static final StringManager sm
The StringManager for this package.


filter

protected Pattern filter
Filter expression


crossContextSessions

protected ThreadLocal<ArrayList<DeltaSession>> crossContextSessions
crossContext session container


doProcessingStats

protected boolean doProcessingStats
doProcessingStats (default = off)


totalRequestTime

protected long totalRequestTime

totalSendTime

protected long totalSendTime

nrOfRequests

protected long nrOfRequests

lastSendTime

protected long lastSendTime

nrOfFilterRequests

protected long nrOfFilterRequests

nrOfSendRequests

protected long nrOfSendRequests

nrOfCrossContextSendRequests

protected long nrOfCrossContextSendRequests

primaryIndicator

protected boolean primaryIndicator
must primary change indicator set


primaryIndicatorName

protected String primaryIndicatorName
Name of primary change indicator as request attribute

Constructor Detail

ReplicationValve

public ReplicationValve()
Method Detail

getInfo

public String getInfo()
Return descriptive information about this Valve implementation.

Specified by:
getInfo in interface Valve
Overrides:
getInfo in class ValveBase

getCluster

public CatalinaCluster getCluster()
Description copied from interface: ClusterValve
Returns the cluster the cluster deployer is associated with

Specified by:
getCluster in interface ClusterValve
Returns:
Returns 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
Parameters:
cluster - The cluster to set.

getFilter

public String getFilter()
Returns:
Returns the filter

setFilter

public void setFilter(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:
Returns the primaryIndicator.

setPrimaryIndicator

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

getPrimaryIndicatorName

public String getPrimaryIndicatorName()
Returns:
Returns the primaryIndicatorName.

setPrimaryIndicatorName

public void setPrimaryIndicatorName(String primaryIndicatorName)
Parameters:
primaryIndicatorName - The primaryIndicatorName to set.

doStatistics

public boolean doStatistics()
Calc processing stats


setStatistics

public void setStatistics(boolean doProcessingStats)
Set Calc processing stats

See Also:
resetStatistics()

getLastSendTime

public long getLastSendTime()
Returns:
Returns the lastSendTime.

getNrOfRequests

public long getNrOfRequests()
Returns:
Returns the nrOfRequests.

getNrOfFilterRequests

public long getNrOfFilterRequests()
Returns:
Returns the nrOfFilterRequests.

getNrOfCrossContextSendRequests

public long getNrOfCrossContextSendRequests()
Returns:
Returns the nrOfCrossContextSendRequests.

getNrOfSendRequests

public long getNrOfSendRequests()
Returns:
Returns the nrOfSendRequests.

getTotalRequestTime

public long getTotalRequestTime()
Returns:
Returns the totalRequestTime.

getTotalSendTime

public long getTotalSendTime()
Returns:
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 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
Specified by:
invoke in class ValveBase
Parameters:
request - The servlet request to be processed
response - The servlet response to be created
Throws:
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,
                                      CatalinaCluster containerCluster)
Parameters:
request -
totalstart -
isCrossContext -
clusterManager -
containerCluster -

sendCrossContextSession

protected void sendCrossContextSession(CatalinaCluster containerCluster)
Send all changed cross context sessions to backups

Parameters:
containerCluster -

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,
                                             CatalinaCluster cluster)
Send Cluster Replication Request

Parameters:
request - current request
manager - session manager
cluster - replication cluster

sendMessage

protected void sendMessage(Session session,
                           ClusterManager manager,
                           CatalinaCluster cluster)
Send message delta message from request session

Parameters:
session - current session
manager - session manager
cluster - replication cluster

send

protected void send(ClusterManager manager,
                    CatalinaCluster cluster,
                    String sessionId)
send manager requestCompleted message to cluster

Parameters:
manager - SessionManager
cluster - replication cluster
sessionId - sessionid from the manager
See Also:
DeltaManager.requestCompleted(String), SimpleTcpCluster.send(ClusterMessage)

sendInvalidSessions

protected void sendInvalidSessions(ClusterManager manager,
                                   CatalinaCluster cluster)
check for session invalidations

Parameters:
manager -
cluster -

isRequestWithoutSessionChange

protected boolean isRequestWithoutSessionChange(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 -
clusterTime -

createPrimaryIndicator

protected void createPrimaryIndicator(Request request)
                               throws IOException
Mark Request that processed at primary node with attribute primaryIndicatorName

Parameters:
request -
Throws:
IOException

Apache Tomcat 7.0.28

Copyright © 2000-2012 Apache Software Foundation. All Rights Reserved.