Search in sources :

Example 1 with BeanRegistration

use of io.micronaut.context.BeanRegistration in project micronaut-mongodb by micronaut-projects.

the class MongoHealthIndicator method checkRegisteredMongoClient.

private Publisher<HealthResult> checkRegisteredMongoClient(BeanRegistration<MongoClient> registration) {
    MongoClient mongoClient = registration.getBean();
    String databaseName = "mongodb (" + registration.getIdentifier().getName() + ")";
    Flux<Map<String, String>> databasePings = Flux.from(pingMongo(mongoClient)).map(this::getVersionDetails).timeout(Duration.of(10, ChronoUnit.SECONDS)).retry(3);
    return databasePings.map(detail -> buildStatusUp(databaseName, detail)).onErrorResume(throwable -> Flux.just(buildStatusDown(throwable, databaseName)));
}
Also used : Document(org.bson.Document) java.util(java.util) BeanRegistration(io.micronaut.context.BeanRegistration) BeanContext(io.micronaut.context.BeanContext) Publisher(org.reactivestreams.Publisher) BasicDBObject(com.mongodb.BasicDBObject) HealthAggregator(io.micronaut.management.health.aggregator.HealthAggregator) Singleton(jakarta.inject.Singleton) HealthIndicator(io.micronaut.management.health.indicator.HealthIndicator) Collectors(java.util.stream.Collectors) MongoClient(com.mongodb.reactivestreams.client.MongoClient) HealthStatus(io.micronaut.health.HealthStatus) Flux(reactor.core.publisher.Flux) ChronoUnit(java.time.temporal.ChronoUnit) Duration(java.time.Duration) Requires(io.micronaut.context.annotation.Requires) HealthResult(io.micronaut.management.health.indicator.HealthResult) MongoClient(com.mongodb.reactivestreams.client.MongoClient)

Example 2 with BeanRegistration

use of io.micronaut.context.BeanRegistration in project micronaut-core by micronaut-projects.

the class ConstructorInterceptorChain method instantiate.

/**
 * Internal methods that handles the logic of instantiating a bean that has constructor interception applied.
 *
 * @param resolutionContext                         The resolution context
 * @param beanContext                               The bean context
 * @param interceptors                              The interceptors. Can be null and if so should be resolved from the context.
 * @param definition                                The definition
 * @param constructor                               The bean constructor
 * @param additionalProxyConstructorParametersCount The additional proxy constructor parameters count
 * @param parameters                                The resolved parameters
 * @param <T1>                                      The bean type
 * @return The instantiated bean
 * @since 3.0.0
 */
@Internal
@UsedByGeneratedCode
@NonNull
public static <T1> T1 instantiate(@NonNull BeanResolutionContext resolutionContext, @NonNull BeanContext beanContext, @Nullable List<BeanRegistration<Interceptor<T1, T1>>> interceptors, @NonNull BeanDefinition<T1> definition, @NonNull BeanConstructor<T1> constructor, int additionalProxyConstructorParametersCount, @NonNull Object... parameters) {
    if (interceptors == null) {
        final AnnotationMetadataHierarchy hierarchy = new AnnotationMetadataHierarchy(definition.getAnnotationMetadata(), constructor.getAnnotationMetadata());
        final Collection<AnnotationValue<?>> annotationValues = resolveInterceptorValues(hierarchy, InterceptorKind.AROUND_CONSTRUCT);
        final Collection<BeanRegistration<Interceptor<?, ?>>> resolved = ((DefaultBeanContext) beanContext).getBeanRegistrations(resolutionContext, Interceptor.ARGUMENT, Qualifiers.byInterceptorBindingValues(annotationValues));
        interceptors = new ArrayList(resolved);
    }
    final InterceptorRegistry interceptorRegistry = beanContext.getBean(InterceptorRegistry.ARGUMENT);
    final Interceptor<T1, T1>[] resolvedInterceptors = interceptorRegistry.resolveConstructorInterceptors(constructor, interceptors);
    return Objects.requireNonNull(new ConstructorInterceptorChain<T1>(definition, constructor, resolvedInterceptors, additionalProxyConstructorParametersCount, parameters).proceed(), "Constructor interceptor chain illegally returned null for constructor: " + constructor.getDescription());
}
Also used : BeanRegistration(io.micronaut.context.BeanRegistration) AnnotationValue(io.micronaut.core.annotation.AnnotationValue) DefaultBeanContext(io.micronaut.context.DefaultBeanContext) AnnotationMetadataHierarchy(io.micronaut.inject.annotation.AnnotationMetadataHierarchy) Internal(io.micronaut.core.annotation.Internal) NonNull(io.micronaut.core.annotation.NonNull) UsedByGeneratedCode(io.micronaut.core.annotation.UsedByGeneratedCode)

Example 3 with BeanRegistration

use of io.micronaut.context.BeanRegistration in project micronaut-core by micronaut-projects.

the class MethodInterceptorChain method doIntercept.

@SuppressWarnings({ "unchecked", "rawtypes" })
private static <T1> T1 doIntercept(BeanResolutionContext resolutionContext, BeanContext beanContext, BeanDefinition<T1> definition, ExecutableMethod<T1, T1> interceptedMethod, T1 bean, InterceptorKind kind) {
    final AnnotationMetadata annotationMetadata = interceptedMethod.getAnnotationMetadata();
    final Collection<AnnotationValue<?>> binding = resolveInterceptorValues(annotationMetadata, kind);
    final Collection<BeanRegistration<Interceptor<?, ?>>> resolved = ((DefaultBeanContext) beanContext).getBeanRegistrations(resolutionContext, Interceptor.ARGUMENT, Qualifiers.byInterceptorBindingValues(binding));
    final InterceptorRegistry interceptorRegistry = beanContext.getBean(InterceptorRegistry.ARGUMENT);
    final Interceptor[] resolvedInterceptors = interceptorRegistry.resolveInterceptors((ExecutableMethod) interceptedMethod, (Collection) resolved, kind);
    if (ArrayUtils.isNotEmpty(resolvedInterceptors)) {
        final MethodInterceptorChain<T1, T1> chain = new MethodInterceptorChain<T1, T1>(resolvedInterceptors, bean, interceptedMethod, kind);
        return Objects.requireNonNull(chain.proceed(), kind.name() + " interceptor chain illegal returned null for type: " + definition.getBeanType());
    } else {
        return interceptedMethod.invoke(bean);
    }
}
Also used : BeanRegistration(io.micronaut.context.BeanRegistration) AnnotationValue(io.micronaut.core.annotation.AnnotationValue) DefaultBeanContext(io.micronaut.context.DefaultBeanContext) AnnotationMetadata(io.micronaut.core.annotation.AnnotationMetadata)

Aggregations

BeanRegistration (io.micronaut.context.BeanRegistration)3 DefaultBeanContext (io.micronaut.context.DefaultBeanContext)2 AnnotationValue (io.micronaut.core.annotation.AnnotationValue)2 BasicDBObject (com.mongodb.BasicDBObject)1 MongoClient (com.mongodb.reactivestreams.client.MongoClient)1 BeanContext (io.micronaut.context.BeanContext)1 Requires (io.micronaut.context.annotation.Requires)1 AnnotationMetadata (io.micronaut.core.annotation.AnnotationMetadata)1 Internal (io.micronaut.core.annotation.Internal)1 NonNull (io.micronaut.core.annotation.NonNull)1 UsedByGeneratedCode (io.micronaut.core.annotation.UsedByGeneratedCode)1 HealthStatus (io.micronaut.health.HealthStatus)1 AnnotationMetadataHierarchy (io.micronaut.inject.annotation.AnnotationMetadataHierarchy)1 HealthAggregator (io.micronaut.management.health.aggregator.HealthAggregator)1 HealthIndicator (io.micronaut.management.health.indicator.HealthIndicator)1 HealthResult (io.micronaut.management.health.indicator.HealthResult)1 Singleton (jakarta.inject.Singleton)1 Duration (java.time.Duration)1 ChronoUnit (java.time.temporal.ChronoUnit)1 java.util (java.util)1