Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.yammer.metrics.jersey;
  
 
 
     private static class TimedRequestDispatcher implements RequestDispatcher {
         private final RequestDispatcher underlying;
         private final Timer timer;
 
         private TimedRequestDispatcher(RequestDispatcher underlyingTimer timer) {
             this. = underlying;
             this. = timer;
         }
 
         @Override
         public void dispatch(Object resourceHttpContext httpContext) {
             final TimerContext context = .time();
             try {
                 .dispatch(resourcehttpContext);
             } finally {
                 context.stop();
             }
         }
     }
 
     private static class MeteredRequestDispatcher implements RequestDispatcher {
         private final RequestDispatcher underlying;
         private final Meter meter;
 
         private MeteredRequestDispatcher(RequestDispatcher underlyingMeter meter) {
             this. = underlying;
             this. = meter;
         }
 
         @Override
         public void dispatch(Object resourceHttpContext httpContext) {
             .mark();
             .dispatch(resourcehttpContext);
         }
     }
 
     private static class ExceptionMeteredRequestDispatcher implements RequestDispatcher {
         private final RequestDispatcher underlying;
         private final Meter meter;
         private final Class<? extends ThrowableexceptionClass;
 
         private ExceptionMeteredRequestDispatcher(RequestDispatcher underlying,
                                                   Meter meter,
                                                   Class<? extends ThrowableexceptionClass) {
             this. = underlying;
             this. = meter;
             this. = exceptionClass;
         }
 
         @Override
         public void dispatch(Object resourceHttpContext httpContext) {
             try {
                 .dispatch(resourcehttpContext);
             } catch (Exception e) {
                 if (.isAssignableFrom(e.getClass()) ||
                         (e.getCause() != null && .isAssignableFrom(e.getCause()
                                                                                   .getClass()))) {
                     .mark();
                 }
                 InstrumentedResourceMethodDispatchProvider.<RuntimeException>rethrow(e);
             }
         }
     }
 
     @SuppressWarnings("unchecked")
     private static <E extends Exceptionvoid rethrow(Exception ethrows E {
         throw (E) e;
     }
 
     private final ResourceMethodDispatchProvider provider;
 
         this. = provider;
     }
 
     @Override
     public RequestDispatcher create(AbstractResourceMethod method) {
         RequestDispatcher dispatcher = .create(method);
         if (dispatcher == null) {
             return null;
         }
        if (method.getMethod().isAnnotationPresent(Timed.class)) {
            final Timed annotation = method.getMethod().getAnnotation(Timed.class);
            final Class<?> klass = method.getDeclaringResource().getResourceClass();
            final String group = MetricName.chooseGroup(annotation.group(), klass);
            final String type = MetricName.chooseType(annotation.type(), klass);
            final String name = MetricName.chooseName(annotation.name(), method.getMethod());
            final MetricName metricName = new MetricName(grouptypename);
            final Timer timer = Metrics.newTimer(metricName,
                                                 annotation.durationUnit() == null ?
                                                         . : annotation.durationUnit(),
                                                 annotation.rateUnit() == null ?
                                                         . : annotation.rateUnit());
            dispatcher = new TimedRequestDispatcher(dispatchertimer);
        }
        if (method.getMethod().isAnnotationPresent(Metered.class)) {
            final Metered annotation = method.getMethod().getAnnotation(Metered.class);
            final Class<?> klass = method.getDeclaringResource().getResourceClass();
            final String group = MetricName.chooseGroup(annotation.group(), klass);
            final String type = MetricName.chooseType(annotation.type(), klass);
            final String name = MetricName.chooseName(annotation.name(), method.getMethod());
            final MetricName metricName = new MetricName(grouptypename);
            final Meter meter = Metrics.newMeter(metricName,
                                                 annotation.eventType() == null ?
                                                         "requests" : annotation.eventType(),
                                                 annotation.rateUnit() == null ?
                                                         . : annotation.rateUnit());
            dispatcher = new MeteredRequestDispatcher(dispatchermeter);
        }
        if (method.getMethod().isAnnotationPresent(ExceptionMetered.class)) {
            final ExceptionMetered annotation = method.getMethod()
                                                      .getAnnotation(ExceptionMetered.class);
            final Class<?> klass = method.getDeclaringResource().getResourceClass();
            final String group = MetricName.chooseGroup(annotation.group(), klass);
            final String type = MetricName.chooseType(annotation.type(), klass);
            final String name = annotation.name() == null || annotation.name().equals("") ?
                    method.getMethod().getName() + . : annotation
                    .name();
            final MetricName metricName = new MetricName(grouptypename);
            final Meter meter = Metrics.newMeter(metricName,
                                                 annotation.eventType() == null ?
                                                         "requests" : annotation.eventType(),
                                                 annotation.rateUnit() == null ?
                                                         . : annotation.rateUnit());
            dispatcher = new ExceptionMeteredRequestDispatcher(dispatcher,
                                                               meter,
                                                               annotation.cause());
        }
        return dispatcher;
    }
New to GrepCode? Check out our FAQ X