Search in sources :

Example 11 with Priority

use of javax.annotation.Priority in project xwiki-platform by xwiki.

the class XWiki method initializeMandatoryDocuments.

/**
 * Ensure that mandatory classes (ie classes XWiki needs to work properly) exist and create them if they don't
 * exist.
 *
 * @param context see {@link XWikiContext}
 */
public void initializeMandatoryDocuments(XWikiContext context) {
    if (context.get("initdone") == null) {
        @SuppressWarnings("deprecation") List<MandatoryDocumentInitializer> initializers = Utils.getComponentList(MandatoryDocumentInitializer.class);
        // Sort the initializers based on priority. Lower priority values are first.
        Collections.sort(initializers, new Comparator<MandatoryDocumentInitializer>() {

            @Override
            public int compare(MandatoryDocumentInitializer left, MandatoryDocumentInitializer right) {
                Priority leftPriority = left.getClass().getAnnotation(Priority.class);
                int leftPriorityValue = leftPriority != null ? leftPriority.value() : MandatoryDocumentInitializer.DEFAULT_PRIORITY;
                Priority rightPriority = right.getClass().getAnnotation(Priority.class);
                int rightPriorityValue = rightPriority != null ? rightPriority.value() : MandatoryDocumentInitializer.DEFAULT_PRIORITY;
                // Compare the two.
                return leftPriorityValue - rightPriorityValue;
            }
        });
        for (MandatoryDocumentInitializer initializer : initializers) {
            initializeMandatoryDocument(initializer, context);
        }
    }
}
Also used : MandatoryDocumentInitializer(com.xpn.xwiki.doc.MandatoryDocumentInitializer) Priority(javax.annotation.Priority)

Example 12 with Priority

use of javax.annotation.Priority in project jsr354-ri-bp by JavaMoney.

the class PriorityServiceComparator method getPriority.

/**
 * Checks the given type optionally annotated with a @Priority. If present the annotation's value is evaluated.
 * If no such annotation is present, a default priority {@code 1} is returned.
 *
 * @param type the type, not {@code null}.
 * @return a priority, by default 1.
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static int getPriority(Class type) {
    int prio = 1;
    Priority priority = (Priority) type.getAnnotation(Priority.class);
    if (priority != null) {
        prio = priority.value();
    }
    return prio;
}
Also used : Priority(javax.annotation.Priority)

Example 13 with Priority

use of javax.annotation.Priority in project Payara by payara.

the class FaultToleranceExtension method determineInterceptorIndex.

static int determineInterceptorIndex(List<Class<?>> interceptorsList, int priority) {
    int index = interceptorsList.size() - 1;
    // Binary search - sometimes another interceptor gets added after the list is sorted (WeldCdi1x), so running
    // backwards through the list under the assumption that most Payara interceptors are registered at
    // PLATFORM_AFTER is not always guaranteed to register this interceptor at the right point.
    int lowIndex = 0;
    int highIndex = interceptorsList.size() - 1;
    while (lowIndex <= highIndex) {
        int midIndex = lowIndex + ((highIndex - lowIndex) / 2);
        Priority priorityAnnotation = interceptorsList.get(midIndex).getAnnotation(Priority.class);
        // If no priority annotation, assume APPLICATION
        int priorityAnnotationValue = priorityAnnotation != null ? priorityAnnotation.value() : javax.interceptor.Interceptor.Priority.APPLICATION;
        // Check for a matching priority value, otherwise determine which way to move the search
        if (priorityAnnotationValue < priority) {
            lowIndex = midIndex + 1;
        } else if (priorityAnnotationValue > priority) {
            highIndex = midIndex - 1;
        } else if (priorityAnnotationValue == priority) {
            index = midIndex;
            break;
        }
    }
    // so just add it at that point
    if (index != interceptorsList.size() - 1) {
        return index;
    } else {
        // found no matching priority
        if (highIndex != interceptorsList.size() - 1) {
            // In either case, we want to use the low index so that we're either before or after it
            return lowIndex;
        } else {
            return interceptorsList.size() - 1;
        }
    }
}
Also used : Priority(javax.annotation.Priority) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint)

Example 14 with Priority

use of javax.annotation.Priority in project Payara by payara.

the class PayaraConfigBuilder method getPriority.

private static int getPriority(Converter<?> converter) {
    int result = 100;
    Priority annotation = converter.getClass().getAnnotation(Priority.class);
    if (annotation != null) {
        result = annotation.value();
    }
    return result;
}
Also used : Priority(javax.annotation.Priority)

Aggregations

Priority (javax.annotation.Priority)14 Annotation (java.lang.annotation.Annotation)2 Parameter (java.lang.reflect.Parameter)2 Observes (javax.enterprise.event.Observes)2 AnnotatedParameter (javax.enterprise.inject.spi.AnnotatedParameter)2 MandatoryDocumentInitializer (com.xpn.xwiki.doc.MandatoryDocumentInitializer)1 Method (java.lang.reflect.Method)1 Type (java.lang.reflect.Type)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 ObserverException (javax.enterprise.event.ObserverException)1 ObservesAsync (javax.enterprise.event.ObservesAsync)1 Reception (javax.enterprise.event.Reception)1 TransactionPhase (javax.enterprise.event.TransactionPhase)1 AnnotatedMethod (javax.enterprise.inject.spi.AnnotatedMethod)1 EventContext (javax.enterprise.inject.spi.EventContext)1 Extension (javax.enterprise.inject.spi.Extension)1 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)1