Search in sources :

Example 1 with CoherenceTopicListener

use of com.oracle.coherence.spring.annotation.CoherenceTopicListener in project coherence-spring by coherence-community.

the class CoherenceTopicListenerPostProcessor method processBean.

private void processBean(final String beanName, final Class<?> targetType) {
    if (!this.nonAnnotatedClasses.contains(targetType) && AnnotationUtils.isCandidateClass(targetType, CoherenceTopicListener.class) && !isSpringContainerClass(targetType)) {
        Map<Method, CoherenceTopicListener> annotatedMethods = null;
        try {
            final MethodIntrospector.MetadataLookup<CoherenceTopicListener> metadataLookup = (method) -> AnnotationUtils.getAnnotation(method, CoherenceTopicListener.class);
            annotatedMethods = MethodIntrospector.selectMethods(targetType, metadataLookup);
        } catch (Throwable ex) {
            // An unresolvable type in a method signature, probably from a lazy bean - let's ignore it.
            if (logger.isDebugEnabled()) {
                logger.debug("Could not resolve methods for bean with name '" + beanName + "'", ex);
            }
        }
        CoherenceTopicListener classAnnotation = AnnotationUtils.getAnnotation(targetType, CoherenceTopicListener.class);
        if (classAnnotation != null) {
            Map<Method, CoherenceTopicListener> notAnnotatedMethods = MethodIntrospector.selectMethods(targetType, (MethodIntrospector.MetadataLookup<CoherenceTopicListener>) (method) -> {
                if (!method.isAnnotationPresent(CoherenceTopicListener.class) && method.getParameterCount() == 1) {
                    return classAnnotation;
                }
                return null;
            });
            annotatedMethods.putAll(notAnnotatedMethods);
        }
        if (CollectionUtils.isEmpty(annotatedMethods)) {
            this.nonAnnotatedClasses.add(targetType);
            if (logger.isTraceEnabled()) {
                logger.trace("No @CoherenceTopicListener annotations found on bean class: " + targetType.getName());
            }
        } else {
            for (Method method : annotatedMethods.keySet()) {
                if (method.getParameterCount() != 1) {
                    throw new IllegalArgumentException("The @CoherenceTopicListener annotated method " + method.getName() + " must have a single argument.");
                }
                this.addTopicListenerCandidate(beanName, method);
            }
            if (logger.isDebugEnabled()) {
                logger.debug(annotatedMethods.size() + " @CoherenceTopicListener methods processed on bean '" + beanName + "': " + annotatedMethods);
            }
        }
    }
}
Also used : AnnotatedElementUtils(org.springframework.core.annotation.AnnotatedElementUtils) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) MethodIntrospector(org.springframework.core.MethodIntrospector) HashMap(java.util.HashMap) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) ArrayList(java.util.ArrayList) Map(java.util.Map) CoherenceEventListener(com.oracle.coherence.spring.event.CoherenceEventListener) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) Method(java.lang.reflect.Method) ScopedProxyUtils(org.springframework.aop.scope.ScopedProxyUtils) CoherenceTopicListener(com.oracle.coherence.spring.annotation.CoherenceTopicListener) ClassUtils(org.springframework.util.ClassUtils) Iterator(java.util.Iterator) BeanFactoryPostProcessor(org.springframework.beans.factory.config.BeanFactoryPostProcessor) AnnotationUtils(org.springframework.core.annotation.AnnotationUtils) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) BeansException(org.springframework.beans.BeansException) List(java.util.List) Component(org.springframework.stereotype.Component) ScopedObject(org.springframework.aop.scope.ScopedObject) CollectionUtils(org.springframework.util.CollectionUtils) AutoProxyUtils(org.springframework.aop.framework.autoproxy.AutoProxyUtils) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) Collections(java.util.Collections) Assert(org.springframework.util.Assert) CoherenceTopicListener(com.oracle.coherence.spring.annotation.CoherenceTopicListener) MethodIntrospector(org.springframework.core.MethodIntrospector) Method(java.lang.reflect.Method)

Aggregations

CoherenceTopicListener (com.oracle.coherence.spring.annotation.CoherenceTopicListener)1 CoherenceEventListener (com.oracle.coherence.spring.event.CoherenceEventListener)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 AutoProxyUtils (org.springframework.aop.framework.autoproxy.AutoProxyUtils)1 ScopedObject (org.springframework.aop.scope.ScopedObject)1 ScopedProxyUtils (org.springframework.aop.scope.ScopedProxyUtils)1 BeansException (org.springframework.beans.BeansException)1 BeanInitializationException (org.springframework.beans.factory.BeanInitializationException)1 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 BeanFactoryPostProcessor (org.springframework.beans.factory.config.BeanFactoryPostProcessor)1