diff options
Diffstat (limited to 'src/com/vaadin/terminal/gwt/server/RequestTimer.java')
-rw-r--r-- | src/com/vaadin/terminal/gwt/server/RequestTimer.java | 55 |
1 files changed, 9 insertions, 46 deletions
diff --git a/src/com/vaadin/terminal/gwt/server/RequestTimer.java b/src/com/vaadin/terminal/gwt/server/RequestTimer.java index d47f444bef..6c0edec466 100644 --- a/src/com/vaadin/terminal/gwt/server/RequestTimer.java +++ b/src/com/vaadin/terminal/gwt/server/RequestTimer.java @@ -4,7 +4,7 @@ package com.vaadin.terminal.gwt.server; -import com.vaadin.terminal.WrappedRequest; +import java.io.Serializable; /** * Times the handling of requests and stores the information as an attribute in @@ -14,67 +14,30 @@ import com.vaadin.terminal.WrappedRequest; * * @author Jonatan Kronqvist / Vaadin Ltd */ -public class RequestTimer { - public static final String SESSION_ATTR_ID = "REQUESTTIMER"; - +public class RequestTimer implements Serializable { private long requestStartTime = 0; - private long totalSessionTime = 0; - private long lastRequestTime = -1; /** * Starts the timing of a request. This should be called before any * processing of the request. - * - * @param request - * the request. */ - public void start(WrappedRequest request) { + public void start() { requestStartTime = System.nanoTime(); - request.setAttribute("TOTAL", totalSessionTime); - request.setAttribute("LASTREQUEST", lastRequestTime); } /** * Stops the timing of a request. This should be called when all processing * of a request has finished. + * + * @param context */ - public void stop() { + public void stop(AbstractWebApplicationContext context) { // Measure and store the total handling time. This data can be // used in TestBench 3 tests. long time = (System.nanoTime() - requestStartTime) / 1000000; - lastRequestTime = time; - totalSessionTime += time; - } - - /** - * Returns a valid request timer for the specified request. Timers are - * session bound. - * - * @param request - * the request for which to get a valid timer. - * @return a valid timer. - */ - public static RequestTimer get(WrappedRequest request) { - RequestTimer timer = (RequestTimer) request - .getSessionAttribute(SESSION_ATTR_ID); - if (timer == null) { - timer = new RequestTimer(); - } - return timer; - } - /** - * Associates the specified request timer with the specified request. Since - * {@link #get(RequestWrapper)} will, at one point or another, return a new - * instance, this method should be called to keep the request <-> timer - * association updated. - * - * @param request - * the request for which to set the timer. - * @param requestTimer - * the timer. - */ - public static void set(WrappedRequest request, RequestTimer requestTimer) { - request.setSessionAttribute(RequestTimer.SESSION_ATTR_ID, requestTimer); + // The timings must be stored in the context, since a new + // RequestTimer is created for every request. + context.setLastRequestTime(time); } } |