|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.javasimon.javaee.SimonServletFilter
public class SimonServletFilter
Simon Servlet filter measuring HTTP request execution times. Non-HTTP usages are not supported. Filter provides these functions:
INIT_PARAM_SIMON_CONSOLE_PATH is used in web.xmlshouldBeReported(javax.servlet.http.HttpServletRequest, long, java.util.List) - compares actual request nano time with getThreshold(javax.servlet.http.HttpServletRequest)
(which may become unused if this method is overridden)getThreshold(javax.servlet.http.HttpServletRequest) - returns threshold configured in web.xmlRequestReporter can be implemented and specified using init parameter INIT_PARAM_REQUEST_REPORTER_CLASSHttpStopwatchSource can be subclassed and specified using init parameter INIT_PARAM_STOPWATCH_SOURCE_CLASS, specifically
following methods are intended for override:
HttpStopwatchSource.isMonitored(javax.servlet.http.HttpServletRequest) - true except for request with typical resource suffixes
(.gif, .jpg, .css, etc.)HttpStopwatchSource.getMonitorName(javax.servlet.http.HttpServletRequest)
| Nested Class Summary | |
|---|---|
private class |
SimonServletFilter.SplitSaverCallback
|
| Field Summary | |
|---|---|
protected String |
consolePath
URL path that displays Simon web console (or null if no console is required). |
private static Replacer |
FINAL_SLASH_REMOVE
|
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. |
private Manager |
manager
Simon Manager used by the filter. |
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. |
private RequestReporter |
requestReporter
Object responsible for reporting the request over threshold (if shouldBeReported(javax.servlet.http.HttpServletRequest, long, java.util.List)
returns true). |
private static Replacer |
SLASH_TRIM
|
private SimonServletFilter.SplitSaverCallback |
splitSaverCallback
Callback that saves all splits in splitsThreadLocal if reportThresholdNanos is configured. |
private ThreadLocal<List<Split>> |
splitsThreadLocal
Thread local list of splits used to cumulate all splits for the request. |
private StopwatchSource<javax.servlet.http.HttpServletRequest> |
stopwatchSource
Stopwatch source is used before/after each request to start/stop a stopwatch. |
| Constructor Summary | |
|---|---|
SimonServletFilter()
|
|
| Method Summary | |
|---|---|
private void |
consolePage(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
String localPath)
|
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. |
private void |
doFilterWithMonitoring(javax.servlet.FilterChain filterChain,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
|
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. |
private void |
pickUpSharedManagerIfExists(javax.servlet.FilterConfig filterConfig)
|
private void |
printSimonTree(javax.servlet.ServletResponse response)
|
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. |
private void |
simonHelp(javax.servlet.ServletResponse response)
|
private void |
stopSplitForRequest(javax.servlet.http.HttpServletRequest request,
Split split)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String INIT_PARAM_PREFIX
public static final String INIT_PARAM_REPORT_THRESHOLD_MS
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).
public static final String INIT_PARAM_SIMON_CONSOLE_PATH
public static final String INIT_PARAM_STOPWATCH_SOURCE_CLASS
MonitorSource.
One can use DisabledMonitorSource to disabled monitoring.
Defaults to HttpStopwatchSource.
public static final String INIT_PARAM_STOPWATCH_SOURCE_CACHE
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.
public static final String INIT_PARAM_REQUEST_REPORTER_CLASS
RequestReporter implementation that is used to report requests
that shouldBeReported(javax.servlet.http.HttpServletRequest, long, java.util.List).
Default is DefaultRequestReporter.
private static Replacer FINAL_SLASH_REMOVE
private static Replacer SLASH_TRIM
protected Long reportThresholdNanos
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.
protected String printTreePath
protected String consolePath
private Manager manager
private final ThreadLocal<List<Split>> splitsThreadLocal
private SimonServletFilter.SplitSaverCallback splitSaverCallback
splitsThreadLocal if reportThresholdNanos is configured.
private StopwatchSource<javax.servlet.http.HttpServletRequest> stopwatchSource
private RequestReporter requestReporter
shouldBeReported(javax.servlet.http.HttpServletRequest, long, java.util.List)
returns true).
| Constructor Detail |
|---|
public SimonServletFilter()
| Method Detail |
|---|
public final void init(javax.servlet.FilterConfig filterConfig)
SimonUtils.MANAGER_SERVLET_CTX_ATTRIBUTE servlet context attribute is not null.
init in interface javax.servlet.FilterfilterConfig - filter config objectprivate void pickUpSharedManagerIfExists(javax.servlet.FilterConfig filterConfig)
public final void doFilter(javax.servlet.ServletRequest servletRequest,
javax.servlet.ServletResponse servletResponse,
javax.servlet.FilterChain filterChain)
throws IOException,
javax.servlet.ServletException
doFilter in interface javax.servlet.FilterservletRequest - HTTP servlet requestservletResponse - HTTP servlet responsefilterChain - filter chain
IOException - possibly thrown by other filter/servlet in the chain
javax.servlet.ServletException - possibly thrown by other filter/servlet in the chain
private void doFilterWithMonitoring(javax.servlet.FilterChain filterChain,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws IOException,
javax.servlet.ServletException
IOException
javax.servlet.ServletException
private void stopSplitForRequest(javax.servlet.http.HttpServletRequest request,
Split split)
protected boolean shouldBeReported(javax.servlet.http.HttpServletRequest request,
long requestNanoTime,
List<Split> splits)
getThreshold(javax.servlet.http.HttpServletRequest) (which by default returns value configured
in web.xml)
request - HTTP servlet requestrequestNanoTime - actual HTTP request nano timesplits - all splits started for the request
true, if request should be reported as over thresholdprotected long getThreshold(javax.servlet.http.HttpServletRequest request)
reportThresholdNanos (already converted to ns).
request - HTTP Request
private void consolePage(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
String localPath)
throws IOException
IOException
private void simonHelp(javax.servlet.ServletResponse response)
throws IOException
IOException
private void printSimonTree(javax.servlet.ServletResponse response)
throws IOException
IOExceptionpublic Manager getManager()
public void destroy()
destroy in interface javax.servlet.Filter
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||