Search in sources :

Example 1 with HystrixCachingException

use of com.netflix.hystrix.contrib.javanica.exception.HystrixCachingException in project Hystrix by Netflix.

the class CacheInvocationContextFactory method createCacheKeyAction.

private static MethodExecutionAction createCacheKeyAction(String method, MetaHolder metaHolder) {
    MethodExecutionAction cacheKeyAction = null;
    if (StringUtils.isNotBlank(method)) {
        Method cacheKeyMethod = getDeclaredMethod(metaHolder.getObj().getClass(), method, metaHolder.getMethod().getParameterTypes());
        if (cacheKeyMethod == null) {
            throw new HystrixCachingException("method with name '" + method + "' doesn't exist in class '" + metaHolder.getObj().getClass() + "'");
        }
        if (!cacheKeyMethod.getReturnType().equals(String.class)) {
            throw new HystrixCachingException("return type of cacheKey method must be String. Method: '" + method + "', Class: '" + metaHolder.getObj().getClass() + "'");
        }
        MetaHolder cMetaHolder = MetaHolder.builder().obj(metaHolder.getObj()).method(cacheKeyMethod).args(metaHolder.getArgs()).build();
        cacheKeyAction = new MethodExecutionAction(cMetaHolder.getObj(), cacheKeyMethod, cMetaHolder.getArgs(), cMetaHolder);
    }
    return cacheKeyAction;
}
Also used : HystrixCachingException(com.netflix.hystrix.contrib.javanica.exception.HystrixCachingException) MetaHolder(com.netflix.hystrix.contrib.javanica.command.MetaHolder) MethodExecutionAction(com.netflix.hystrix.contrib.javanica.command.MethodExecutionAction) AopUtils.getDeclaredMethod(com.netflix.hystrix.contrib.javanica.utils.AopUtils.getDeclaredMethod) Method(java.lang.reflect.Method)

Aggregations

MetaHolder (com.netflix.hystrix.contrib.javanica.command.MetaHolder)1 MethodExecutionAction (com.netflix.hystrix.contrib.javanica.command.MethodExecutionAction)1 HystrixCachingException (com.netflix.hystrix.contrib.javanica.exception.HystrixCachingException)1 AopUtils.getDeclaredMethod (com.netflix.hystrix.contrib.javanica.utils.AopUtils.getDeclaredMethod)1 Method (java.lang.reflect.Method)1