use of com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand 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;
}
use of com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand 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;
}
Aggregations