Package com.dynatrace.android.agent
Class WebRequestTiming
- java.lang.Object
-
- com.dynatrace.android.agent.WebRequestTiming
-
public class WebRequestTiming extends Object
This class represents a network timing event for reporting the time elapsed between two user-defined time points (startWebRequestTimingandstopWebRequestTiming). Each timing event requires an associated tag, generated byDynatrace.getRequestTag()orDTXAction.getRequestTag().Web request timing example:
// [1] Create an action for the web request DTXAction webAction = Dynatrace.enterAction("yourActionName"); HttpURLConnection urlConnection = null; WebRequestTiming timing = null; try{ URL url = new URL("http://www.example.com"); urlConnection = (HttpURLConnection) url.openConnection(); // [2] Tag the web request automatically and receive a WebRequestTiming instance timing = Dynatrace.getWebRequestTiming(urlConnection); // [3] Call startWebRequestTiming() to begin the timing (and then handle the input stream from the connection) timing.startWebRequestTiming(); InputStream input = new BufferedInputStream(urlConnection.getInputStream()); readStream(input); // [4] Once we're done reading, we can stop the timing timing.stopWebRequestTiming(); processData(); } catch (Exception exception) { // [5a] Finalize the timing when an error occurs if(timing != null) { timing.stopWebRequestTiming(); } // [5b] Attach the exception to the action webAction.reportError("Exception", e); // user-defined exception handling handleError(exception); } finally { if(urlConnection != null) { urlConnection.disconnect(); } // [6] Lastly finalize the timing of the action in the finally block. webAction.leaveAction(); }
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanisFinalized()Used to determine if the current object has been finalized.voidstartWebRequestTiming()Begin timing a web request event.voidstopWebRequestTiming()Stop, finalize, and send a web request timing event.voidstopWebRequestTiming(String requestUrl, int respCode, String respPhrase)Stop, finalize, and send a web request timing event.voidstopWebRequestTiming(URI requestUri, int respCode, String respPhrase)Stop, finalize, and send a web request timing event.voidstopWebRequestTiming(URL requestUrl, int respCode, String respPhrase)Stop, finalize, and send a web request timing event.
-
-
-
Method Detail
-
startWebRequestTiming
public void startWebRequestTiming()
Begin timing a web request event.You must call
stopWebRequestTiming()to complete the timing.
-
stopWebRequestTiming
public void stopWebRequestTiming(String requestUrl, int respCode, String respPhrase) throws MalformedURLException
Stop, finalize, and send a web request timing event. This can only be called once on each object. This method has to be called afterstartWebRequestTiming()The given requestUrl must have a scheme that is eitherhttp,https,ws,wssorfile. Other schemes are rejected and the web request timing event is dropped.- Parameters:
respCode- Status code from responserespPhrase- Response phrase from responserequestUrl- The URL of the request as a string- Throws:
MalformedURLException- is never thrown but has been retained for API stability
-
stopWebRequestTiming
public void stopWebRequestTiming(URL requestUrl, int respCode, String respPhrase)
Stop, finalize, and send a web request timing event. This can only be called once on each object. This method has to be called afterstartWebRequestTiming()- Parameters:
respCode- Status code from responserespPhrase- Response phrase from responserequestUrl- The URL of the request
-
stopWebRequestTiming
public void stopWebRequestTiming(URI requestUri, int respCode, String respPhrase)
Stop, finalize, and send a web request timing event. This can only be called once on each object. This method has to be called afterstartWebRequestTiming(). The given URI must have a scheme that is eitherhttp,https,ws,wssorfile. Other schemes are rejected and the web request timing event is dropped.- Parameters:
respCode- Status code from responserespPhrase- Response phrase from responserequestUri- The URL of the request- Since:
- 8.239
-
isFinalized
public boolean isFinalized()
Used to determine if the current object has been finalized. Finalized objects cannot be restarted or reused. CallingstopWebRequestTiming()finalizes the object and prepares the data for the next sending interval.- Returns:
trueif the object has been finalized
falseif it has not been finalized
-
stopWebRequestTiming
public void stopWebRequestTiming()
Stop, finalize, and send a web request timing event. This can only be called once on each object.
-
-