Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…#14).
- Loading branch information
1 parent
61b0712
commit 6f0ac63
Showing
43 changed files
with
2,605 additions
and
2,828 deletions.
There are no files selected for viewing
130 changes: 51 additions & 79 deletions
130
src/main/java/com/ryantenney/metrics/annotation/InjectedMetric.java
100644 → 100755
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,51 @@ | ||
/* | ||
* Copyright 2012 Ryan W Tenney (http://ryan.10e.us) | ||
* and Martello Technologies (http://martellotech.com) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.ryantenney.metrics.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* An annotation requesting that a metric be injected | ||
* <p/> | ||
* Given a field like this: | ||
* <pre><code> | ||
* \@InjectedMetric | ||
* public Meter someTimer; | ||
* </code></pre> | ||
* <p/> | ||
* A meter for the defining class with the name {@code someTimer} will be created. It will be up to the user to mark the meter. This annotation can be used on fields of type Meter, Timer, Counter, and Histogram. | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.FIELD) | ||
public @interface InjectedMetric { | ||
|
||
/** | ||
* The group of the metric. | ||
*/ | ||
String group() default ""; | ||
|
||
/** | ||
* The type of the metric. | ||
*/ | ||
String type() default ""; | ||
|
||
/** | ||
* The name of the metric. | ||
*/ | ||
String name() default ""; | ||
|
||
/** | ||
* The name of the type of events the meter is measuring. | ||
* Applies to Meter | ||
*/ | ||
String eventType() default "calls"; | ||
|
||
/** | ||
* The time unit of the meter's rate. | ||
* Applies to Meter, Timer | ||
*/ | ||
TimeUnit rateUnit() default TimeUnit.SECONDS; | ||
|
||
/** | ||
* The time unit of the timer's duration. | ||
* Applies to Timer | ||
*/ | ||
TimeUnit durationUnit() default TimeUnit.MILLISECONDS; | ||
|
||
/** | ||
* The type of sampling that should be performed. | ||
* Applies to Histogram | ||
*/ | ||
boolean biased() default false; | ||
|
||
} | ||
/* | ||
* Copyright 2012 Ryan W Tenney (http://ryan.10e.us) | ||
* and Martello Technologies (http://martellotech.com) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.ryantenney.metrics.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* An annotation requesting that a metric be injected | ||
* <p/> | ||
* Given a field like this: | ||
* <pre><code> | ||
* \@InjectedMetric | ||
* public Meter someTimer; | ||
* </code></pre> | ||
* <p/> | ||
* A meter for the defining class with the name {@code someTimer} will be created. It will be up to the user to mark the meter. This annotation can be used on fields of type Meter, Timer, Counter, and Histogram. | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.FIELD) | ||
public @interface InjectedMetric { | ||
|
||
/** | ||
* The name of the metric. | ||
*/ | ||
String name() default ""; | ||
|
||
/** | ||
* The name of the type of events the meter is measuring. | ||
* Applies to Meter | ||
*/ | ||
boolean absolute() default false; | ||
|
||
} |
102 changes: 50 additions & 52 deletions
102
src/main/java/com/ryantenney/metrics/spring/ExceptionMeteredAnnotationBeanPostProcessor.java
100644 → 100755
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,50 @@ | ||
/* | ||
* Copyright 2012 Ryan W Tenney (http://ryan.10e.us) | ||
* and Martello Technologies (http://martellotech.com) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.ryantenney.metrics.spring; | ||
|
||
import org.aopalliance.intercept.MethodInterceptor; | ||
import org.springframework.aop.Pointcut; | ||
import org.springframework.aop.framework.ProxyConfig; | ||
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut; | ||
|
||
import com.yammer.metrics.annotation.ExceptionMetered; | ||
import com.yammer.metrics.core.MetricsRegistry; | ||
|
||
public class ExceptionMeteredAnnotationBeanPostProcessor extends AbstractProxyingBeanPostProcessor { | ||
|
||
private static final long serialVersionUID = -1967025297766933304L; | ||
|
||
private final Pointcut pointcut = new AnnotationMatchingPointcut(null, ExceptionMetered.class); | ||
private final MetricsRegistry metrics; | ||
private final String scope; | ||
|
||
public ExceptionMeteredAnnotationBeanPostProcessor(final MetricsRegistry metrics, final ProxyConfig config, final String scope) { | ||
this.metrics = metrics; | ||
this.scope = scope; | ||
|
||
this.copyFrom(config); | ||
} | ||
|
||
@Override | ||
public Pointcut getPointcut() { | ||
return pointcut; | ||
} | ||
|
||
@Override | ||
public MethodInterceptor getMethodInterceptor(Class<?> targetClass) { | ||
return new ExceptionMeteredMethodInterceptor(metrics, targetClass, scope); | ||
} | ||
|
||
} | ||
/* | ||
* Copyright 2012 Ryan W Tenney (http://ryan.10e.us) | ||
* and Martello Technologies (http://martellotech.com) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.ryantenney.metrics.spring; | ||
|
||
import org.aopalliance.intercept.MethodInterceptor; | ||
import org.springframework.aop.Pointcut; | ||
import org.springframework.aop.framework.ProxyConfig; | ||
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut; | ||
|
||
import com.yammer.metrics.annotation.ExceptionMetered; | ||
import com.yammer.metrics.MetricRegistry; | ||
|
||
public class ExceptionMeteredAnnotationBeanPostProcessor extends AbstractProxyingBeanPostProcessor { | ||
|
||
private static final long serialVersionUID = -1967025297766933304L; | ||
|
||
private final Pointcut pointcut = new AnnotationMatchingPointcut(null, ExceptionMetered.class); | ||
private final MetricRegistry metrics; | ||
|
||
public ExceptionMeteredAnnotationBeanPostProcessor(final MetricRegistry metrics, final ProxyConfig config) { | ||
this.metrics = metrics; | ||
|
||
this.copyFrom(config); | ||
} | ||
|
||
@Override | ||
public Pointcut getPointcut() { | ||
return pointcut; | ||
} | ||
|
||
@Override | ||
public MethodInterceptor getMethodInterceptor(Class<?> targetClass) { | ||
return new ExceptionMeteredMethodInterceptor(metrics, targetClass); | ||
} | ||
|
||
} |
Oops, something went wrong.