Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@

package org.springframework.boot.actuate.autoconfigure.metrics;

import java.io.Closeable;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.binder.MeterBinder;
import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics;
import io.micrometer.core.instrument.binder.jvm.JvmCompilationMetrics;
import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics;
Expand All @@ -31,9 +30,6 @@
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
Expand Down Expand Up @@ -103,47 +99,9 @@ public JvmCompilationMetrics jvmCompilationMetrics() {
@ConditionalOnClass(name = VIRTUAL_THREAD_METRICS_CLASS)
@ConditionalOnMissingBean(type = VIRTUAL_THREAD_METRICS_CLASS)
@ImportRuntimeHints(VirtualThreadMetricsRuntimeHintsRegistrar.class)
VirtualThreadMetricsFactoryBean virtualThreadMetrics() {
return new VirtualThreadMetricsFactoryBean();
}

static final class VirtualThreadMetricsFactoryBean
implements FactoryBean<Object>, BeanClassLoaderAware, DisposableBean {

private ClassLoader classLoader;

private Class<?> instanceType;

private Object instance;

@Override
public void setBeanClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader;
}

@Override
public Object getObject() {
if (this.instance == null) {
this.instance = BeanUtils.instantiateClass(getObjectType());
}
return this.instance;
}

@Override
public Class<?> getObjectType() {
if (this.instanceType == null) {
this.instanceType = ClassUtils.resolveClassName(VIRTUAL_THREAD_METRICS_CLASS, this.classLoader);
}
return this.instanceType;
}

@Override
public void destroy() throws Exception {
if (this.instance instanceof Closeable closeable) {
closeable.close();
}
}

MeterBinder virtualThreadMetrics() throws ClassNotFoundException {
Class<?> clazz = ClassUtils.forName(VIRTUAL_THREAD_METRICS_CLASS, getClass().getClassLoader());
return (MeterBinder) BeanUtils.instantiateClass(clazz);
}

static final class VirtualThreadMetricsRuntimeHintsRegistrar implements RuntimeHintsRegistrar {
Expand Down
Loading