Search in sources :

Example 1 with HystrixCollapser

use of com.netflix.hystrix.contrib.javanica.annotation.HystrixCollapser in project Hystrix by Netflix.

the class HystrixCommandAspect method methodsAnnotatedWithHystrixCommand.

@Around("hystrixCommandAnnotationPointcut() || hystrixCollapserAnnotationPointcut()")
public Object methodsAnnotatedWithHystrixCommand(final ProceedingJoinPoint joinPoint) throws Throwable {
    Method method = getMethodFromTarget(joinPoint);
    Validate.notNull(method, "failed to get method from joinPoint: %s", joinPoint);
    if (method.isAnnotationPresent(HystrixCommand.class) && method.isAnnotationPresent(HystrixCollapser.class)) {
        throw new IllegalStateException("method cannot be annotated with HystrixCommand and HystrixCollapser " + "annotations at the same time");
    }
    MetaHolderFactory metaHolderFactory = META_HOLDER_FACTORY_MAP.get(HystrixPointcutType.of(method));
    MetaHolder metaHolder = metaHolderFactory.create(joinPoint);
    HystrixInvokable invokable = HystrixCommandFactory.getInstance().create(metaHolder);
    ExecutionType executionType = metaHolder.isCollapserAnnotationPresent() ? metaHolder.getCollapserExecutionType() : metaHolder.getExecutionType();
    Object result;
    try {
        if (!metaHolder.isObservable()) {
            result = CommandExecutor.execute(invokable, executionType, metaHolder);
        } else {
            result = executeObservable(invokable, executionType, metaHolder);
        }
    } catch (HystrixBadRequestException e) {
        throw e.getCause();
    } catch (HystrixRuntimeException e) {
        throw hystrixRuntimeExceptionToThrowable(metaHolder, e);
    }
    return result;
}
Also used : HystrixCommand(com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand) HystrixCollapser(com.netflix.hystrix.contrib.javanica.annotation.HystrixCollapser) HystrixBadRequestException(com.netflix.hystrix.exception.HystrixBadRequestException) MetaHolder(com.netflix.hystrix.contrib.javanica.command.MetaHolder) ExecutionType(com.netflix.hystrix.contrib.javanica.command.ExecutionType) HystrixInvokable(com.netflix.hystrix.HystrixInvokable) AopUtils.getDeclaredMethod(com.netflix.hystrix.contrib.javanica.utils.AopUtils.getDeclaredMethod) Method(java.lang.reflect.Method) FallbackMethod(com.netflix.hystrix.contrib.javanica.utils.FallbackMethod) HystrixRuntimeException(com.netflix.hystrix.exception.HystrixRuntimeException) Around(org.aspectj.lang.annotation.Around)

Aggregations

HystrixInvokable (com.netflix.hystrix.HystrixInvokable)1 HystrixCollapser (com.netflix.hystrix.contrib.javanica.annotation.HystrixCollapser)1 HystrixCommand (com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand)1 ExecutionType (com.netflix.hystrix.contrib.javanica.command.ExecutionType)1 MetaHolder (com.netflix.hystrix.contrib.javanica.command.MetaHolder)1 AopUtils.getDeclaredMethod (com.netflix.hystrix.contrib.javanica.utils.AopUtils.getDeclaredMethod)1 FallbackMethod (com.netflix.hystrix.contrib.javanica.utils.FallbackMethod)1 HystrixBadRequestException (com.netflix.hystrix.exception.HystrixBadRequestException)1 HystrixRuntimeException (com.netflix.hystrix.exception.HystrixRuntimeException)1 Method (java.lang.reflect.Method)1 Around (org.aspectj.lang.annotation.Around)1