[java-opensaml COMMIT] in /trunk: opensaml-core/src/main/java/org/opensaml/core/metrics/MetricsSupport.java opensaml-...
noreply at shibboleth.net
noreply at shibboleth.net
Sat Nov 5 23:15:32 EDT 2016
Author: putmanb
Date: Sat Nov 5 23:15:32 2016
New Revision: 4564
URL: http://svn.shibboleth.net/view/java-opensaml?rev=4564&view=rev
Log:
OSJ-182: Add Metrics instrumentation to dynamic metadata resolvers
Properly handle case of a null MetricRegistry.
Modified:
trunk/opensaml-core/src/main/java/org/opensaml/core/metrics/MetricsSupport.java
trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynamicMetadataResolver.java
Modified: trunk/opensaml-core/src/main/java/org/opensaml/core/metrics/MetricsSupport.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-core/src/main/java/org/opensaml/core/metrics/MetricsSupport.java?rev=4564&r1=4563&r2=4564&view=diff
==============================================================================
--- trunk/opensaml-core/src/main/java/org/opensaml/core/metrics/MetricsSupport.java (original)
+++ trunk/opensaml-core/src/main/java/org/opensaml/core/metrics/MetricsSupport.java Sat Nov 5 23:15:32 2016
@@ -24,6 +24,8 @@
import com.codahale.metrics.Metric;
import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.Timer;
+import com.codahale.metrics.Timer.Context;
import net.shibboleth.utilities.java.support.logic.Constraint;
@@ -64,7 +66,7 @@
*
* @param <T> the type of metric being registered
*/
- public static <T extends Metric> T register(@Nonnull final String name, @Nonnull final T metric) {
+ @Nullable public static <T extends Metric> T register(@Nonnull final String name, @Nonnull final T metric) {
return register(name, metric, true, null);
}
@@ -82,7 +84,7 @@
*
* @param <T> the type of metric being registered
*/
- public static <T extends Metric> T register(@Nonnull final String name, @Nonnull final T metric,
+ @Nullable public static <T extends Metric> T register(@Nonnull final String name, @Nonnull final T metric,
final boolean replaceExisting) {
return register(name, metric, replaceExisting, null);
}
@@ -99,7 +101,7 @@
*
* @param <T> the type of metric being registered
*/
- public static <T extends Metric> T register(@Nonnull final String name, @Nonnull final T metric,
+ @Nullable public static <T extends Metric> T register(@Nonnull final String name, @Nonnull final T metric,
final boolean replaceExisting, @Nullable final MetricRegistry registry) {
Constraint.isNotNull(name, "Metric name was null");
@@ -226,4 +228,34 @@
Metric registeredMetric = registry.getMetrics().get(name);
return metric == registeredMetric;
}
+
+ /**
+ * Start the specified timer.
+ *
+ * @param timer the timer to start, may be null
+ *
+ * @return the timer context, or null if the input timer was null
+ */
+ @Nullable public static Context startTimer(@Nullable final Timer timer) {
+ if (timer != null) {
+ return timer.time();
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Stop the timer represented by the specified timer context instance.
+ *
+ * @param context the timer context to stop, may be null
+ *
+ * @return the elapsed time in nanoseconds, or null if the input context was null
+ */
+ @Nullable public static Long stopTimer(@Nullable final Context context) {
+ if (context != null) {
+ return context.stop();
+ } else {
+ return null;
+ }
+ }
}
Modified: trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynamicMetadataResolver.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynamicMetadataResolver.java?rev=4564&r1=4563&r2=4564&view=diff
==============================================================================
--- trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynamicMetadataResolver.java (original)
+++ trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynamicMetadataResolver.java Sat Nov 5 23:15:32 2016
@@ -53,6 +53,7 @@
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.RatioGauge;
+import com.codahale.metrics.Timer.Context;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
@@ -480,7 +481,7 @@
ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this);
ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
- com.codahale.metrics.Timer.Context contextResolve = timerResolve.time();
+ Context contextResolve = MetricsSupport.startTimer(timerResolve);
try {
final EntityIdCriterion entityIdCriterion = criteria.get(EntityIdCriterion.class);
if (entityIdCriterion == null || Strings.isNullOrEmpty(entityIdCriterion.getEntityId())) {
@@ -518,9 +519,7 @@
[... 66 lines stripped ...]
More information about the commits
mailing list