package com.codahale.metrics.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
An annotation for marking a method of an annotated object as counted.
Given a method like this:
@Counted(name = "fancyName") public String fancyName(String name) { return "Sir Captain " + name; }
A counter for the defining class with the name fancyName
will be created and each time the #fancyName(String)
method is invoked, the counter will be marked.
Since: 3.1
/**
* An annotation for marking a method of an annotated object as counted.
*
* <p>
* Given a method like this:
* <pre><code>
* {@literal @}Counted(name = "fancyName")
* public String fancyName(String name) {
* return "Sir Captain " + name;
* }
* </code></pre>
* <p>
* A counter for the defining class with the name {@code fancyName} will be created and each time the
* {@code #fancyName(String)} method is invoked, the counter will be marked.
*
* @since 3.1
*/
@Inherited
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.ANNOTATION_TYPE })
public @interface Counted {
Returns: The name of the counter.
/**
* @return The name of the counter.
*/
String name() default "";
Returns: If true
, use the given name as an absolute name. If false
, use the given name relative to the annotated class. When annotating a class, this must be false
.
/**
* @return If {@code true}, use the given name as an absolute name. If {@code false}, use the given name
* relative to the annotated class. When annotating a class, this must be {@code false}.
*/
boolean absolute() default false;
Returns: If false
(default), the counter is decremented when the annotated method returns, counting current invocations of the annotated method. If true
, the counter increases monotonically, counting total invocations of the annotated method.
/**
* @return
* If {@code false} (default), the counter is decremented when the annotated
* method returns, counting current invocations of the annotated method.
* If {@code true}, the counter increases monotonically, counting total
* invocations of the annotated method.
*/
boolean monotonic() default false;
}