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);
}
}
}
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;
}
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;
}
}
}
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;
}
Aggregations