Tapestry钩子:渲染开始和渲染结束

发布于 2024-11-06 20:58:06 字数 192 浏览 6 评论 0原文

我正在尝试使用 jamon 来收集使用 Tapestry 的网站的统计信息(渲染网页的时间)。

如何继续

  • 当服务器收到请求(即渲染开始)时,
  • 执行方法?当响应全部发送时执行的方法,即渲染结束?

我正在尝试使用 @OnEvent 注释,但我不会走得太远。

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 the 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蘑菇王子 2024-11-13 20:58:06

您可以创建一个 RequestFilter 来包装对您自己的代码的调用之间的实际渲染:

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() {
       ...
   }    

}

您需要通过应用程序模块将过滤器贡献给渲染管道:

public void contributeRequestHandler(
        final OrderedConfiguration<RequestFilter> configuration) {
    configuration.add("RenderStatisticsFilter", new RenderStatisticsFilter());
}

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());
}
漆黑的白昼 2024-11-13 20:58:06

Tapestry 具有可扩展的管道,可以组织任何特定类型请求的逻辑。我不确定您是否正在尝试测量总体请求处理时间,或者只是测量渲染所花费的时间(并且,在 Tapestry 中,实际上是渲染 DOM,然后将 DOM 流式传输到客户端)。 HttpServletRequestHandler 管道是放置过滤器的好地方,该过滤器可以测量所有请求的所有响应时间(但没有提供仅选择页面渲染请求的好方法),PageRenderRequestHandler 管道适合测量渲染和流式传输的时间页。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文