Search in sources :

Example 1 with FallbackMethod

use of com.netflix.hystrix.contrib.javanica.utils.FallbackMethod in project Hystrix by Netflix.

the class HystrixCommandAspect method setFallbackMethod.

private static MetaHolder.Builder setFallbackMethod(MetaHolder.Builder builder, Class<?> declaringClass, Method commandMethod) {
    FallbackMethod fallbackMethod = MethodProvider.getInstance().getFallbackMethod(declaringClass, commandMethod);
    if (fallbackMethod.isPresent()) {
        fallbackMethod.validateReturnType(commandMethod);
        builder.fallbackMethod(fallbackMethod.getMethod()).fallbackExecutionType(ExecutionType.getExecutionType(fallbackMethod.getMethod().getReturnType()));
    }
    return builder;
}
Also used : FallbackMethod(com.netflix.hystrix.contrib.javanica.utils.FallbackMethod)

Example 2 with FallbackMethod

use of com.netflix.hystrix.contrib.javanica.utils.FallbackMethod in project Hystrix by Netflix.

the class HystrixCommandBuilderFactory method createFallbackAction.

private CommandAction createFallbackAction(MetaHolder metaHolder) {
    FallbackMethod fallbackMethod = MethodProvider.getInstance().getFallbackMethod(metaHolder.getObj().getClass(), metaHolder.getMethod(), metaHolder.isExtendedFallback());
    fallbackMethod.validateReturnType(metaHolder.getMethod());
    CommandAction fallbackAction = null;
    if (fallbackMethod.isPresent()) {
        Method fMethod = fallbackMethod.getMethod();
        Object[] args = fallbackMethod.isDefault() ? new Object[0] : metaHolder.getArgs();
        if (fallbackMethod.isCommand()) {
            fMethod.setAccessible(true);
            HystrixCommand hystrixCommand = fMethod.getAnnotation(HystrixCommand.class);
            MetaHolder fmMetaHolder = MetaHolder.builder().obj(metaHolder.getObj()).method(fMethod).ajcMethod(getAjcMethod(metaHolder.getObj(), fMethod)).args(args).fallback(true).defaultFallback(fallbackMethod.isDefault()).defaultCollapserKey(metaHolder.getDefaultCollapserKey()).fallbackMethod(fMethod).extendedFallback(fallbackMethod.isExtended()).fallbackExecutionType(fallbackMethod.getExecutionType()).extendedParentFallback(metaHolder.isExtendedFallback()).observable(ExecutionType.OBSERVABLE == fallbackMethod.getExecutionType()).defaultCommandKey(fMethod.getName()).defaultGroupKey(metaHolder.getDefaultGroupKey()).defaultThreadPoolKey(metaHolder.getDefaultThreadPoolKey()).defaultProperties(metaHolder.getDefaultProperties().orNull()).hystrixCollapser(metaHolder.getHystrixCollapser()).observableExecutionMode(hystrixCommand.observableExecutionMode()).hystrixCommand(hystrixCommand).build();
            fallbackAction = new LazyCommandExecutionAction(fmMetaHolder);
        } else {
            MetaHolder fmMetaHolder = MetaHolder.builder().obj(metaHolder.getObj()).defaultFallback(fallbackMethod.isDefault()).method(fMethod).fallbackExecutionType(ExecutionType.SYNCHRONOUS).extendedFallback(fallbackMethod.isExtended()).extendedParentFallback(metaHolder.isExtendedFallback()).ajcMethod(// if fallback method isn't annotated with command annotation then we don't need to get ajc method for this
            null).args(args).build();
            fallbackAction = new MethodExecutionAction(fmMetaHolder.getObj(), fMethod, fmMetaHolder.getArgs(), fmMetaHolder);
        }
    }
    return fallbackAction;
}
Also used : HystrixCommand(com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand) FallbackMethod(com.netflix.hystrix.contrib.javanica.utils.FallbackMethod) Method(java.lang.reflect.Method) FallbackMethod(com.netflix.hystrix.contrib.javanica.utils.FallbackMethod)

Aggregations

FallbackMethod (com.netflix.hystrix.contrib.javanica.utils.FallbackMethod)2 HystrixCommand (com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand)1 Method (java.lang.reflect.Method)1