Java Code Examples for javax.enterprise.inject.spi.AnnotatedMethod#getAnnotation()

The following examples show how to use javax.enterprise.inject.spi.AnnotatedMethod#getAnnotation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultFutureableStrategy.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
protected ExecutorService getOrCreatePool(final InvocationContext ic)
{
    final Method method = ic.getMethod();
    ExecutorService executorService = configByMethod.get(method);
    if (executorService == null)
    {
        final AnnotatedType<?> annotatedType = beanManager.createAnnotatedType(method.getDeclaringClass());
        final AnnotatedMethod<?> annotatedMethod = AnnotatedMethods.findMethod(annotatedType, method);
        final Futureable methodConfig = annotatedMethod.getAnnotation(Futureable.class);
        final ExecutorService instance = manager.find(
                (methodConfig == null ? annotatedType.getAnnotation(Futureable.class) : methodConfig).value());
        configByMethod.putIfAbsent(method, instance);
        executorService = instance;
    }
    return executorService;
}
 
Example 2
Source File: GenericConfig.java    From smallrye-fault-tolerance with Apache License 2.0 5 votes vote down vote up
GenericConfig(Class<X> annotationType, AnnotatedMethod<?> annotatedMethod) {
    this(annotatedMethod.getDeclaringType()
            .getJavaClass(), annotatedMethod.getJavaMember(), annotatedMethod, annotationType,
            annotatedMethod.isAnnotationPresent(annotationType) ? annotatedMethod.getAnnotation(annotationType)
                    : annotatedMethod.getDeclaringType()
                            .getAnnotation(annotationType),
            annotatedMethod.isAnnotationPresent(annotationType) ? ElementType.METHOD : ElementType.TYPE);
}
 
Example 3
Source File: LockSupplierStorage.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
protected LockSupplier getLockSupplier(final InvocationContext ic)
{
    final Method key = ic.getMethod();
    LockSupplier operation = lockSuppliers.get(key);
    if (operation == null)
    {
        final Class declaringClass = key.getDeclaringClass();
        final AnnotatedType<Object> annotatedType = beanManager.createAnnotatedType(declaringClass);
        final AnnotatedMethod<?> annotatedMethod = AnnotatedMethods.findMethod(annotatedType, key);

        Locked config = annotatedMethod.getAnnotation(Locked.class);
        if (config == null)
        {
            config = annotatedType.getAnnotation(Locked.class);
        }
        final Locked.LockFactory factory = config.factory() != Locked.LockFactory.class ?
                Locked.LockFactory.class.cast(
                        beanManager.getReference(beanManager.resolve(
                                beanManager.getBeans(
                                        config.factory())),
                                Locked.LockFactory.class, null)) : this;

        final ReadWriteLock writeLock = factory.newLock(annotatedMethod, config.fair());
        final long timeout = config.timeoutUnit().toMillis(config.timeout());
        final Lock lock = config.operation() == READ ? writeLock.readLock() : writeLock.writeLock();

        if (timeout > 0)
        {
            operation = new LockSupplier()
            {
                @Override
                public Lock get()
                {
                    try
                    {
                        if (!lock.tryLock(timeout, TimeUnit.MILLISECONDS))
                        {
                            throw new IllegalStateException("Can't lock for " + key + " in " + timeout + "ms");
                        }
                    }
                    catch (final InterruptedException e)
                    {
                        Thread.interrupted();
                        throw new IllegalStateException("Locking interrupted", e);
                    }
                    return lock;
                }
            };
        }
        else
        {
            operation = new LockSupplier()
            {
                @Override
                public Lock get()
                {
                    lock.lock();
                    return lock;
                }
            };
        }

        final LockSupplier existing = lockSuppliers.putIfAbsent(key, operation);
        if (existing != null)
        {
            operation = existing;
        }
    }
    return operation;
}
 
Example 4
Source File: InvokerStorage.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 5
Source File: AnnotatedTypeProcessor.java    From ozark with Apache License 2.0 3 votes vote down vote up
private <T> AnnotatedMethod<? super T> getReplacement(AnnotatedType<T> type,
                                                      AnnotatedMethod<? super T> method) {

    boolean isResourceMethod = method.getAnnotation(GET.class) != null ||
        method.getAnnotation(POST.class) != null || method.getAnnotation(PUT.class) != null ||
        method.getAnnotation(HEAD.class) != null || method.getAnnotation(DELETE.class) != null;

    boolean hasControllerAnnotation =
        method.getAnnotation(Controller.class) != null || type.getAnnotation(Controller.class) != null;

    // added to methods to intercept calls with our validation interceptor
    Set<Annotation> markerAnnotations = Collections.singleton(() -> ValidationInterceptorBinding.class);

    // drop Hibernate Validator's marker annotations to skip the native validation
    Predicate<Class> annotationBlacklist = clazz -> isHibernateValidatorMarkerAnnotation(clazz);

    if (isResourceMethod && hasControllerAnnotation) {

        log.log(Level.FINE, "Found controller method: {0}#{1}", new Object[]{
            type.getJavaClass().getName(),
            method.getJavaMember().getName()
        });

        return new AnnotatedMethodWrapper<>(method, markerAnnotations, annotationBlacklist);

    }

    return null;

}