Search in sources :

Example 1 with ExtractorBinding

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

the class MapEventTransformerService method resolve.

/**
 * Resolve a {@link MapEventTransformer} from the
 * specified qualifier annotations.
 * @param annotations  the qualifier annotations to use to create the transformer
 * @param <K>          the type of the keys of the entry to be transformed
 * @param <V>          the type of the values of the entry to be transformed
 * @param <U>          the type of the transformed values
 * @return a {@link MapEventTransformer} from the specified qualifier annotations
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public <K, V, U> MapEventTransformer<K, V, U> resolve(Set<Annotation> annotations) {
    Optional<Annotation> optionalTransformer = annotations.stream().filter((annotation) -> annotation.annotationType().isAnnotationPresent(MapEventTransformerBinding.class)).findFirst();
    Optional<Annotation> optionalExtractor = annotations.stream().filter((annotation) -> annotation.annotationType().isAnnotationPresent(ExtractorBinding.class)).findFirst();
    if (optionalTransformer.isPresent()) {
        final Annotation annotation = optionalTransformer.get();
        final Class<? extends Annotation> annotationType = annotation.annotationType();
        final MapEventTransformerFactory factory = CoherenceAnnotationUtils.getSingleBeanWithAnnotation(this.applicationContext, annotationType);
        return factory.create(annotation);
    } else if (optionalExtractor.isPresent()) {
        // there is one or more ExtractorBinding annotations
        ValueExtractor<Object, Object> extractor = this.extractorFactory.resolve(annotations);
        return new ExtractorEventTransformer(extractor);
    }
    // there are no transformer or extractor annotations.
    return null;
}
Also used : ExtractorEventTransformer(com.tangosol.util.transformer.ExtractorEventTransformer) ExtractorBinding(com.oracle.coherence.spring.annotation.ExtractorBinding) MapEventTransformerBinding(com.oracle.coherence.spring.annotation.MapEventTransformerBinding) MapEventTransformerFactory(com.oracle.coherence.spring.annotation.MapEventTransformerFactory) CoherenceAnnotationUtils(com.oracle.coherence.spring.configuration.support.CoherenceAnnotationUtils) InjectionPoint(org.springframework.beans.factory.InjectionPoint) Set(java.util.Set) List(java.util.List) ValueExtractor(com.tangosol.util.ValueExtractor) MapEventTransformer(com.tangosol.util.MapEventTransformer) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Annotation(java.lang.annotation.Annotation) Optional(java.util.Optional) ExtractorEventTransformer(com.tangosol.util.transformer.ExtractorEventTransformer) MapEventTransformerFactory(com.oracle.coherence.spring.annotation.MapEventTransformerFactory) ValueExtractor(com.tangosol.util.ValueExtractor) Annotation(java.lang.annotation.Annotation)

Example 2 with ExtractorBinding

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

the class NamedTopicConfiguration method getSubscriber.

@SuppressWarnings("unchecked")
@Bean(destroyMethod = "release")
@DependsOn(CoherenceSpringConfiguration.COHERENCE_SERVER_BEAN_NAME)
@Primary
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
<V> Subscriber<V> getSubscriber(InjectionPoint injectionPoint) {
    List<Subscriber.Option> options = new ArrayList<>();
    final MergedAnnotations mergedAnnotations = MergedAnnotations.from(injectionPoint.getAnnotatedElement());
    final MergedAnnotation<SubscriberGroup> mergedSubscribedGroupAnnotation = mergedAnnotations.get(SubscriberGroup.class);
    if (mergedSubscribedGroupAnnotation.isPresent()) {
        String subscribedGroupName = mergedSubscribedGroupAnnotation.synthesize().value();
        if (StringUtils.hasLength(subscribedGroupName)) {
            options.add(Subscriber.Name.of(subscribedGroupName));
        }
    }
    final MergedAnnotation<FilterBinding> mergedFilterBindingAnnotation = mergedAnnotations.get(FilterBinding.class);
    if (mergedFilterBindingAnnotation.isPresent()) {
        Filter filter = this.filterService.getFilter(injectionPoint);
        options.add(Subscriber.Filtered.by(filter));
    }
    final MergedAnnotation<ExtractorBinding> mergedExtractorBindingAnnotation = mergedAnnotations.get(ExtractorBinding.class);
    if (mergedExtractorBindingAnnotation.isPresent()) {
        ValueExtractor extractor = this.extractorService.getExtractor(injectionPoint);
        options.add(Subscriber.Convert.using(extractor));
    }
    NamedTopic<V> topic = getTopicInternal(injectionPoint);
    return options.isEmpty() ? topic.createSubscriber() : topic.createSubscriber(options.toArray(new Subscriber.Option[0]));
}
Also used : ExtractorBinding(com.oracle.coherence.spring.annotation.ExtractorBinding) ArrayList(java.util.ArrayList) SubscriberGroup(com.oracle.coherence.spring.annotation.SubscriberGroup) ValueExtractor(com.tangosol.util.ValueExtractor) FilterBinding(com.oracle.coherence.spring.annotation.FilterBinding) Filter(com.tangosol.util.Filter) Subscriber(com.tangosol.net.topic.Subscriber) MergedAnnotations(org.springframework.core.annotation.MergedAnnotations) DependsOn(org.springframework.context.annotation.DependsOn) Scope(org.springframework.context.annotation.Scope) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Aggregations

ExtractorBinding (com.oracle.coherence.spring.annotation.ExtractorBinding)2 ValueExtractor (com.tangosol.util.ValueExtractor)2 FilterBinding (com.oracle.coherence.spring.annotation.FilterBinding)1 MapEventTransformerBinding (com.oracle.coherence.spring.annotation.MapEventTransformerBinding)1 MapEventTransformerFactory (com.oracle.coherence.spring.annotation.MapEventTransformerFactory)1 SubscriberGroup (com.oracle.coherence.spring.annotation.SubscriberGroup)1 CoherenceAnnotationUtils (com.oracle.coherence.spring.configuration.support.CoherenceAnnotationUtils)1 Subscriber (com.tangosol.net.topic.Subscriber)1 Filter (com.tangosol.util.Filter)1 MapEventTransformer (com.tangosol.util.MapEventTransformer)1 ExtractorEventTransformer (com.tangosol.util.transformer.ExtractorEventTransformer)1 Annotation (java.lang.annotation.Annotation)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 InjectionPoint (org.springframework.beans.factory.InjectionPoint)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 Bean (org.springframework.context.annotation.Bean)1 DependsOn (org.springframework.context.annotation.DependsOn)1