Search in sources :

Example 1 with Priority

use of jakarta.annotation.Priority in project resteasy by resteasy.

the class PriorityComparator method getPriority.

private int getPriority(final Class<?> type) {
    final Class<?> clazz = type.isSynthetic() ? type.getSuperclass() : type;
    final Priority priority = clazz.getAnnotation(Priority.class);
    if (priority != null) {
        return priority.value();
    }
    final Class<?> superType = clazz.getSuperclass();
    return superType == null ? Priorities.USER : getPriority(superType);
}
Also used : Priority(jakarta.annotation.Priority)

Example 2 with Priority

use of jakarta.annotation.Priority in project resteasy by resteasy.

the class PriorityServiceLoader method findClasses.

@SuppressWarnings("unchecked")
private static <S> Holder<S>[] findClasses(final Class<S> type, final ClassLoader cl, final Function<Class<? extends S>, S> constructor) throws IOException {
    final Set<Holder<S>> holders = new TreeSet<>();
    final Enumeration<URL> resources = cl.getResources(PREFIX + type.getName());
    while (resources.hasMoreElements()) {
        final URL url = resources.nextElement();
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), StandardCharsets.UTF_8))) {
            String line;
            while ((line = reader.readLine()) != null) {
                int commentIdx = line.indexOf('#');
                if (commentIdx >= 0) {
                    line = line.substring(0, commentIdx);
                }
                line = line.trim();
                if (line.equals(""))
                    continue;
                try {
                    final Class<S> found = (Class<S>) cl.loadClass(line);
                    final Priority priority = found.getAnnotation(Priority.class);
                    int p = Integer.MAX_VALUE;
                    if (priority != null) {
                        p = priority.value();
                    }
                    holders.add(new Holder<>(found, p, constructor));
                } catch (ClassNotFoundException e) {
                    LogMessages.LOGGER.failedToLoad(e, line);
                }
            }
        } catch (IOException e) {
            LogMessages.LOGGER.failedToLoad(e, url.toString());
        }
    }
    return (Holder<S>[]) holders.toArray(new Holder[0]);
}
Also used : InputStreamReader(java.io.InputStreamReader) Priority(jakarta.annotation.Priority) IOException(java.io.IOException) URL(java.net.URL) TreeSet(java.util.TreeSet) BufferedReader(java.io.BufferedReader)

Example 3 with Priority

use of jakarta.annotation.Priority in project resteasy by resteasy.

the class Utils method getPriority.

public static int getPriority(Class<?> component) {
    component = component.isSynthetic() ? component.getSuperclass() : component;
    Priority priority = component.getAnnotation(Priority.class);
    if (priority == null)
        return Priorities.USER;
    return priority.value();
}
Also used : Priority(jakarta.annotation.Priority)

Example 4 with Priority

use of jakarta.annotation.Priority in project core by weld.

the class ObserverMethodConfiguratorImpl method read.

@Override
public ObserverMethodConfigurator<T> read(Method method) {
    checkArgumentNotNull(method);
    Set<Parameter> eventParameters = Configurators.getAnnotatedParameters(method, Observes.class, ObservesAsync.class);
    checkEventParams(eventParameters, method);
    Parameter eventParameter = eventParameters.iterator().next();
    Observes observesAnnotation = eventParameter.getAnnotation(Observes.class);
    if (observesAnnotation != null) {
        reception(observesAnnotation.notifyObserver());
        transactionPhase(observesAnnotation.during());
    } else {
        reception(eventParameter.getAnnotation(ObservesAsync.class).notifyObserver());
    }
    Priority priority = method.getAnnotation(Priority.class);
    if (priority != null) {
        priority(priority.value());
    }
    beanClass(eventParameter.getDeclaringExecutable().getDeclaringClass());
    observedType(eventParameter.getType());
    qualifiers(Configurators.getQualifiers(eventParameter));
    return this;
}
Also used : Observes(jakarta.enterprise.event.Observes) Priority(jakarta.annotation.Priority) AnnotatedParameter(jakarta.enterprise.inject.spi.AnnotatedParameter) Parameter(java.lang.reflect.Parameter)

Example 5 with Priority

use of jakarta.annotation.Priority in project core by weld.

the class ObserverMethodConfiguratorImpl method read.

@Override
public ObserverMethodConfigurator<T> read(AnnotatedMethod<?> method) {
    checkArgumentNotNull(method);
    Set<AnnotatedParameter<?>> eventParameters = method.getParameters().stream().filter((p) -> p.isAnnotationPresent(Observes.class) || p.isAnnotationPresent(ObservesAsync.class)).collect(Collectors.toSet());
    checkEventParams(eventParameters, method.getJavaMember());
    AnnotatedParameter<?> eventParameter = eventParameters.iterator().next();
    Observes observesAnnotation = eventParameter.getAnnotation(Observes.class);
    if (observesAnnotation != null) {
        reception(observesAnnotation.notifyObserver());
        transactionPhase(observesAnnotation.during());
        async(false);
    } else {
        reception(eventParameter.getAnnotation(ObservesAsync.class).notifyObserver());
        async(true);
    }
    Priority priority = method.getAnnotation(Priority.class);
    if (priority != null) {
        priority(priority.value());
    }
    beanClass(eventParameter.getDeclaringCallable().getDeclaringType().getJavaClass());
    observedType(eventParameter.getBaseType());
    qualifiers(Configurators.getQualifiers(eventParameter));
    return this;
}
Also used : EventLogger(org.jboss.weld.logging.EventLogger) Observes(jakarta.enterprise.event.Observes) ObserverMethodConfigurator(jakarta.enterprise.inject.spi.configurator.ObserverMethodConfigurator) Preconditions.checkArgumentNotNull(org.jboss.weld.util.Preconditions.checkArgumentNotNull) Reception(jakarta.enterprise.event.Reception) ObservesAsync(jakarta.enterprise.event.ObservesAsync) HashSet(java.util.HashSet) AnnotatedMethod(jakarta.enterprise.inject.spi.AnnotatedMethod) Extension(jakarta.enterprise.inject.spi.Extension) AnnotatedParameter(jakarta.enterprise.inject.spi.AnnotatedParameter) Parameter(java.lang.reflect.Parameter) ObserverException(jakarta.enterprise.event.ObserverException) Formats(org.jboss.weld.util.reflection.Formats) Priority(jakarta.annotation.Priority) Method(java.lang.reflect.Method) TransactionPhase(jakarta.enterprise.event.TransactionPhase) SyntheticObserverMethod(org.jboss.weld.event.SyntheticObserverMethod) CovariantTypes(org.jboss.weld.resolution.CovariantTypes) ImmutableSet(org.jboss.weld.util.collections.ImmutableSet) Set(java.util.Set) ObserverMethod(jakarta.enterprise.inject.spi.ObserverMethod) Collectors(java.util.stream.Collectors) EventContext(jakarta.enterprise.inject.spi.EventContext) Type(java.lang.reflect.Type) Annotation(java.lang.annotation.Annotation) Collections(java.util.Collections) ObservesAsync(jakarta.enterprise.event.ObservesAsync) AnnotatedParameter(jakarta.enterprise.inject.spi.AnnotatedParameter) Observes(jakarta.enterprise.event.Observes) Priority(jakarta.annotation.Priority)

Aggregations

Priority (jakarta.annotation.Priority)12 Observes (jakarta.enterprise.event.Observes)6 Extension (jakarta.enterprise.inject.spi.Extension)5 ApplicationScoped (jakarta.enterprise.context.ApplicationScoped)4 Initialized (jakarta.enterprise.context.Initialized)4 Method (java.lang.reflect.Method)4 BeforeDestroyed (jakarta.enterprise.context.BeforeDestroyed)3 Dependent (jakarta.enterprise.context.Dependent)3 AfterBeanDiscovery (jakarta.enterprise.inject.spi.AfterBeanDiscovery)3 AnnotatedParameter (jakarta.enterprise.inject.spi.AnnotatedParameter)3 BeforeBeanDiscovery (jakarta.enterprise.inject.spi.BeforeBeanDiscovery)3 ProcessAnnotatedType (jakarta.enterprise.inject.spi.ProcessAnnotatedType)3 Qualifier (jakarta.inject.Qualifier)3 PLATFORM_AFTER (jakarta.interceptor.Interceptor.Priority.PLATFORM_AFTER)3 PLATFORM_BEFORE (jakarta.interceptor.Interceptor.Priority.PLATFORM_BEFORE)3 Annotation (java.lang.annotation.Annotation)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 LinkedList (java.util.LinkedList)3