/** * Returns the set of qualifying annotations on the given elements. * @param elements the annotated elements. Null elements are ignored. * @return the set of qualifying annotations on the given elements. */ public static Set<Annotation> getQualifiers(AnnotatedElement... elements) { return ANNOS.computeIfAbsent(elements.length == 1 ? elements[0] : new HashSet<>(Arrays.asList(elements)), x -> Arrays.stream(elements) .filter(Objects::nonNull) .map(AnnotatedElement::getAnnotations) .flatMap(Arrays::stream) .filter(anno -> anno.annotationType().isAnnotationPresent(Qualifier.class)) .collect(toSet())); } }
@Override public Baton acquire(String key, final int weight) { final Semaphore semaphore = expiringKeyMap.computeIfAbsent(key, s -> new Semaphore(rule.getConcurrentLimit(), false)); if (semaphore.tryAcquire(weight)) { // TODO the semaphore needs to expire the if never closed return new InMemoryBaton(semaphore, weight); } return new InMemoryBaton(weight); }