@Test void stats() throws IOException, ServletException { Request baseReq = mock(Request.class); HttpChannelState s = new HttpChannelState(null){}; when(baseReq.getHttpChannelState()).thenReturn(s); Response resp = mock(Response.class); when(baseReq.getResponse()).thenReturn(resp); when(resp.getContentCount()).thenReturn(772L); handler.handle("/testUrl", baseReq, new MockHttpServletRequest(), new MockHttpServletResponse()); assertThat(registry.mustFind("jetty.requests").functionTimer().count()).isEqualTo(1L); assertThat(registry.mustFind("jetty.responses.size").functionCounter().count()).isEqualTo(772.0); }
@Override public void handle(String path, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { if (!registry.isEnabled()) { super.handle(path, request, httpRequest, httpResponse); return; } final HttpChannelState state = request.getHttpChannelState(); if (state.isInitial()) { state.addListener(listener); } final long startTime = registry.getNanos(); try { super.handle(path, request, httpRequest, httpResponse); } finally { if (!state.isSuspended() && state.isInitial()) { updateResponses(httpRequest, httpResponse, startTime); } // else onCompletion will handle it. } }
@Override public void handle(String path, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { activeDispatches.inc(); final long start; final HttpChannelState state = request.getHttpChannelState(); if (state.isInitial()) { // new request activeRequests.inc(); start = request.getTimeStamp(); } else { // resumed request start = System.currentTimeMillis(); activeSuspended.dec(); if (state.getState() == State.DISPATCHED) { asyncDispatches.mark(); } } try { super.handle(path, request, httpRequest, httpResponse); } finally { final long now = System.currentTimeMillis(); final long dispatched = now - start; activeDispatches.dec(); dispatches.update(dispatched, TimeUnit.MILLISECONDS); if (state.isSuspended()) { if (state.isInitial()) { state.addListener(listener); } activeSuspended.inc(); } else if (state.isInitial()) { requests.update(dispatched, TimeUnit.MILLISECONDS); updateResponses(request); } // else onCompletion will handle it. } }