Skip to content

Commit

Permalink
Remove references to deprecated ClassLoadingReporter approach
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed Apr 1, 2020
1 parent ebd7549 commit 28152d2
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@
package io.micronaut.core.reflect;

import io.micronaut.core.util.Toggleable;
import org.slf4j.LoggerFactory;

import static io.micronaut.core.reflect.ClassUtils.CLASS_LOADING_REPORTERS;
import static io.micronaut.core.reflect.ClassUtils.CLASS_LOADING_REPORTER_ENABLED;

/**
* An interface that can be implemented by classes that wish to listen to the classloading requirements for the an application. The {@link #close()} method will be called when the application terminates.
*
* @author graemerocher
* @since 1.0
* @deprecated Replaced by compile time computation
*/
@Deprecated
public interface ClassLoadingReporter extends AutoCloseable, Toggleable {

/**
Expand Down Expand Up @@ -58,7 +56,7 @@ public interface ClassLoadingReporter extends AutoCloseable, Toggleable {
* @return True if it is
*/
static boolean isReportingEnabled() {
return CLASS_LOADING_REPORTER_ENABLED;
return false;
}

/**
Expand All @@ -67,11 +65,6 @@ static boolean isReportingEnabled() {
* @param type The type
*/
static void reportPresent(Class<?> type) {
if (CLASS_LOADING_REPORTER_ENABLED) {
for (ClassLoadingReporter reporter : CLASS_LOADING_REPORTERS) {
reporter.onPresent(type);
}
}
}

/**
Expand All @@ -80,11 +73,6 @@ static void reportPresent(Class<?> type) {
* @param type The type
*/
static void reportBeanPresent(Class<?> type) {
if (CLASS_LOADING_REPORTER_ENABLED) {
for (ClassLoadingReporter reporter : CLASS_LOADING_REPORTERS) {
reporter.onBeanPresent(type);
}
}
}

/**
Expand All @@ -93,26 +81,11 @@ static void reportBeanPresent(Class<?> type) {
* @param type The type
*/
static void reportMissing(String type) {
if (CLASS_LOADING_REPORTER_ENABLED) {
for (ClassLoadingReporter reporter : CLASS_LOADING_REPORTERS) {
reporter.onMissing(type);
}
}
}


/**
* Finish reporting classloading.
*/
static void finish() {
if (CLASS_LOADING_REPORTER_ENABLED) {
for (ClassLoadingReporter classLoadingReporter : ClassUtils.CLASS_LOADING_REPORTERS) {
try {
classLoadingReporter.close();
} catch (Throwable e) {
LoggerFactory.getLogger(ClassLoadingReporter.class).warn("Error reporting classloading with loader [" + classLoadingReporter + "]: " + e.getMessage(), e);
}
}
}
}
}
25 changes: 0 additions & 25 deletions core/src/main/java/io/micronaut/core/reflect/ClassUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import io.micronaut.core.util.ArrayUtils;
import io.micronaut.core.util.CollectionUtils;
import io.micronaut.core.util.StringUtils;
import io.micronaut.core.util.Toggleable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.helpers.NOPLogger;
Expand Down Expand Up @@ -63,9 +62,6 @@ public class ClassUtils {
*/
public static final Logger REFLECTION_LOGGER;

static final List<ClassLoadingReporter> CLASS_LOADING_REPORTERS;
static final boolean CLASS_LOADING_REPORTER_ENABLED;

private static final boolean ENABLE_CLASS_LOADER_LOGGING = Boolean.getBoolean(PROPERTY_MICRONAUT_CLASSLOADER_LOGGING);

static {
Expand Down Expand Up @@ -140,25 +136,6 @@ public class ClassUtils {
BASIC_TYPE_MAP.put(LocalDate.class.getName(), LocalDate.class);
BASIC_TYPE_MAP.put(Instant.class.getName(), Instant.class);
BASIC_TYPE_MAP.put(ZonedDateTime.class.getName(), ZonedDateTime.class);

List<ClassLoadingReporter> reporterList = new ArrayList<>();
try {
ServiceLoader<ClassLoadingReporter> reporters = ServiceLoader.load(ClassLoadingReporter.class);
for (ClassLoadingReporter reporter : reporters) {
if (reporter.isEnabled()) {
reporterList.add(reporter);
}
}
} catch (Throwable e) {
reporterList = Collections.emptyList();
}

CLASS_LOADING_REPORTERS = reporterList;
if (CLASS_LOADING_REPORTERS == Collections.EMPTY_LIST) {
CLASS_LOADING_REPORTER_ENABLED = false;
} else {
CLASS_LOADING_REPORTER_ENABLED = reporterList.stream().anyMatch(Toggleable::isEnabled);
}
}

/**
Expand Down Expand Up @@ -297,14 +274,12 @@ public static Optional<Class> forName(String name, @Nullable ClassLoader classLo
REFLECTION_LOGGER.debug("Attempting to dynamically load class {}", name);
}
Class<?> type = Class.forName(name, true, classLoader);
ClassLoadingReporter.reportPresent(type);
if (REFLECTION_LOGGER.isDebugEnabled()) {
REFLECTION_LOGGER.debug("Successfully loaded class {}", name);
}
return Optional.of(type);
}
} catch (ClassNotFoundException | NoClassDefFoundError e) {
ClassLoadingReporter.reportMissing(name);
if (REFLECTION_LOGGER.isDebugEnabled()) {
REFLECTION_LOGGER.debug("Class {} is not present", name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import io.micronaut.context.processor.ExecutableMethodProcessor;
import io.micronaut.core.convert.ConversionService;
import io.micronaut.core.naming.NameUtils;
import io.micronaut.core.reflect.ClassLoadingReporter;
import io.micronaut.core.reflect.ClassUtils;
import io.micronaut.core.type.Argument;
import io.micronaut.core.util.StringUtils;
Expand Down Expand Up @@ -182,11 +181,6 @@ public void process(BeanDefinition<?> beanDefinition, ExecutableMethod<?, ?> met
}
}

ClassLoadingReporter.reportBeanPresent(method.getReturnType().getType());
for (Class argumentType : method.getArgumentTypes()) {
ClassLoadingReporter.reportBeanPresent(argumentType);
}

String functionPath = resolveFunctionPath(methodName, declaringType, functionName);
availableFunctions.put(functionName, URI.create(functionPath));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import io.micronaut.context.processor.ExecutableMethodProcessor;
import io.micronaut.core.naming.NameUtils;
import io.micronaut.core.reflect.ClassLoadingReporter;
import io.micronaut.core.util.StringUtils;
import io.micronaut.http.MediaType;
import io.micronaut.http.codec.MediaTypeCodec;
Expand Down Expand Up @@ -48,7 +47,6 @@ public class DefaultLocalFunctionRegistry implements ExecutableMethodProcessor<F
private final Map<String, ExecutableMethod<?, ?>> suppliers = new LinkedHashMap<>(1);
private final MediaTypeCodecRegistry decoderRegistry;


/**
* Constructor.
* @param decoders decoders
Expand Down Expand Up @@ -189,34 +187,19 @@ public Collection<MediaTypeCodec> getCodecs() {
}

private void registerSupplier(ExecutableMethod<?, ?> method, String functionId) {
ClassLoadingReporter.reportBeanPresent(method.getReturnType().getType());

suppliers.put(functionId, method);
}

private void registerBiFunction(ExecutableMethod<?, ?> method, String functionId) {
ClassLoadingReporter.reportBeanPresent(method.getReturnType().getType());
for (Class argumentType : method.getArgumentTypes()) {
ClassLoadingReporter.reportBeanPresent(argumentType);
}

biFunctions.put(functionId, method);
}

private void registerConsumer(ExecutableMethod<?, ?> method, String functionId) {
for (Class argumentType : method.getArgumentTypes()) {
ClassLoadingReporter.reportBeanPresent(argumentType);
}

consumers.put(functionId, method);
}

private void registerFunction(ExecutableMethod<?, ?> method, String functionId) {
ClassLoadingReporter.reportBeanPresent(method.getReturnType().getType());
for (Class argumentType : method.getArgumentTypes()) {
ClassLoadingReporter.reportBeanPresent(argumentType);
}

functions.put(functionId, method);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import io.micronaut.core.convert.ConversionService;
import io.micronaut.core.convert.exceptions.ConversionErrorException;
import io.micronaut.core.io.Writable;
import io.micronaut.core.reflect.ClassLoadingReporter;
import io.micronaut.core.reflect.ClassUtils;
import io.micronaut.core.reflect.exception.InvocationException;
import io.micronaut.core.type.Argument;
Expand Down Expand Up @@ -88,10 +87,6 @@ protected void execute(InputStream input, OutputStream output, C context) throws
LocalFunctionRegistry localFunctionRegistry = applicationContext.getBean(LocalFunctionRegistry.class);
ExecutableMethod<Object, Object> method = resolveFunction(localFunctionRegistry, functionName);
Class<?> returnJavaType = method.getReturnType().getType();
if (ClassLoadingReporter.isReportingEnabled()) {
ClassLoadingReporter.reportBeanPresent(returnJavaType);
}

Argument[] requiredArguments = method.getArguments();
int argCount = requiredArguments.length;
Object result;
Expand Down Expand Up @@ -199,8 +194,6 @@ private Object decodeInputArgument(
Argument<?> arg,
InputStream input) {
Class<?> argType = arg.getType();
ClassLoadingReporter.reportBeanPresent(argType);

if (ClassUtils.isJavaLangType(argType)) {
Object converted = doConvertInput(conversionService, arg, input);
if (converted != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import io.micronaut.core.naming.Named;
import io.micronaut.core.order.OrderUtil;
import io.micronaut.core.order.Ordered;
import io.micronaut.core.reflect.ClassLoadingReporter;
import io.micronaut.core.reflect.ClassUtils;
import io.micronaut.core.reflect.GenericTypeUtils;
import io.micronaut.core.reflect.ReflectionUtils;
Expand Down Expand Up @@ -289,7 +288,6 @@ public synchronized BeanContext stop() {

terminating.set(false);
running.set(false);
ClassLoadingReporter.finish();
}
return this;
}
Expand Down

0 comments on commit 28152d2

Please sign in to comment.