Java Simon 3.5.0

org.javasimon.javaee
Class SimonServletFilter

java.lang.Object
  extended by org.javasimon.javaee.SimonServletFilter
All Implemented Interfaces:
javax.servlet.Filter

public class SimonServletFilter
extends Object
implements javax.servlet.Filter

Simon Servlet filter measuring HTTP request execution times. Non-HTTP usages are not supported. Filter provides these functions:

All constants are public and fields protected for easy extension of the class. Following protected methods and classes are provided to override the default function:

Since:
2.3
Author:
Richard "Virgo" Richter

Field Summary
protected  String consolePath
          URL path that displays Simon web console (or null if no console is required).
static String INIT_PARAM_PREFIX
          Name of filter init parameter for Simon name prefix.
static String INIT_PARAM_REPORT_THRESHOLD_MS
          Name of filter init parameter that sets the value of threshold in milliseconds for maximal request duration beyond which all splits will be dumped to log.
static String INIT_PARAM_REQUEST_REPORTER_CLASS
          FQN of the RequestReporter implementation that is used to report requests that shouldBeReported(javax.servlet.http.HttpServletRequest, long, java.util.List).
static String INIT_PARAM_SIMON_CONSOLE_PATH
          Name of filter init parameter that sets relative ULR path that will provide Simon console page.
static String INIT_PARAM_STOPWATCH_SOURCE_CACHE
          Enable/disable caching on Stopwatch resolution.
static String INIT_PARAM_STOPWATCH_SOURCE_CLASS
          FQN of the Stopwatch source class implementing MonitorSource.
static String INIT_PARAM_STOPWATCH_SOURCE_PROPS
          Properties for a StopwatchSource class.
protected  String printTreePath
          URL path that displays Simon tree - it is console-path without the ending slash.
protected  Long reportThresholdNanos
          Threshold in ns - any request longer than this will be reported by current requestReporter instance.
 
Constructor Summary
SimonServletFilter()
           
 
Method Summary
 void destroy()
          Removes the splitSaverCallback if initialized.
 void doFilter(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse, javax.servlet.FilterChain filterChain)
          Wraps the HTTP request with Simon measuring.
 Manager getManager()
           
protected  long getThreshold(javax.servlet.http.HttpServletRequest request)
          Returns actual threshold in *nanoseconds* (not ms as configured) which allows to further customize threshold per request - intended for override.
 void init(javax.servlet.FilterConfig filterConfig)
          Initialization method that processes various init parameters from web.xml and sets manager, if SimonUtils.MANAGER_SERVLET_CTX_ATTRIBUTE servlet context attribute is not null.
protected  boolean shouldBeReported(javax.servlet.http.HttpServletRequest request, long requestNanoTime, List<Split> splits)
          Determines whether the request is over the threshold - with all incoming parameters this method can be very flexible.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INIT_PARAM_PREFIX

public static final String INIT_PARAM_PREFIX
Name of filter init parameter for Simon name prefix.

See Also:
Constant Field Values

INIT_PARAM_REPORT_THRESHOLD_MS

public static final String INIT_PARAM_REPORT_THRESHOLD_MS
Name of filter init parameter that sets the value of threshold in milliseconds for maximal request duration beyond which all splits will be dumped to log. The actual threshold can be further customized overriding getThreshold(javax.servlet.http.HttpServletRequest) method, but this parameter has to be set to non-null value to enable threshold reporting feature (0 for instance).

See Also:
Constant Field Values

INIT_PARAM_SIMON_CONSOLE_PATH

public static final String INIT_PARAM_SIMON_CONSOLE_PATH
Name of filter init parameter that sets relative ULR path that will provide Simon console page. If the parameter is not used, basic plain text console will be disabled.

See Also:
Constant Field Values

INIT_PARAM_STOPWATCH_SOURCE_CLASS

public static final String INIT_PARAM_STOPWATCH_SOURCE_CLASS
FQN of the Stopwatch source class implementing MonitorSource. One can use DisabledMonitorSource to disabled monitoring. Defaults to HttpStopwatchSource.

See Also:
Constant Field Values

INIT_PARAM_STOPWATCH_SOURCE_CACHE

public static final String INIT_PARAM_STOPWATCH_SOURCE_CACHE
Enable/disable caching on Stopwatch resolution. Warning: as the cache key is the HttpServletRequest.getRequestURI(), this is incompatible with application passing data in their request URI, this is often the case of RESTful services. For instance "/car/1023/driver" and "/car/3624/driver" may point to the same page but with different URLs. Defaults to false.

See Also:
Constant Field Values

INIT_PARAM_REQUEST_REPORTER_CLASS

public static final String INIT_PARAM_REQUEST_REPORTER_CLASS
FQN of the RequestReporter implementation that is used to report requests that shouldBeReported(javax.servlet.http.HttpServletRequest, long, java.util.List). Default is DefaultRequestReporter.

See Also:
Constant Field Values

INIT_PARAM_STOPWATCH_SOURCE_PROPS

public static final String INIT_PARAM_STOPWATCH_SOURCE_PROPS
Properties for a StopwatchSource class. Has the following format: prop1=val1;prop2=val2 Properties are assumed to be correct Java bean properties and should exist in a class specified by INIT_PARAM_STOPWATCH_SOURCE_CLASS

See Also:
Constant Field Values

reportThresholdNanos

protected Long reportThresholdNanos
Threshold in ns - any request longer than this will be reported by current requestReporter instance. Specified by INIT_PARAM_REPORT_THRESHOLD_MS ("report-threshold-ms") in the web.xml (in ms, converted to ns during servlet init). This is the default value returned by getThreshold(javax.servlet.http.HttpServletRequest) but it may be completely ignored if method is overridden so. However if the field is null threshold reporting feature is disabled.


printTreePath

protected String printTreePath
URL path that displays Simon tree - it is console-path without the ending slash.


consolePath

protected String consolePath
URL path that displays Simon web console (or null if no console is required).

Constructor Detail

SimonServletFilter

public SimonServletFilter()
Method Detail

init

public final void init(javax.servlet.FilterConfig filterConfig)
Initialization method that processes various init parameters from web.xml and sets manager, if SimonUtils.MANAGER_SERVLET_CTX_ATTRIBUTE servlet context attribute is not null.

Specified by:
init in interface javax.servlet.Filter
Parameters:
filterConfig - filter config object

doFilter

public final void doFilter(javax.servlet.ServletRequest servletRequest,
                           javax.servlet.ServletResponse servletResponse,
                           javax.servlet.FilterChain filterChain)
                    throws IOException,
                           javax.servlet.ServletException
Wraps the HTTP request with Simon measuring. Separate Simons are created for different URIs (parameters ignored).

Specified by:
doFilter in interface javax.servlet.Filter
Parameters:
servletRequest - HTTP servlet request
servletResponse - HTTP servlet response
filterChain - filter chain
Throws:
IOException - possibly thrown by other filter/servlet in the chain
javax.servlet.ServletException - possibly thrown by other filter/servlet in the chain

shouldBeReported

protected boolean shouldBeReported(javax.servlet.http.HttpServletRequest request,
                                   long requestNanoTime,
                                   List<Split> splits)
Determines whether the request is over the threshold - with all incoming parameters this method can be very flexible. Default implementation just compares the actual requestNanoTime with getThreshold(javax.servlet.http.HttpServletRequest) (which by default returns value configured in web.xml)

Parameters:
request - HTTP servlet request
requestNanoTime - actual HTTP request nano time
splits - all splits started for the request
Returns:
true, if request should be reported as over threshold

getThreshold

protected long getThreshold(javax.servlet.http.HttpServletRequest request)
Returns actual threshold in *nanoseconds* (not ms as configured) which allows to further customize threshold per request - intended for override. Default behavior returns configured reportThresholdNanos (already converted to ns).

Parameters:
request - HTTP Request
Returns:
threshold in ns for current request
Since:
3.2

getManager

public Manager getManager()

destroy

public void destroy()
Removes the splitSaverCallback if initialized.

Specified by:
destroy in interface javax.servlet.Filter

Java Simon 3.5.0

Copyright © 2014. All rights reserved.