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;
}
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;
}
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;
}
Aggregations