summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJonatan Kronqvist <jonatan.kronqvist@itmill.com>2012-04-27 07:19:56 +0000
committerJonatan Kronqvist <jonatan.kronqvist@itmill.com>2012-04-27 07:19:56 +0000
commita19e0784a8d254d0f0ce764f628c247000dd265d (patch)
tree27f262c6115e946a9adb67d2feaa9deacd939518 /src
parentbc06045297c00666447a39f6fa43d67516a005e4 (diff)
downloadvaadin-framework-a19e0784a8d254d0f0ce764f628c247000dd265d.tar.gz
vaadin-framework-a19e0784a8d254d0f0ce764f628c247000dd265d.zip
Simplified fix for #8694
svn changeset:23647/svn branch:6.8
Diffstat (limited to 'src')
-rw-r--r--src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java11
-rw-r--r--src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java10
-rw-r--r--src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java21
-rw-r--r--src/com/vaadin/terminal/gwt/server/AbstractWebApplicationContext.java30
-rw-r--r--src/com/vaadin/terminal/gwt/server/RequestTimer.java116
5 files changed, 56 insertions, 132 deletions
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
index a5923cb47f..a9364c3cf7 100644
--- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
+++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
@@ -326,10 +326,8 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
protected void handleRequest(PortletRequest request,
PortletResponse response) throws PortletException, IOException {
- RequestTimer.RequestWrapper wrappedRequest = new RequestTimer.RequestWrapper(
- request);
- RequestTimer requestTimer = RequestTimer.get(wrappedRequest);
- requestTimer.start(wrappedRequest);
+ RequestTimer requestTimer = new RequestTimer();
+ requestTimer.start();
RequestType requestType = getRequestType(request);
@@ -496,8 +494,9 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
}
- requestTimer.stop();
- RequestTimer.set(wrappedRequest, requestTimer);
+ requestTimer
+ .stop((AbstractWebApplicationContext) application
+ .getContext());
}
}
}
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
index 04ea423004..b177cc5629 100644
--- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
+++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
@@ -401,10 +401,8 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
@Override
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
- RequestTimer.RequestWrapper wrappedRequest = new RequestTimer.RequestWrapper(
- request);
- RequestTimer requestTimer = RequestTimer.get(wrappedRequest);
- requestTimer.start(wrappedRequest);
+ RequestTimer requestTimer = new RequestTimer();
+ requestTimer.start();
RequestType requestType = getRequestType(request);
if (!ensureCookiesEnabled(requestType, request, response)) {
@@ -553,8 +551,8 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
request, response);
}
- requestTimer.stop();
- RequestTimer.set(wrappedRequest, requestTimer);
+ requestTimer.stop((AbstractWebApplicationContext) application
+ .getContext());
}
}
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
index 9a6bccebb8..be1b829eb4 100644
--- a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
+++ b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
@@ -912,7 +912,7 @@ public abstract class AbstractCommunicationManager implements
repaintAll = true;
}
- writeUidlResponse(request, callback, repaintAll, outWriter, window,
+ writeUidlResponce(callback, repaintAll, outWriter, window,
analyzeLayouts);
}
@@ -922,9 +922,9 @@ public abstract class AbstractCommunicationManager implements
}
- public void writeUidlResponse(Request request, Callback callback,
- boolean repaintAll, final PrintWriter outWriter, Window window,
- boolean analyzeLayouts) throws PaintException {
+ public void writeUidlResponce(Callback callback, boolean repaintAll,
+ final PrintWriter outWriter, Window window, boolean analyzeLayouts)
+ throws PaintException {
outWriter.print("\"changes\":[");
ArrayList<Paintable> paintables = null;
@@ -1206,19 +1206,18 @@ public abstract class AbstractCommunicationManager implements
dragAndDropService.printJSONResponse(outWriter);
}
- writePerformanceDataForTestBench(request, outWriter);
+ writePerformanceDataForTestBench(outWriter);
}
/**
* Adds the performance timing data used by TestBench 3 to the UIDL
* response.
*/
- private void writePerformanceDataForTestBench(final Request request,
- final PrintWriter outWriter) {
- Long totalTime = (Long) request.getAttribute("TOTAL");
- Long lastRequestTime = (Long) request.getAttribute("LASTREQUEST");
- outWriter.write(String.format(", \"tbss\":[%d, %d]", totalTime,
- lastRequestTime));
+ private void writePerformanceDataForTestBench(final PrintWriter outWriter) {
+ AbstractWebApplicationContext ctx = (AbstractWebApplicationContext) application
+ .getContext();
+ outWriter.write(String.format(", \"tbss\":[%d, %d]",
+ ctx.getTotalSessionTime(), ctx.getLastRequestTime()));
}
private int getTimeoutInterval() {
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractWebApplicationContext.java b/src/com/vaadin/terminal/gwt/server/AbstractWebApplicationContext.java
index c8335a8607..c0ae0afc26 100644
--- a/src/com/vaadin/terminal/gwt/server/AbstractWebApplicationContext.java
+++ b/src/com/vaadin/terminal/gwt/server/AbstractWebApplicationContext.java
@@ -44,6 +44,10 @@ public abstract class AbstractWebApplicationContext implements
protected HashMap<Application, AbstractCommunicationManager> applicationToAjaxAppMgrMap = new HashMap<Application, AbstractCommunicationManager>();
+ private long totalSessionTime = 0;
+
+ private long lastRequestTime = -1;
+
public void addTransactionListener(TransactionListener listener) {
if (listener != null) {
listeners.add(listener);
@@ -222,4 +226,30 @@ public abstract class AbstractWebApplicationContext implements
return relativeUri.substring(index + 1, next);
}
+ /**
+ * @return The total time spent servicing requests in this session.
+ */
+ public long getTotalSessionTime() {
+ return totalSessionTime;
+ }
+
+ /**
+ * Sets the time spent servicing the last request in the session and updates
+ * the total time spent servicing requests in this session.
+ *
+ * @param time
+ * the time spent in the last request.
+ */
+ public void setLastRequestTime(long time) {
+ lastRequestTime = time;
+ totalSessionTime += time;
+ }
+
+ /**
+ * @return the time spent servicing the last request in this session.
+ */
+ public long getLastRequestTime() {
+ return lastRequestTime;
+ }
+
} \ No newline at end of file
diff --git a/src/com/vaadin/terminal/gwt/server/RequestTimer.java b/src/com/vaadin/terminal/gwt/server/RequestTimer.java
index 1df65d6c58..1fec2d280b 100644
--- a/src/com/vaadin/terminal/gwt/server/RequestTimer.java
+++ b/src/com/vaadin/terminal/gwt/server/RequestTimer.java
@@ -6,11 +6,6 @@ package com.vaadin.terminal.gwt.server;
import java.io.Serializable;
-import javax.portlet.PortletRequest;
-import javax.portlet.PortletSession;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-
/**
* Times the handling of requests and stores the information as an attribute in
* the request. The timing info is later passed on to the client in the UIDL and
@@ -20,125 +15,28 @@ import javax.servlet.http.HttpSession;
* @author Jonatan Kronqvist / Vaadin Ltd
*/
public class RequestTimer implements Serializable {
- public static final String SESSION_ATTR_ID = "REQUESTTIMER";
-
private long requestStartTime = 0;
- private long totalSessionTime = 0;
- private long lastRequestTime = -1;
-
- /**
- * This class acts as a proxy for setting and getting session and request
- * attributes on HttpServletRequests and PortletRequests. Using this class
- * we don't need to duplicate code everywhere.
- */
- static class RequestWrapper implements Serializable {
- private final HttpServletRequest servletRequest;
- private final PortletRequest portletRequest;
-
- public RequestWrapper(HttpServletRequest servletRequest) {
- this.servletRequest = servletRequest;
- portletRequest = null;
- }
-
- public RequestWrapper(PortletRequest portletRequest) {
- this.portletRequest = portletRequest;
- servletRequest = null;
- }
-
- public void setAttribute(String name, Object value) {
- if (servletRequest != null) {
- servletRequest.setAttribute(name, value);
- } else {
- portletRequest.setAttribute(name, value);
- }
- }
-
- public void setSessionAttribute(String name, Object value) {
- if (servletRequest != null) {
- HttpSession session = servletRequest.getSession();
- if (session != null) {
- session.setAttribute(name, value);
- }
- } else {
- PortletSession portletSession = portletRequest
- .getPortletSession();
- if (portletSession != null) {
- portletSession.setAttribute(name, value);
- }
- }
- }
-
- public Object getSessionAttribute(String name) {
- if (servletRequest != null) {
- HttpSession session = servletRequest.getSession();
- if (session != null) {
- return session.getAttribute(name);
- }
- } else {
- PortletSession portletSession = portletRequest
- .getPortletSession();
- if (portletSession != null) {
- return portletSession.getAttribute(name);
- }
- }
- return null;
- }
- }
/**
* Starts the timing of a request. This should be called before any
* processing of the request.
- *
- * @param request
- * the request.
*/
- public void start(RequestWrapper 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(RequestWrapper 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(RequestWrapper 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);
}
}