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;
}
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]));
}
Aggregations