I am trying to use jamon to collect statistics (time to render a web page) of a website using tapestry.
How can I proceed to have
- a method executed when the request is received by the server, i.e. the start of the rendering ?
- a method executed when th开发者_运维百科e response is all sent, i.e. the end of the rendering ?
I am trying to use the @OnEvent
annotation but I'm not going very far with that.
You could create a RequestFilter
to wrap the actual rendering between calls to your own code:
public class RenderStatisticsFilter implements RequestFilter {
@Override
public boolean service(Request request, Response response,
RequestHandler handler) throws IOException {
this.beforeRender();
final boolean result = handler.service(request, response);
this.afterRender();
return result;
}
private void beforeRender() {
...
}
private void afterRender() {
...
}
}
You'd need to contribute your filter to the rendering pipeline via your application module:
public void contributeRequestHandler(
final OrderedConfiguration<RequestFilter> configuration) {
configuration.add("RenderStatisticsFilter", new RenderStatisticsFilter());
}
Tapestry has extensible pipelines that organize the logic for any particular type of request. I'm not sure if you are trying to measure over-all request processing time, or just the time spent rendering (and, in Tapestry, there's actually rendering the DOM, and then streaming the DOM to the client). The HttpServletRequestHandler pipeline is a good place to put a filter that can measure over all response time for all requests (but does not provide a good way to select only page render requests), the PageRenderRequestHandler pipeline is good for measuring time to render and stream the page.
精彩评论