Java Simon 3.5.0

org.javasimon.javaee
Class HttpStopwatchSource

java.lang.Object
  extended by org.javasimon.source.AbstractStopwatchSource<javax.servlet.http.HttpServletRequest>
      extended by org.javasimon.javaee.HttpStopwatchSource
All Implemented Interfaces:
MonitorSource<javax.servlet.http.HttpServletRequest,Stopwatch>, StopwatchSource<javax.servlet.http.HttpServletRequest>

public class HttpStopwatchSource
extends AbstractStopwatchSource<javax.servlet.http.HttpServletRequest>

Provide stopwatch source for HTTP Servlet request. Used by SimonServletFilter as default stopwatch source. Can be overridden to customize monitored HTTP Requests and their related Simon name.

To select which HTTP Request should be monitored method isMonitored(javax.servlet.http.HttpServletRequest) can be overridden. Default implementation monitors everything except for typical resource-like requests (images, JS/CSS, ...).

Author:
gquintana, Richard "Virgo" Richter

Nested Class Summary
static class HttpStopwatchSource.IncludeHttpMethodName
          Enum that represents modes of preserving HTTP methods names in Simons' names
 
Field Summary
static String DEFAULT_SIMON_PREFIX
          Default prefix for web filter Simons if no "prefix" init parameter is used.
 
Constructor Summary
HttpStopwatchSource(Manager manager)
           
 
Method Summary
 HttpStopwatchSource.IncludeHttpMethodName getIncludeHttpMethodName()
          Returns current mode of preserving HTTP method names in simons' names
 Stopwatch getMonitor(javax.servlet.http.HttpServletRequest request)
          Get a stopwatch for given HTTP request.
protected  String getMonitorName(javax.servlet.http.HttpServletRequest request)
          Returns Simon name for the specified HTTP request with the specified prefix.
 String getPrefix()
           
 String getReplaceUnallowed()
           
 boolean isMonitored(javax.servlet.http.HttpServletRequest httpServletRequest)
          Indicates whether the HTTP Request should be monitored - method is intended for override.
static StopwatchSource<javax.servlet.http.HttpServletRequest> newCacheStopwatchSource(StopwatchSource<javax.servlet.http.HttpServletRequest> stopwatchSource)
          Wraps given stop watch source in a cache.
protected  String removeJSessionIdFromUri(String uri)
          Removes JSESSIONID parameter from URI.
protected  String removeTrailingStuff(String uri)
          Removes any trailing slashes followed by other characters if none of them is alphabetic.
protected  String requestToStringForMonitorName(javax.servlet.http.HttpServletRequest request)
          Performs the first step in getting the monitor name from the specified HTTP request - here any custom ignore logic should happen.
 void setIncludeHttpMethodName(HttpStopwatchSource.IncludeHttpMethodName includeHttpMethodName)
          Set current mode of preserving HTTP method names in simons' names
 void setPrefix(String prefix)
           
 void setReplaceUnallowed(String replaceUnallowed)
           
 
Methods inherited from class org.javasimon.source.AbstractStopwatchSource
getManager, start
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SIMON_PREFIX

public static final String DEFAULT_SIMON_PREFIX
Default prefix for web filter Simons if no "prefix" init parameter is used.

See Also:
Constant Field Values
Constructor Detail

HttpStopwatchSource

public HttpStopwatchSource(Manager manager)
Method Detail

getPrefix

public String getPrefix()

setPrefix

public void setPrefix(String prefix)

getReplaceUnallowed

public String getReplaceUnallowed()

setReplaceUnallowed

public void setReplaceUnallowed(String replaceUnallowed)

getIncludeHttpMethodName

public HttpStopwatchSource.IncludeHttpMethodName getIncludeHttpMethodName()
Returns current mode of preserving HTTP method names in simons' names

Returns:
current mode of preserving HTTP method names

setIncludeHttpMethodName

public void setIncludeHttpMethodName(HttpStopwatchSource.IncludeHttpMethodName includeHttpMethodName)
Set current mode of preserving HTTP method names in simons' names

Parameters:
includeHttpMethodName - current mode of preserving HTTP method names

getMonitorName

protected String getMonitorName(javax.servlet.http.HttpServletRequest request)
Returns Simon name for the specified HTTP request with the specified prefix. By default it contains URI without parameters with all slashes replaced for dots (slashes then determines position in Simon hierarchy). Method can NOT be overridden, but some of the following steps can:
  1. the request is transformed to the string (requestToStringForMonitorName(javax.servlet.http.HttpServletRequest), can be overridden),
  2. the characters that are not allowed as part of the Simon name are replaced with underscore (_) - replacement regex can be changed with setReplaceUnallowed(String),
  3. any subsequent slashes and dots are replaced with a single dot (Manager.HIERARCHY_DELIMITER)

Specified by:
getMonitorName in class AbstractStopwatchSource<javax.servlet.http.HttpServletRequest>
Parameters:
request - HTTP request
Returns:
fully qualified name of the Simon
See Also:
requestToStringForMonitorName(javax.servlet.http.HttpServletRequest)

requestToStringForMonitorName

protected String requestToStringForMonitorName(javax.servlet.http.HttpServletRequest request)
Performs the first step in getting the monitor name from the specified HTTP request - here any custom ignore logic should happen. By default the name is URI (without parameters - see HttpServletRequest.getRequestURI()) with JSessionID removed (see removeJSessionIdFromUri(String)) and any trailing stuff removed (see removeTrailingStuff(String)). This method can be overridden for two typical reasons:

Parameters:
request - HTTP request
Returns:
preprocessed URI that will be converted to the Simon name
See Also:
getMonitorName(javax.servlet.http.HttpServletRequest), removeJSessionIdFromUri(String)

removeJSessionIdFromUri

protected String removeJSessionIdFromUri(String uri)
Removes JSESSIONID parameter from URI. By default it is not necessary to handle parameters, as incoming URI already is without parameters, but JSESSIONID sometimes come before parameters in other forms and this method tries to remove such forms.

Called by default implementation of requestToStringForMonitorName(javax.servlet.http.HttpServletRequest) and extracted so it can be used by any overriding implementation of the same method. Method can be overridden if the default behavior is not sufficient.

Parameters:
uri - preprocessed URI that may contain JSessionID
Returns:
preprocessed URI without JSessionID
See Also:
requestToStringForMonitorName(javax.servlet.http.HttpServletRequest)

removeTrailingStuff

protected String removeTrailingStuff(String uri)
Removes any trailing slashes followed by other characters if none of them is alphabetic. This should take care of some REST parameters (numeric id-s) and it also removes trailing slashes to avoid empty local Simon names which is forbidden.

Called by default implementation of requestToStringForMonitorName(javax.servlet.http.HttpServletRequest) and extracted so it can be used by any overriding implementation of the same method. Method can be overridden if the default behavior is not sufficient.

Parameters:
uri - preprocessed URI that may contain JSessionID
Returns:
preprocessed URI without JSessionID
See Also:
requestToStringForMonitorName(javax.servlet.http.HttpServletRequest)

isMonitored

public boolean isMonitored(javax.servlet.http.HttpServletRequest httpServletRequest)
Indicates whether the HTTP Request should be monitored - method is intended for override. Default behavior ignores URIs ending with .css, .png, .gif, .jpg and .js (ignores casing).

Specified by:
isMonitored in interface MonitorSource<javax.servlet.http.HttpServletRequest,Stopwatch>
Overrides:
isMonitored in class AbstractStopwatchSource<javax.servlet.http.HttpServletRequest>
Parameters:
httpServletRequest - HTTP Request
Returns:
true to enable request monitoring, false either

getMonitor

public Stopwatch getMonitor(javax.servlet.http.HttpServletRequest request)
Get a stopwatch for given HTTP request.

Specified by:
getMonitor in interface MonitorSource<javax.servlet.http.HttpServletRequest,Stopwatch>
Overrides:
getMonitor in class AbstractStopwatchSource<javax.servlet.http.HttpServletRequest>
Parameters:
request - Method HTTP request
Returns:
Stopwatch for the HTTP request

newCacheStopwatchSource

public static StopwatchSource<javax.servlet.http.HttpServletRequest> newCacheStopwatchSource(StopwatchSource<javax.servlet.http.HttpServletRequest> stopwatchSource)
Wraps given stop watch source in a cache.

Parameters:
stopwatchSource - Stopwatch source
Returns:
Cached stopwatch source

Java Simon 3.5.0

Copyright © 2014. All rights reserved.