use of org.apache.deltaspike.core.api.throttling.Throttling in project deltaspike by apache.
the class InvokerStorage method getOrCreateInvoker.
Invoker getOrCreateInvoker(final InvocationContext ic) {
final Method method = ic.getMethod();
Invoker i = providers.get(method);
if (i == null) {
final Class declaringClass = method.getDeclaringClass();
final AnnotatedType<Object> annotatedType = beanManager.createAnnotatedType(declaringClass);
final AnnotatedMethod<?> annotatedMethod = AnnotatedMethods.findMethod(annotatedType, method);
Throttled config = annotatedMethod.getAnnotation(Throttled.class);
if (config == null) {
config = annotatedType.getAnnotation(Throttled.class);
}
Throttling sharedConfig = annotatedMethod.getAnnotation(Throttling.class);
if (sharedConfig == null) {
sharedConfig = annotatedType.getAnnotation(Throttling.class);
}
final Throttling.SemaphoreFactory factory = sharedConfig != null && sharedConfig.factory() != Throttling.SemaphoreFactory.class ? Throttling.SemaphoreFactory.class.cast(beanManager.getReference(beanManager.resolve(beanManager.getBeans(sharedConfig.factory())), Throttling.SemaphoreFactory.class, null)) : this;
final Semaphore semaphore = factory.newSemaphore(annotatedMethod, sharedConfig != null && !sharedConfig.name().isEmpty() ? sharedConfig.name() : declaringClass.getName(), sharedConfig != null && sharedConfig.fair(), sharedConfig != null ? sharedConfig.permits() : 1);
final long timeout = config.timeoutUnit().toMillis(config.timeout());
final int weigth = config.weight();
i = new Invoker(semaphore, weigth, timeout);
final Invoker existing = providers.putIfAbsent(ic.getMethod(), i);
if (existing != null) {
i = existing;
}
}
return i;
}
Aggregations