[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 22:55:35 EDT 2016
Author: putmanb
Date: Sat Nov 5 22:55:34 2016
New Revision: 4563
URL: http://svn.shibboleth.net/view/java-opensaml?rev=4563&view=rev
Log:
OSJ-182: Add Metrics instrumentation to dynamic metadata resolvers
Update Metrics use in abstract dynamic metadata resolver: Update init and destroy approach
to properly handle issues around component/bean lifecycles and order-of-operations.
Add MetricsSupport methods that are needed to suppor all this.
Added:
trunk/opensaml-core/src/test/java/org/opensaml/core/metrics/
trunk/opensaml-core/src/test/java/org/opensaml/core/metrics/MetricsSupportTest.java (with props)
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=4563&r1=4562&r2=4563&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 22:55:34 2016
@@ -17,11 +17,15 @@
package org.opensaml.core.metrics;
+import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.opensaml.core.config.ConfigurationService;
+import com.codahale.metrics.Metric;
import com.codahale.metrics.MetricRegistry;
+
+import net.shibboleth.utilities.java.support.logic.Constraint;
/**
* Support code for use of metrics.
@@ -46,4 +50,180 @@
return ConfigurationService.get(MetricRegistry.class);
}
+ /**
+ * Register a metric instance under the given name.
+ *
+ * <p>
+ * Any existing instance registered under the given name will be replaced.
+ * The {@link MetricRegistry} on which to operate will be obtained via {@link #getMetricRegistry()}.
+ * </p>
+ *
+ * @param name the name under which to register the metric
+ * @param metric the metric instance to register
+ * @return the metric instance which was registered
+ *
+ * @param <T> the type of metric being registered
+ */
+ public static <T extends Metric> T register(@Nonnull final String name, @Nonnull final T metric) {
+ return register(name, metric, true, null);
+ }
+
+ /**
+ * Register a metric instance under the given name.
+ *
+ * <p>
+ * The {@link MetricRegistry} on which to operate will be obtained via {@link #getMetricRegistry()}.
+ * </p>
+ *
+ * @param name the name under which to register the metric
+ * @param metric the metric instance to register
+ * @param replaceExisting whether or not to replace the existing metric registered under that name
+ * @return the metric instance which was registered
+ *
+ * @param <T> the type of metric being registered
+ */
+ public static <T extends Metric> T register(@Nonnull final String name, @Nonnull final T metric,
+ final boolean replaceExisting) {
+ return register(name, metric, replaceExisting, null);
+ }
+
+ /**
+ * Register a metric instance under the given name.
+ *
+ * @param name the name under which to register the metric
+ * @param metric the metric instance to register
+ * @param replaceExisting whether or not to replace the existing metric registered under that name
+ * @param registry the metric registry on which to operate.
+ * If null, will be obtained via {@link #getMetricRegistry()}.
+ * @return the metric instance which was registered
+ *
+ * @param <T> the type of metric being registered
+ */
+ 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");
+ Constraint.isNotNull(metric, "Metric was null");
+
+ MetricRegistry metricRegistry = registry;
+ if (metricRegistry == null) {
+ metricRegistry = getMetricRegistry();
+ }
+ if (metricRegistry == null) {
+ return null;
+ }
+
+ synchronized (metricRegistry) {
+ try {
+ if (replaceExisting) {
+ metricRegistry.remove(name);
+ }
+ return metricRegistry.register(name, metric);
+ } catch (final IllegalArgumentException e) {
+ // Catch this and try again, just in case something not using this synchronized
+ // method added since we removed above.
+ if (replaceExisting) {
+ metricRegistry.remove(name);
+ return metricRegistry.register(name, metric);
[... 195 lines stripped ...]
More information about the commits
mailing list