@Override public void dec() { delegate.dec(); }
@Override public void dec(long n) { delegate.dec(n); }
@Override protected void postInvoke(Counter counter, Counted annot, InvocationContext context, Exception ex) { if (!annot.monotonic()) { counter.dec(); } } }
/** * Updates fallback metrics and adjust failed invocations based on outcome of fallback. */ private void updateMetrics(Throwable throwable) { final Method method = context.getMethod(); FaultToleranceMetrics.getCounter(method, FaultToleranceMetrics.FALLBACK_CALLS_TOTAL).inc(); // If fallback was successful, it is not a failed invocation if (throwable == null) { FaultToleranceMetrics.getCounter(method, FaultToleranceMetrics.INVOCATIONS_FAILED_TOTAL).dec(); } } }
@Override protected void postInvoke(Counter counter, Counted annot, InvocationContext context, Exception ex) { if (!annot.monotonic()) { counter.dec(); } } }
private Object invoke(final InvocationContext context, final Executable executable) throws Exception { final Meta counter = findCounter(executable); counter.counter.inc(); try { return context.proceed(); } finally { if (!counter.skipDecrement) { counter.counter.dec(); } } }
@Override public void onComplete(AsyncEvent event) throws IOException { if (!done) { HttpServletResponse suppliedResponse = (HttpServletResponse) event.getSuppliedResponse(); context.stop(); activeRequests.dec(); markMeterForStatusCode(suppliedResponse.getStatus()); } }
@Override public void onTimeout(AsyncEvent event) throws IOException { context.stop(); activeRequests.dec(); timeoutsMeter.mark(); done = true; }
@Override public void onError(AsyncEvent event) throws IOException { context.stop(); activeRequests.dec(); errorsMeter.mark(); done = true; }
@Test @InSequence(4) public void decrementTest() { count.dec(); Assert.assertEquals(4, count.getCount()); }
@Test @InSequence(5) public void decrementLongTest() { count.dec(4); Assert.assertEquals(0, count.getCount()); } }
private <E extends Member & AnnotatedElement> Object applyInterceptor(InvocationContext context, E member) throws Exception { Metadata metadata = AnnotationMetadata.buildMetadata(bean.getBeanClass(), member, Counted.class); Counter counter = applicationRegistry.getCounters().get(metadata.getName()); if (counter == null) { throw new IllegalStateException("No counter with name [" + metadata.getName() + "] found in registry [" + applicationRegistry + "]"); } counter.inc(); try { return context.proceed(); } finally { Counted annotation = AnnotationMetadata.getAnnotation(bean.getBeanClass(), member, Counted.class); if(annotation != null && !annotation.monotonic()) { counter.dec(); } } } }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final StatusExposingServletResponse wrappedResponse = new StatusExposingServletResponse((HttpServletResponse) response); activeRequests.inc(); final Timer.Context context = requestTimer.time(); boolean error = false; try { chain.doFilter(request, wrappedResponse); } catch (IOException | RuntimeException | ServletException e) { error = true; throw e; } finally { if (!error && request.isAsyncStarted()) { request.getAsyncContext().addListener(new AsyncResultListener(context)); } else { context.stop(); activeRequests.dec(); if (error) { errorsMeter.mark(); } else { markMeterForStatusCode(wrappedResponse.getStatus()); } } } }