/** * Gets fallback method for command method. * * @param enclosingType the enclosing class * @param commandMethod the command method. in the essence it can be a fallback * method annotated with HystrixCommand annotation that has a fallback as well. * @param extended true if the given commandMethod was derived using additional parameter, otherwise - false * @return new instance of {@link FallbackMethod} or {@link FallbackMethod#ABSENT} if there is no suitable fallback method for the given command */ public FallbackMethod getFallbackMethod(Class<?> enclosingType, Method commandMethod, boolean extended) { if (commandMethod.isAnnotationPresent(HystrixCommand.class)) { return FALLBACK_METHOD_FINDER.find(enclosingType, commandMethod, extended); } return FallbackMethod.ABSENT; }
private FallbackMethod doFind(Class<?> enclosingType, Method commandMethod, boolean extended) { String name = getFallbackName(enclosingType, commandMethod); Class<?>[] fallbackParameterTypes = null; if (isDefault()) { fallbackParameterTypes = new Class[0]; } else { fallbackParameterTypes = commandMethod.getParameterTypes(); } if (extended && fallbackParameterTypes[fallbackParameterTypes.length - 1] == Throwable.class) { fallbackParameterTypes = ArrayUtils.remove(fallbackParameterTypes, fallbackParameterTypes.length - 1); } Class<?>[] extendedFallbackParameterTypes = Arrays.copyOf(fallbackParameterTypes, fallbackParameterTypes.length + 1); extendedFallbackParameterTypes[fallbackParameterTypes.length] = Throwable.class; Optional<Method> exFallbackMethod = getMethod(enclosingType, name, extendedFallbackParameterTypes); Optional<Method> fMethod = getMethod(enclosingType, name, fallbackParameterTypes); Method method = exFallbackMethod.or(fMethod).orNull(); if (method == null) { throw new FallbackDefinitionException("fallback method wasn't found: " + name + "(" + Arrays.toString(fallbackParameterTypes) + ")"); } return new FallbackMethod(method, exFallbackMethod.isPresent(), isDefault()); }
private FallbackMethod doFind(Class<?> enclosingType, Method commandMethod, boolean extended) { String name = getFallbackName(enclosingType, commandMethod); Class<?>[] fallbackParameterTypes = null; if (isDefault()) { fallbackParameterTypes = new Class[0]; } else { fallbackParameterTypes = commandMethod.getParameterTypes(); } if (extended && fallbackParameterTypes[fallbackParameterTypes.length - 1] == Throwable.class) { fallbackParameterTypes = ArrayUtils.remove(fallbackParameterTypes, fallbackParameterTypes.length - 1); } Class<?>[] extendedFallbackParameterTypes = Arrays.copyOf(fallbackParameterTypes, fallbackParameterTypes.length + 1); extendedFallbackParameterTypes[fallbackParameterTypes.length] = Throwable.class; Optional<Method> exFallbackMethod = getMethod(enclosingType, name, extendedFallbackParameterTypes); Optional<Method> fMethod = getMethod(enclosingType, name, fallbackParameterTypes); Method method = exFallbackMethod.or(fMethod).orNull(); if (method == null) { throw new FallbackDefinitionException("fallback method wasn't found: " + name + "(" + Arrays.toString(fallbackParameterTypes) + ")"); } return new FallbackMethod(method, exFallbackMethod.isPresent(), isDefault()); }
/** * Gets fallback method for command method. * * @param enclosingType the enclosing class * @param commandMethod the command method. in the essence it can be a fallback * method annotated with HystrixCommand annotation that has a fallback as well. * @param extended true if the given commandMethod was derived using additional parameter, otherwise - false * @return new instance of {@link FallbackMethod} or {@link FallbackMethod#ABSENT} if there is no suitable fallback method for the given command */ public FallbackMethod getFallbackMethod(Class<?> enclosingType, Method commandMethod, boolean extended) { if (commandMethod.isAnnotationPresent(HystrixCommand.class)) { return FALLBACK_METHOD_FINDER.find(enclosingType, commandMethod, extended); } return FallbackMethod.ABSENT; }
public FallbackMethod find(Class<?> enclosingType, Method commandMethod, boolean extended) { if (canHandle(enclosingType, commandMethod)) { return doFind(enclosingType, commandMethod, extended); } else if (next != null) { return next.find(enclosingType, commandMethod, extended); } else { return FallbackMethod.ABSENT; } }
public FallbackMethod find(Class<?> enclosingType, Method commandMethod, boolean extended) { if (canHandle(enclosingType, commandMethod)) { return doFind(enclosingType, commandMethod, extended); } else if (next != null) { return next.find(enclosingType, commandMethod, extended); } else { return FallbackMethod.ABSENT; } }