Package com.codahale.metrics

Examples of com.codahale.metrics.Timer


            if(executeMethod.isAnnotationPresent(Timed.class)) {
                Timed annotation = executeMethod.getAnnotation(Timed.class);
                String name = chooseName(annotation.name(),
                        annotation.absolute(),
                        task);
                Timer timer = metricRegistry.timer(name);
                taskExecutor = new TimedTask(taskExecutor, timer);
            }

            if(executeMethod.isAnnotationPresent(Metered.class)) {
                Metered annotation = executeMethod.getAnnotation(Metered.class);
View Full Code Here


    if (!propertyFilter.hasFilters()) {
      super.writeTo(o, type, genericType, annotations, mediaType, httpHeaders, os);
      return;
    }

    final Timer timer = getTimer();
    final Timer.Context context = timer.time();

    try {
      final JsonNode tree = objectMapper.valueToTree(o);
      propertyFilter.filter(tree);
      super.writeTo(tree, tree.getClass(), tree.getClass(), annotations, mediaType, httpHeaders, os);
View Full Code Here

    MetricFilter filter = PatternMetricFilter.parse(new Configs(), config);
    assertNotSame(filter, MetricFilter.ALL);
    assertTrue(filter.matches("foo", new Counter()));
    assertTrue(filter.matches("boo", new Counter()));
    assertFalse(filter.matches("foo.bar", new Counter()));
    assertFalse(filter.matches("boo", new Timer()));
    assertTrue(filter.toString().length() > 0);
  }
View Full Code Here

    }
  }

  @Test
  public void timedMethod() throws Throwable {
    Timer timedMethod = forTimedMethod(metricRegistry, MeteredClassImpl.class, "timedMethod");

    assertEquals(0, timedMethod.getCount());

    meteredClass.timedMethod();
    assertEquals(1, timedMethod.getCount());
  }
View Full Code Here

    assertSame(target.theNameForTheMeter, meter);
    assertSame(target2.theNameForTheMeter, meter);

    assertNotNull(target.timer);
    assertNotNull(target2.timer);
    Timer timer = (Timer) forMetricField(metricRegistry, MetricAnnotationTest.Target.class, "timer");
    assertSame(target.timer, timer);
    assertSame(target2.timer, timer);

    assertNotNull(target.counter);
    assertNotNull(target2.counter);
View Full Code Here

  }

  @Test
  public void timedMethod() throws Throwable {
    // Verify that the Timer's counter is incremented on method invocation
    Timer timedMethodTimer = forTimedMethod(metricRegistry, TestBean.class, "timedMethod");
    assertNotNull(timedMethodTimer);
    assertThat(timedMethodTimer.getCount(), is(0L));
    testBean.timedMethod();
    assertThat(timedMethodTimer.getCount(), is(1L));
  }
View Full Code Here

    assertEquals(0.5, gaugedGaugeField.getValue());
  }

  @Test
  public void timedMethod() throws Throwable {
    Timer timedMethod = forTimedMethod(metricRegistry, MeteredClass.class, "timedMethod");

    assertEquals(0, timedMethod.getCount());

    meteredClass.timedMethod(false);
    assertEquals(1, timedMethod.getCount());

    // getCount increments even when the method throws an exception
    try {
      meteredClass.timedMethod(true);
      fail();
    }
    catch (Throwable e) {
      assertTrue(e instanceof BogusException);
    }
    assertEquals(2, timedMethod.getCount());
  }
View Full Code Here

    assertEquals(2, countedMethod.getCount());
  }

  @Test
  public void quadruplyMeteredMethod() throws Throwable {
    Timer quadruple_Timed = forTimedMethod(metricRegistry, MeteredClass.class, "quadruplyMeteredMethod");
    Meter quadruple_Metered = forMeteredMethod(metricRegistry, MeteredClass.class, "quadruplyMeteredMethod");
    Meter quadruple_ExceptionMetered = forExceptionMeteredMethod(metricRegistry, MeteredClass.class, "quadruplyMeteredMethod");
    final Counter quadruple_Counted = forCountedMethod(metricRegistry, MeteredClass.class, "quadruplyMeteredMethod");

    assertEquals(0, quadruple_Metered.getCount());
    assertEquals(0, quadruple_Timed.getCount());
    assertEquals(0, quadruple_ExceptionMetered.getCount());
    assertEquals(0, quadruple_Counted.getCount());

    // doesn't throw an exception
    meteredClass.quadruplyMeteredMethod(new Runnable() {
      @Override
      public void run() {
        assertEquals(1, quadruple_Counted.getCount());
      }
    });

    assertEquals(1, quadruple_Metered.getCount());
    assertEquals(1, quadruple_Timed.getCount());
    assertEquals(0, quadruple_ExceptionMetered.getCount());
    assertEquals(0, quadruple_Counted.getCount());

    // throws an exception
    try {
      meteredClass.quadruplyMeteredMethod(new Runnable() {
        @Override
        public void run() {
          assertEquals(1, quadruple_Counted.getCount());
          throw new BogusException();
        }
      });
      fail();
    }
    catch (Throwable t) {
      assertTrue(t instanceof BogusException);
    }
    assertEquals(2, quadruple_Metered.getCount());
    assertEquals(2, quadruple_Timed.getCount());
    assertEquals(1, quadruple_ExceptionMetered.getCount());
    assertEquals(0, quadruple_Counted.getCount());
  }
View Full Code Here

    assertEquals(1, varargs.getCount());
  }

  @Test
  public void overloadedTimedMethod() {
    Timer overloaded = metricRegistry.getTimers().get(MetricRegistry.name(MeteredClass.class.getCanonicalName(), "overloaded-timed"));
    Timer overloaded_param = metricRegistry.getTimers().get(MetricRegistry.name(MeteredClass.class.getCanonicalName(), "overloaded-timed-param"));

    assertEquals(0, overloaded.getCount());
    assertEquals(0, overloaded_param.getCount());

    meteredClass.overloadedTimedMethod();

    assertEquals(1, overloaded.getCount());
    assertEquals(0, overloaded_param.getCount());

    meteredClass.overloadedTimedMethod(1);

    assertEquals(1, overloaded.getCount());
    assertEquals(1, overloaded_param.getCount());

    meteredClass.overloadedTimedMethod(1);

    assertEquals(1, overloaded.getCount());
    assertEquals(2, overloaded_param.getCount());
  }
View Full Code Here

        return true;
      }
      if (callStackEveryXRequestsToGroup < 1) {
        return false;
      }
      Timer requestTimer = getRequestTimer();
      if (requestTimer.getCount() == 0) {
        return false;
      }
      return requestTimer.getCount() % callStackEveryXRequestsToGroup == 0;
    }
View Full Code Here

TOP

Related Classes of com.codahale.metrics.Timer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.