Search in sources :

Example 1 with Throttling

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;
}
Also used : Throttling(org.apache.deltaspike.core.api.throttling.Throttling) Method(java.lang.reflect.Method) AnnotatedMethod(javax.enterprise.inject.spi.AnnotatedMethod) Semaphore(java.util.concurrent.Semaphore) Throttled(org.apache.deltaspike.core.api.throttling.Throttled)

Aggregations

Method (java.lang.reflect.Method)1 Semaphore (java.util.concurrent.Semaphore)1 AnnotatedMethod (javax.enterprise.inject.spi.AnnotatedMethod)1 Throttled (org.apache.deltaspike.core.api.throttling.Throttled)1 Throttling (org.apache.deltaspike.core.api.throttling.Throttling)1