本文整理汇总了Java中javax.annotation.Priority类的典型用法代码示例。如果您正苦于以下问题:Java Priority类的具体用法?Java Priority怎么用?Java Priority使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Priority类属于javax.annotation包,在下文中一共展示了Priority类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: stopWatching
import javax.annotation.Priority; //导入依赖的package包/类
private final void stopWatching(@Observes @BeforeDestroyed(ApplicationScoped.class) @Priority(LIBRARY_BEFORE) final Object event) throws Exception {
final Closeable watch = this.watch;
if (watch != null) {
KubernetesClientException closeException = this.closeException;
try {
watch.close();
} catch (final Exception everything) {
if (closeException != null) {
closeException.addSuppressed(everything);
throw closeException;
} else {
throw everything;
}
}
if (closeException != null) {
throw closeException;
}
}
}
示例2: alternatives
import javax.annotation.Priority; //导入依赖的package包/类
/**
* Activates the alternatives declared with {@code @Beans} globally for the
* application.
* <p/>
* For every types and every methods of every types declared with
* {@link Beans#alternatives()}, the {@code Priority} annotation is added
* so that the corresponding alternatives are selected globally for the
* entire application.
*
* @see Beans
*/
private <T> void alternatives(@Observes @WithAnnotations(Alternative.class) ProcessAnnotatedType<T> pat) {
AnnotatedType<T> type = pat.getAnnotatedType();
if (!Arrays.asList(beans.alternatives()).contains(type.getJavaClass())) {
// Only select globally the alternatives that are declared with @Beans
return;
}
Set<AnnotatedMethod<? super T>> methods = new HashSet<>();
for (AnnotatedMethod<? super T> method : type.getMethods()) {
if (method.isAnnotationPresent(Alternative.class) && !method.isAnnotationPresent(Priority.class)) {
methods.add(new AnnotatedMethodDecorator<>(method, PriorityLiteral.of(APPLICATION)));
}
}
if (type.isAnnotationPresent(Alternative.class) && !type.isAnnotationPresent(Priority.class)) {
pat.setAnnotatedType(new AnnotatedTypeDecorator<>(type, PriorityLiteral.of(APPLICATION), methods));
} else if (!methods.isEmpty()) {
pat.setAnnotatedType(new AnnotatedTypeDecorator<>(type, methods));
}
}
示例3: compareServices
import javax.annotation.Priority; //导入依赖的package包/类
public static int compareServices(Object o1, Object o2) {
int prio1 = 0;
int prio2 = 0;
Priority prio1Annot = o1.getClass().getAnnotation(Priority.class);
if (prio1Annot != null) {
prio1 = prio1Annot.value();
}
Priority prio2Annot = o2.getClass().getAnnotation(Priority.class);
if (prio2Annot != null) {
prio2 = prio2Annot.value();
}
if (prio1 < prio2) {
return 1;
}
if (prio2 < prio1) {
return -1;
}
return o2.getClass().getSimpleName().compareTo(o1.getClass().getSimpleName());
}
示例4: beans
import javax.annotation.Priority; //导入依赖的package包/类
public <X> void beans(
final @Observes ProcessAnnotatedType<X> processBean
) {
if (!processBean.getAnnotatedType().isAnnotationPresent(Interceptor.class)) {
return;
}
final FilteringAnnotatedTypeWrapper<X> filtered = new FilteringAnnotatedTypeWrapper<>(
processBean.getAnnotatedType(),
it -> it != Priority.class
);
processBean.setAnnotatedType(filtered);
}
示例5: getPriority
import javax.annotation.Priority; //导入依赖的package包/类
/**
* The priority of this mapper. By default, it will use the {@link Priority} annotation's value as the priority.
* If no annotation is present, it uses a default priority of {@link Priorities#USER}.
* @return the priority of this mapper
*/
default int getPriority() {
Priority priority = getClass().getAnnotation(Priority.class);
if(priority == null) {
return DEFAULT_PRIORITY;
}
return priority.value();
}
示例6: testAnnotations
import javax.annotation.Priority; //导入依赖的package包/类
@Test
public void testAnnotations() {
// Check that the class is correctly annotated
assertNotNull("@PreMatching annotation is required to modify headers", MediaTypeFilter.class.getAnnotation(PreMatching.class));
Priority priority = MediaTypeFilter.class.getAnnotation(Priority.class);
assertNotNull("@Priority annotation is required to modify headers", priority);
assertTrue("priority should be higher than HEADER_DECORATOR", priority.value() <= Priorities.HEADER_DECORATOR);
}
示例7: find
import javax.annotation.Priority; //导入依赖的package包/类
/**
* Finds view engine for a viewable.
*
* @param viewable the viewable to be used.
* @return selected view engine or {@code null} if none found.
*/
public ViewEngine find(Viewable viewable) {
Optional<ViewEngine> engine;
final String view = viewable.getView();
// If engine specified in viewable, use it
final Class<? extends ViewEngine> engineClass = viewable.getViewEngine();
if (engineClass != null) {
engine = Optional.of(cdiUtils.newBean(engineClass));
} else {
// Check cache first
engine = Optional.ofNullable(cache.get(view));
if (!engine.isPresent()) {
List<ViewEngine> engines = CdiUtils.getApplicationBeans(ViewEngine.class);
// Gather set of candidates
final Set<ViewEngine> candidates = engines.stream()
.filter(e -> e.supports(view)).collect(toSet());
// Find candidate with highest priority
engine = candidates.stream().max(
(e1, e2) -> {
final Priority p1 = getAnnotation(e1.getClass(), Priority.class);
final int v1 = p1 != null ? p1.value() : Priorities.DEFAULT;
final Priority p2 = getAnnotation(e2.getClass(), Priority.class);
final int v2 = p2 != null ? p2.value() : Priorities.DEFAULT;
return v1 - v2;
});
// Update cache
if (engine.isPresent()) {
cache.put(view, engine.get());
}
}
}
return engine.isPresent() ? engine.get() : null;
}
示例8: resolve
import javax.annotation.Priority; //导入依赖的package包/类
public Locale resolve(ContainerRequestContext requestContext) {
// prepare context instance
LocaleResolverContext context = new LocaleResolverContextImpl(configuration, requestContext);
List<LocaleResolver> resolvers = CdiUtils.getApplicationBeans(LocaleResolver.class);
// candidates as sorted list
List<LocaleResolver> candidates = StreamSupport.stream(resolvers.spliterator(), false)
.sorted((resolver1, resolver2) -> {
final Priority prio1 = getAnnotation(resolver1.getClass(), Priority.class);
final Priority prio2 = getAnnotation(resolver2.getClass(), Priority.class);
final int value1 = prio1 != null ? prio1.value() : 1000;
final int value2 = prio2 != null ? prio2.value() : 1000;
return value2 - value1;
})
.collect(Collectors.toList());
// do the resolving
for (LocaleResolver candidate : candidates) {
Locale locale = candidate.resolveLocale(context);
if (locale != null) {
return locale;
}
}
throw new IllegalStateException("Could not resolve locale with any of the " + candidates.size()
+ " resolver implementations");
}
示例9: getPriority
import javax.annotation.Priority; //导入依赖的package包/类
private int getPriority(Converter<?> converter) {
int priority = 100;
Priority priorityAnnotation = converter.getClass().getAnnotation(Priority.class);
if (priorityAnnotation != null) {
priority = priorityAnnotation.value();
}
return priority;
}
示例10: returnPrimaryOrHighestPriorityBean
import javax.annotation.Priority; //导入依赖的package包/类
private Object returnPrimaryOrHighestPriorityBean(List<Bean> beans) {
long highestPriority = Integer.MIN_VALUE;
Object highestPrioBean = null;
for (Bean bean : beans) {
if (bean.isPrimary()) {
return bean.getInstance();
}
// TODO figure out to retrieve order from BeanDefinition /
// BeanDeclaration
Object instance = bean.getInstance();
Order order = instance.getClass().getAnnotation(Order.class);
if (order != null) {
if (order.value() > highestPriority) {
highestPriority = order.value();
highestPrioBean = instance;
}
}
Priority priority = instance.getClass().getAnnotation(Priority.class);
if (priority != null) {
if (priority.value() > highestPriority) {
highestPriority = priority.value();
highestPrioBean = instance;
}
}
}
return highestPrioBean;
}
开发者ID:thomasdarimont,项目名称:spring-boot-cdi-instance-example,代码行数:35,代码来源:CustomAutowireCandidateResolver.java
示例11: compareTo
import javax.annotation.Priority; //导入依赖的package包/类
@Override
public int compareTo(Object o) {
if (!(o instanceof Filter)) return 1;
Priority p1 = this.getClass().getAnnotation(Priority.class);
Priority p2 = o.getClass().getAnnotation(Priority.class);
return (p2 == null ? 0 : p2.value()) - (p1 == null ? 0 : p1.value());
}
示例12: getPriority
import javax.annotation.Priority; //导入依赖的package包/类
/**
* 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;
}
示例13: getPriority
import javax.annotation.Priority; //导入依赖的package包/类
/**
* Checks the given instance for a @Priority annotation. If present the annotation's value is evaluated. If no such
* annotation is present, a default priority of {@code 1} is returned.
* @param o the instance, not {@code null}.
* @return a priority, by default 1.
*/
public static int getPriority(Object o){
int prio = 1; //X TODO discuss default priority
Priority priority = o.getClass().getAnnotation(Priority.class);
if (priority != null) {
prio = priority.value();
}
return prio;
}
示例14: comparePropertyFilters
import javax.annotation.Priority; //导入依赖的package包/类
/**
* Compare 2 filters for ordering the filter chain.
*
* @param filter1 the first filter
* @param filter2 the second filter
* @return the comparison result
*/
private int comparePropertyFilters(PropertyFilter filter1, PropertyFilter filter2) {
Priority prio1 = filter1.getClass().getAnnotation(Priority.class);
Priority prio2 = filter2.getClass().getAnnotation(Priority.class);
int ord1 = prio1 != null ? prio1.value() : 0;
int ord2 = prio2 != null ? prio2.value() : 0;
if (ord1 < ord2) {
return -1;
} else if (ord1 > ord2) {
return 1;
} else {
return filter1.getClass().getName().compareTo(filter2.getClass().getName());
}
}
示例15: getPriority
import javax.annotation.Priority; //导入依赖的package包/类
/**
* 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.
*/
public static int getPriority(Class<? extends Object> type) {
int prio = 1;
Priority priority = type.getAnnotation(Priority.class);
if (priority != null) {
prio = priority.value();
}
return prio;
}