in src/main/java/org/apache/sling/commons/metrics/MetricsServiceFactory.java [38:61]
public static MetricsService getMetricsService(Class<?> c) {
if(c == null) {
throw new IllegalArgumentException("Class parameter is required");
}
final Bundle b = FrameworkUtil.getBundle(c);
if(b == null) {
throw new IllegalArgumentException("No BundleContext, Class was not loaded from a Bundle?: "
+ c.getClass().getName());
}
final BundleContext ctx = b.getBundleContext();
// In theory we should unget this reference, but the OSGi framework
// ungets all references held by a bundle when it stops and we cannot
// do much better than that anyway.
final ServiceReference ref = ctx.getServiceReference(MetricsService.class.getName());
if(ref == null) {
throw new IllegalStateException("MetricsService not found for Bundle "
+ b.getSymbolicName());
}
return (MetricsService)ctx.getService(ref);
}