Search in sources :

Example 1 with MethodExecutionAction

use of com.netflix.hystrix.contrib.javanica.command.MethodExecutionAction 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)

Example 2 with MethodExecutionAction

use of com.netflix.hystrix.contrib.javanica.command.MethodExecutionAction in project Hystrix by Netflix.

the class CacheInvocationContextFactory method createCacheResultInvocationContext.

/**
     * Create {@link CacheInvocationContext} parametrized with {@link CacheResult} annotation.
     *
     * @param metaHolder the meta holder, see {@link com.netflix.hystrix.contrib.javanica.command.MetaHolder}
     * @return initialized and configured {@link CacheInvocationContext}
     */
public static CacheInvocationContext<CacheResult> createCacheResultInvocationContext(MetaHolder metaHolder) {
    Method method = metaHolder.getMethod();
    if (method.isAnnotationPresent(CacheResult.class)) {
        CacheResult cacheResult = method.getAnnotation(CacheResult.class);
        MethodExecutionAction cacheKeyMethod = createCacheKeyAction(cacheResult.cacheKeyMethod(), metaHolder);
        return new CacheInvocationContext<CacheResult>(cacheResult, cacheKeyMethod, metaHolder.getObj(), method, metaHolder.getArgs());
    }
    return null;
}
Also used : CacheResult(com.netflix.hystrix.contrib.javanica.cache.annotation.CacheResult) AopUtils.getDeclaredMethod(com.netflix.hystrix.contrib.javanica.utils.AopUtils.getDeclaredMethod) Method(java.lang.reflect.Method) MethodExecutionAction(com.netflix.hystrix.contrib.javanica.command.MethodExecutionAction)

Example 3 with MethodExecutionAction

use of com.netflix.hystrix.contrib.javanica.command.MethodExecutionAction in project Hystrix by Netflix.

the class CacheInvocationContextFactory method createCacheRemoveInvocationContext.

/**
     * Create {@link CacheInvocationContext} parametrized with {@link CacheRemove} annotation.
     *
     * @param metaHolder the meta holder, see {@link com.netflix.hystrix.contrib.javanica.command.MetaHolder}
     * @return initialized and configured {@link CacheInvocationContext}
     */
public static CacheInvocationContext<CacheRemove> createCacheRemoveInvocationContext(MetaHolder metaHolder) {
    Method method = metaHolder.getMethod();
    if (method.isAnnotationPresent(CacheRemove.class)) {
        CacheRemove cacheRemove = method.getAnnotation(CacheRemove.class);
        MethodExecutionAction cacheKeyMethod = createCacheKeyAction(cacheRemove.cacheKeyMethod(), metaHolder);
        return new CacheInvocationContext<CacheRemove>(cacheRemove, cacheKeyMethod, metaHolder.getObj(), method, metaHolder.getArgs());
    }
    return null;
}
Also used : CacheRemove(com.netflix.hystrix.contrib.javanica.cache.annotation.CacheRemove) AopUtils.getDeclaredMethod(com.netflix.hystrix.contrib.javanica.utils.AopUtils.getDeclaredMethod) Method(java.lang.reflect.Method) MethodExecutionAction(com.netflix.hystrix.contrib.javanica.command.MethodExecutionAction)

Aggregations

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