Remove unused annotation enhancers

- Remove unncessary annotation enhancers in PulsarListener/PulsarReader
This commit is contained in:
Soby Chacko
2023-02-17 17:38:21 -05:00
parent ba51c23e7d
commit b82128c82c
3 changed files with 2 additions and 49 deletions

View File

@@ -18,7 +18,6 @@ package org.springframework.pulsar.annotation;
import java.io.IOException;
import java.io.StringReader;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
@@ -29,7 +28,6 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.function.BiFunction;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
@@ -90,8 +88,6 @@ public class AbstractPulsarAnnotationsBeanPostProcessor
protected final PulsarHandlerMethodFactoryAdapter messageHandlerMethodFactory = new PulsarHandlerMethodFactoryAdapter();
protected AnnotationEnhancer enhancer;
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
return bean;
@@ -224,24 +220,9 @@ public class AbstractPulsarAnnotationsBeanPostProcessor
}
}
private void buildEnhancer() {
if (this.applicationContext != null) {
List<AnnotationEnhancer> enhancers = this.applicationContext
.getBeanProvider(AnnotationEnhancer.class, false).orderedStream().toList();
if (!enhancers.isEmpty()) {
this.enhancer = (attrs, element) -> {
for (AnnotationEnhancer enh : enhancers) {
attrs = enh.apply(attrs, element);
}
return attrs;
};
}
}
}
@Override
public void afterPropertiesSet() {
buildEnhancer();
// place holder
}
@Override
@@ -427,9 +408,4 @@ public class AbstractPulsarAnnotationsBeanPostProcessor
}
protected interface AnnotationEnhancer
extends BiFunction<Map<String, Object>, AnnotatedElement, Map<String, Object>> {
}
}

View File

@@ -16,7 +16,6 @@
package org.springframework.pulsar.annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
@@ -107,8 +106,6 @@ public class PulsarListenerAnnotationBeanPostProcessor<V> extends AbstractPulsar
private final ListenerScope listenerScope = new ListenerScope();
private AnnotationEnhancer enhancer;
private final AtomicInteger counter = new AtomicInteger();
@Override
@@ -380,24 +377,15 @@ public class PulsarListenerAnnotationBeanPostProcessor<V> extends AbstractPulsar
Set<PulsarListener> listeners = new HashSet<>();
PulsarListener ann = AnnotatedElementUtils.findMergedAnnotation(method, PulsarListener.class);
if (ann != null) {
ann = enhance(method, ann);
listeners.add(ann);
}
PulsarListeners anns = AnnotationUtils.findAnnotation(method, PulsarListeners.class);
if (anns != null) {
listeners.addAll(Arrays.stream(anns.value()).map(anno -> enhance(method, anno)).toList());
listeners.addAll(Arrays.stream(anns.value()).toList());
}
return listeners;
}
private PulsarListener enhance(AnnotatedElement element, PulsarListener ann) {
if (this.enhancer == null) {
return ann;
}
return AnnotationUtils.synthesizeAnnotation(
this.enhancer.apply(AnnotationUtils.getAnnotationAttributes(ann), element), PulsarListener.class, null);
}
private void addFormatters(FormatterRegistry registry) {
this.beanFactory.getBeanProvider(Converter.class).forEach(registry::addConverter);
this.beanFactory.getBeanProvider(GenericConverter.class).forEach(registry::addConverter);

View File

@@ -16,7 +16,6 @@
package org.springframework.pulsar.annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
@@ -35,7 +34,6 @@ import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.context.ApplicationContext;
import org.springframework.core.MethodIntrospector;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.log.LogAccessor;
import org.springframework.lang.Nullable;
import org.springframework.pulsar.config.MethodPulsarReaderEndpoint;
@@ -250,18 +248,9 @@ public class PulsarReaderAnnotationBeanPostProcessor<V> extends AbstractPulsarAn
Set<PulsarReader> readers = new HashSet<>();
PulsarReader ann = AnnotatedElementUtils.findMergedAnnotation(method, PulsarReader.class);
if (ann != null) {
ann = enhance(method, ann);
readers.add(ann);
}
return readers;
}
private PulsarReader enhance(AnnotatedElement element, PulsarReader ann) {
if (this.enhancer == null) {
return ann;
}
return AnnotationUtils.synthesizeAnnotation(
this.enhancer.apply(AnnotationUtils.getAnnotationAttributes(ann), element), PulsarReader.class, null);
}
}