summaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/terminal/gwt/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/vaadin/terminal/gwt/server')
-rw-r--r--src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java6
-rw-r--r--src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java5
-rw-r--r--src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java20
-rw-r--r--src/com/vaadin/terminal/gwt/server/RequestTimer.java80
4 files changed, 108 insertions, 3 deletions
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
index 0d67086339..58d6a18592 100644
--- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
+++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
@@ -530,6 +530,9 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
WrappedPortletResponse wrappedResponse = new WrappedPortletResponse(
response, getDeploymentConfiguration());
+ RequestTimer requestTimer = RequestTimer.get(wrappedRequest);
+ requestTimer.start(wrappedRequest);
+
RequestType requestType = getRequestType(request);
if (requestType == RequestType.UNKNOWN) {
@@ -719,6 +722,9 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
Root.setCurrentRoot(null);
Application.setCurrentApplication(null);
}
+
+ requestTimer.stop();
+ RequestTimer.set(wrappedRequest, requestTimer);
}
}
}
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
index 18cc3f97f4..799271b979 100644
--- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
+++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
@@ -403,6 +403,9 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
AbstractApplicationServletWrapper servletWrapper = new AbstractApplicationServletWrapper(
this);
+ RequestTimer requestTimer = RequestTimer.get(request);
+ requestTimer.start(request);
+
RequestType requestType = getRequestType(request);
if (!ensureCookiesEnabled(requestType, request, response)) {
return;
@@ -539,6 +542,8 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
Application.setCurrentApplication(null);
}
+ requestTimer.stop();
+ RequestTimer.set(request, requestTimer);
}
}
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
index a1a917130f..b780f66a23 100644
--- a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
+++ b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
@@ -691,7 +691,7 @@ public abstract class AbstractCommunicationManager implements Serializable {
outWriter.print(getSecurityKeyUIDL(request));
}
- writeUidlResponse(repaintAll, outWriter, root, analyzeLayouts);
+ writeUidlResponse(request, repaintAll, outWriter, root, analyzeLayouts);
closeJsonMessage(outWriter);
@@ -735,7 +735,7 @@ public abstract class AbstractCommunicationManager implements Serializable {
}
@SuppressWarnings("unchecked")
- public void writeUidlResponse(boolean repaintAll,
+ public void writeUidlResponse(WrappedRequest request, boolean repaintAll,
final PrintWriter outWriter, Root root, boolean analyzeLayouts)
throws PaintException {
ArrayList<ClientConnector> dirtyVisibleConnectors = new ArrayList<ClientConnector>();
@@ -1096,6 +1096,20 @@ public abstract class AbstractCommunicationManager implements Serializable {
if (dragAndDropService != null) {
dragAndDropService.printJSONResponse(outWriter);
}
+
+ writePerformanceDataForTestBench(request, outWriter);
+ }
+
+ /**
+ * Adds the performance timing data used by TestBench 3 to the UIDL
+ * response.
+ */
+ private void writePerformanceDataForTestBench(final WrappedRequest 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 legacyPaint(PaintTarget paintTarget,
@@ -2161,7 +2175,7 @@ public abstract class AbstractCommunicationManager implements Serializable {
if (isXSRFEnabled(root.getApplication())) {
pWriter.print(getSecurityKeyUIDL(request));
}
- writeUidlResponse(true, pWriter, root, false);
+ writeUidlResponse(request, true, pWriter, root, false);
pWriter.print("}");
String initialUIDL = sWriter.toString();
logger.log(Level.FINE, "Initial UIDL:" + initialUIDL);
diff --git a/src/com/vaadin/terminal/gwt/server/RequestTimer.java b/src/com/vaadin/terminal/gwt/server/RequestTimer.java
new file mode 100644
index 0000000000..d47f444bef
--- /dev/null
+++ b/src/com/vaadin/terminal/gwt/server/RequestTimer.java
@@ -0,0 +1,80 @@
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.terminal.gwt.server;
+
+import com.vaadin.terminal.WrappedRequest;
+
+/**
+ * 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
+ * the client provides JavaScript API for accessing this data from e.g.
+ * TestBench.
+ *
+ * @author Jonatan Kronqvist / Vaadin Ltd
+ */
+public class RequestTimer {
+ public static final String SESSION_ATTR_ID = "REQUESTTIMER";
+
+ 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) {
+ 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.
+ */
+ public void stop() {
+ // 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);
+ }
+}