<T> void findJobs( @Observes @WithAnnotations({Cron.class}) ProcessAnnotatedType<T> pat, BeanManager beanManager ) { // Ensure we are named otherwise job won't fire as we can't locate it AnnotatedType<?> type = pat.getAnnotatedType(); Class<?> clazz = type.getJavaClass(); CDIUtils.addTypeAnnotation( pat, Named.class, () -> new NamedImpl( "Schedule_" + (id++) ) ); if( type.isAnnotationPresent( Cron.class ) ) { if( Job.class.isAssignableFrom( clazz ) ) { jobClasses.add( clazz ); } else { throw new UnsupportedOperationException( "@Cron on type must implement Job" ); } } else { for( AnnotatedMethod<?> meth: type.getMethods() ) { if( meth.isAnnotationPresent( Cron.class ) ) { jobClasses.add( clazz ); } } } }
/** * Activates the alternatives declared with {@code @Beans} globally for the * application. * <p/> * For every types and every methods of every types declared with * {@link Beans#alternatives()}, the {@code Priority} annotation is added * so that the corresponding alternatives are selected globally for the * entire application. * * @see Beans */ private <T> void alternatives(@Observes @WithAnnotations(Alternative.class) ProcessAnnotatedType<T> pat) { AnnotatedType<T> type = pat.getAnnotatedType(); if (!Arrays.asList(beans.alternatives()).contains(type.getJavaClass())) { // Only select globally the alternatives that are declared with @Beans return; } Set<AnnotatedMethod<? super T>> methods = new HashSet<>(); for (AnnotatedMethod<? super T> method : type.getMethods()) { if (method.isAnnotationPresent(Alternative.class) && !method.isAnnotationPresent(Priority.class)) { methods.add(new AnnotatedMethodDecorator<>(method, PriorityLiteral.of(APPLICATION))); } } if (type.isAnnotationPresent(Alternative.class) && !type.isAnnotationPresent(Priority.class)) { pat.setAnnotatedType(new AnnotatedTypeDecorator<>(type, PriorityLiteral.of(APPLICATION), methods)); } else if (!methods.isEmpty()) { pat.setAnnotatedType(new AnnotatedTypeDecorator<>(type, methods)); } }
/** * Discover all classes that implements HealthCheckProcedure */ public void observeResources(@Observes @WithAnnotations({Health.class}) ProcessAnnotatedType<? extends HealthCheck> event) { AnnotatedType<? extends HealthCheck> annotatedType = event.getAnnotatedType(); Class<? extends HealthCheck> javaClass = annotatedType.getJavaClass(); MicroProfileHealthLogger.ROOT_LOGGER.debugf("Discovered health check procedure %s", javaClass); delegates.add(annotatedType); }
<T> void processAnnotatedType(@Observes @WithAnnotations(EnableSnoopEEClient.class) ProcessAnnotatedType<T> pat) { // workaround for WELD bug revealed by JDK8u60 final ProcessAnnotatedType<T> snoopAnnotated = pat; LOGGER.config(() -> "Found @EnableSnoopEEClient annotated class: " + snoopAnnotated.getAnnotatedType().getJavaClass().getName()); snoopEnabled = true; serviceName = snoopAnnotated.getAnnotatedType().getAnnotation(EnableSnoopEEClient.class).serviceName(); LOGGER.config(() -> "SnoopEE Service name is: " + serviceName); }
void findServiceInterfaces(@Observes @WithAnnotations(ProxyGen.class) ProcessAnnotatedType<?> event, BeanManager beanManager) { AnnotatedType<?> annotatedType = event.getAnnotatedType(); if (annotatedType.isAnnotationPresent(ProxyGen.class) && annotatedType.getJavaClass().isInterface()) { LOGGER.debug("Service interface {0} discovered", annotatedType.getJavaClass()); serviceInterfaces.add(annotatedType.getJavaClass()); } }
public <T> void observeResources(@Observes @WithAnnotations({Health.class}) ProcessAnnotatedType<T> event) { AnnotatedType<T> annotatedType = event.getAnnotatedType(); Class<T> javaClass = annotatedType.getJavaClass(); for (Class<?> intf : javaClass.getInterfaces()) { if (intf.getName().equals(HealthCheck.class.getName())) { log.info(">> Discovered health check procedure " + javaClass); delegates.add(annotatedType); } } }
<T> void processAnnotatedType(@Observes @WithAnnotations(EnableSnoopClient.class) ProcessAnnotatedType<T> pat) { // workaround for WELD bug revealed by JDK8u60 final ProcessAnnotatedType<T> snoopAnnotated = pat; LOGGER.config(() -> "Found @EnableSnoopClient annotated class: " + snoopAnnotated.getAnnotatedType().getJavaClass().getName()); snoopEnabled = true; serviceName = snoopAnnotated.getAnnotatedType().getAnnotation(EnableSnoopClient.class).serviceName(); LOGGER.config(() -> "Snoop Service name is: " + serviceName); }
<T> void processAnnotatedType(@Observes @WithAnnotations({EnableEurekaClient.class}) ProcessAnnotatedType<T> pat) { LOGGER.config(() -> "Found @EnableEurekaClient annotated class: " + pat.getAnnotatedType().getJavaClass().getName()); eurekaEnabled = true; applicationName = pat.getAnnotatedType().getAnnotation(EnableEurekaClient.class).name(); LOGGER.config(() -> "Eureka application name is: " + applicationName); }
public <T> void processAnnotatedType( @Observes @WithAnnotations({ FilterParameters.class, FilterParameter.class }) final ProcessAnnotatedType<T> event) { final AnnotatedType<T> annotatedType = event.getAnnotatedType(); if (annotatedType.isAnnotationPresent(FilterParameters.class)) { final FilterParameters annotation = annotatedType.getAnnotation(FilterParameters.class); addFilterParameters(annotation); } if (annotatedType.isAnnotationPresent(FilterParameter.class)) { // TODO deal with single parameters } }
/** * Looks for {@link MongoClientDefinition} annotation to capture it. * Also Checks if the application contains more than one of these definition */ void detectMongoClientDefinition( @Observes @WithAnnotations(MongoClientDefinition.class) ProcessAnnotatedType<?> pat) { AnnotatedType at = pat.getAnnotatedType(); MongoClientDefinition md = at.getAnnotation(MongoClientDefinition.class); String name = md.name(); if (mongoDef != null) { moreThanOne = true; } else { mongoDef = md; } }
public <T> void observeResources(@WithAnnotations({ Path.class }) @Observes ProcessAnnotatedType<T> event) { AnnotatedType<T> annotatedType = event.getAnnotatedType(); if (!annotatedType.getJavaClass().isInterface()) { this.resources.add(annotatedType.getJavaClass()); } }
public <T> void observeProviders(@WithAnnotations({ Provider.class }) @Observes ProcessAnnotatedType<T> event) { AnnotatedType<T> annotatedType = event.getAnnotatedType(); if (!annotatedType.getJavaClass().isInterface()) { this.providers.add(annotatedType.getJavaClass()); } }
public <T> void processStandaloneController(@WithAnnotations({StandaloneController.class}) @Observes ProcessAnnotatedType<T> event) { LOGGER.info("Processing standalone controller class: {}", event.getAnnotatedType().getJavaClass()); StandaloneController a = event.getAnnotatedType().getJavaClass().getAnnotation(StandaloneController.class); if (a != null && ControllerUtils.useEmbeddedController()) { LOGGER.info("Removing standalone controller class {} from CDI context", event.getAnnotatedType().getJavaClass()); event.veto(); } }
public <T> void processEmbeddedController(@WithAnnotations({EmbeddedController.class}) @Observes ProcessAnnotatedType<T> event) { LOGGER.info("Processing embedded controller class: {}", event.getAnnotatedType().getJavaClass()); EmbeddedController a = event.getAnnotatedType().getJavaClass().getAnnotation(EmbeddedController.class); if (a != null && ControllerUtils.useEmbeddedController() == false) { LOGGER.info("Removing embedded controller class {} from CDI context", event.getAnnotatedType().getJavaClass()); event.veto(); } }
<T> void processAnnotatedTypeWithAnnotations( @Observes @WithAnnotations({ Named.class }) ProcessAnnotatedType<T> pat) { logger.info("scanning type: " + pat.getAnnotatedType().getJavaClass().getName()); processAnnotatedTypeWithAnnotations++; }
public void findObservers(@Observes @WithAnnotations(ObservesReactor.class)ProcessAnnotatedType<?> pat) { discoveredTypes.add(pat.getAnnotatedType()); }
public void collect(@Observes @WithAnnotations(Restifyable.class) ProcessAnnotatedType<?> type) { types.add(type.getAnnotatedType().getJavaClass()); }
private <X> void metricsAnnotations(@Observes @WithAnnotations({ Counted.class, Gauge.class, Metered.class, Timed.class }) ProcessAnnotatedType<X> pat) { AnnotatedTypeDecorator newPAT = new AnnotatedTypeDecorator<>(pat.getAnnotatedType(), METRICS_BINDING); LOGGER.debugf("annotations: %s", newPAT.getAnnotations()); LOGGER.debugf("methods: %s", newPAT.getMethods()); pat.setAnnotatedType(newPAT); }
<T> void processAnnotatedType(@Observes @WithAnnotations(Veto.class) ProcessAnnotatedType<T> pat) { pat.veto(); }
private void importResources(@Observes @WithAnnotations(ImportResource.class) ProcessAnnotatedType<?> pat) { resources.add(pat.getAnnotatedType().getAnnotation(ImportResource.class)); }
private void typeConverters(@Observes @WithAnnotations(Converter.class) ProcessAnnotatedType<?> pat) { converters.add(pat.getAnnotatedType().getJavaClass()); }
private void camelAnnotations(@Observes @WithAnnotations({BeanInject.class, Consume.class, EndpointInject.class, Produce.class, PropertyInject.class}) ProcessAnnotatedType<?> pat) { camelBeans.add(pat.getAnnotatedType()); }
private void consumeBeans(@Observes @WithAnnotations(Consume.class) ProcessAnnotatedType<?> pat) { eagerBeans.add(pat.getAnnotatedType()); }
public void findListeners(@Observes @WithAnnotations({WebListener.class}) ProcessAnnotatedType<? extends ServletContextListener> pat) { listeners.add(pat.getAnnotatedType().getJavaClass()); }
public void findServlets(@Observes @WithAnnotations({WebServlet.class}) ProcessAnnotatedType<? extends HttpServlet> pat) { servlets.add(pat.getAnnotatedType().getJavaClass()); }
public void findFilters(@Observes @WithAnnotations({WebFilter.class}) ProcessAnnotatedType<? extends Filter> pat) { filters.add(pat.getAnnotatedType().getJavaClass()); }
public void findWebSocketServers(@Observes @WithAnnotations(ServerEndpoint.class)ProcessAnnotatedType<?> pat) { endpointClasses.add(pat.getAnnotatedType().getJavaClass()); }
public void watchForRestEndpoints(@Observes @WithAnnotations(Path.class) ProcessAnnotatedType processAnnotatedType) { restEndpointClasses.add(processAnnotatedType.getAnnotatedType().getJavaClass()); }
public void watchForProviders(@Observes @WithAnnotations(Provider.class) ProcessAnnotatedType processAnnotatedType) { providerClasses.add(processAnnotatedType.getAnnotatedType().getJavaClass()); }
private <X> void metricsAnnotations(@Observes @WithAnnotations({CachedGauge.class, Counted.class, ExceptionMetered.class, Gauge.class, Metered.class, Timed.class}) ProcessAnnotatedType<X> pat) { pat.setAnnotatedType(new AnnotatedTypeDecorator<>(pat.getAnnotatedType(), METRICS_BINDING)); }
/** * Replaces the meta data of the {@link ProcessAnnotatedType}. * * <p> * The ProcessAnnotatedType's meta data will be replaced, if the annotated type has one of the following annotations: * <ul> * <li> {@link Stateless} * <li> {@link MessageDriven} * <li> {@link Interceptor} * <li> {@link Singleton} * </ul> * * @param <X> the type of the ProcessAnnotatedType * @param pat the annotated type representing the class being processed */ public <X> void processInjectionTarget(@Observes @WithAnnotations({Stateless.class, MessageDriven.class, Interceptor.class, Singleton.class}) ProcessAnnotatedType<X> pat) { if (pat.getAnnotatedType().isAnnotationPresent(Stateless.class) || pat.getAnnotatedType().isAnnotationPresent(MessageDriven.class)) { modifiyAnnotatedTypeMetadata(pat); } else if (pat.getAnnotatedType().isAnnotationPresent(Interceptor.class)) { processInterceptorDependencies(pat); } else if(pat.getAnnotatedType().isAnnotationPresent(Singleton.class)) { addApplicationScopedAndTransactionalToSingleton(pat); } }