Search in sources :

Example 1 with Condition

use of org.springframework.context.annotation.Condition in project incubator-dubbo-spring-boot-project by apache.

the class CompatibleOnEnabledEndpointCondition method matches.

@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
    ClassLoader classLoader = context.getClassLoader();
    Condition condition = // Iterate class names
    Stream.of(CONDITION_CLASS_NAMES).filter(// Search class existing or not by name
    className -> ClassUtils.isPresent(className, classLoader)).findFirst().map(// Resolve class name to Class
    className -> ClassUtils.resolveClassName(className, classLoader)).filter(// Accept the Condition implementation
    Condition.class::isAssignableFrom).map(// Instantiate Class to be instance
    BeanUtils::instantiateClass).map(// Cast the instance to be Condition one
    Condition.class::cast).orElse(// Or else get a negative condition
    NegativeCondition.INSTANCE);
    return condition.matches(context, metadata);
}
Also used : Condition(org.springframework.context.annotation.Condition) BeanUtils(org.springframework.beans.BeanUtils)

Example 2 with Condition

use of org.springframework.context.annotation.Condition in project dubbo by alibaba.

the class CompatibleOnEnabledEndpointCondition method matches.

@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
    ClassLoader classLoader = context.getClassLoader();
    if (ClassUtils.isPresent(CONDITION_CLASS_NAME_OLD, classLoader)) {
        Class<?> cls = ClassUtils.resolveClassName(CONDITION_CLASS_NAME_OLD, classLoader);
        if (Condition.class.isAssignableFrom(cls)) {
            Condition condition = Condition.class.cast(BeanUtils.instantiateClass(cls));
            return condition.matches(context, metadata);
        }
    }
    // Check by org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint
    if (ClassUtils.isPresent(CONDITION_CLASS_NAME_NEW, classLoader)) {
        return true;
    }
    // No condition class found
    LOGGER.warn(String.format("No condition class found, Dubbo Health Endpoint [%s] will not expose", metadata));
    return false;
}
Also used : Condition(org.springframework.context.annotation.Condition)

Aggregations

Condition (org.springframework.context.annotation.Condition)2 BeanUtils (org.springframework.beans.BeanUtils)1