Search in sources :

Example 1 with CacheRemove

use of com.netflix.hystrix.contrib.javanica.cache.annotation.CacheRemove in project Hystrix by Netflix.

the class CacheInvocationContextFactoryTest method testCreateCacheRemoveInvocationContext_givenMethodAnnotatedWithCacheRemove_shouldCreateCorrectCacheKeyInvocationContext.

@Test
public void testCreateCacheRemoveInvocationContext_givenMethodAnnotatedWithCacheRemove_shouldCreateCorrectCacheKeyInvocationContext() throws NoSuchMethodException {
    // given
    TestCacheClass testCacheClass = new TestCacheClass();
    String param1 = "val_1";
    MetaHolder metaHolder = MetaHolder.builder().method(TestCacheClass.class.getMethod("cacheRemoveMethod", String.class)).args(new Object[] { param1 }).obj(testCacheClass).build();
    // when
    CacheInvocationContext<CacheRemove> context = CacheInvocationContextFactory.createCacheRemoveInvocationContext(metaHolder);
    // then
    assertNotNull(context.getKeyParameters());
    assertEquals(1, context.getKeyParameters().size());
    CacheInvocationParameter actual = context.getKeyParameters().get(0);
    assertEquals(String.class, actual.getRawType());
    assertEquals(param1, actual.getValue());
    assertEquals(0, actual.getPosition());
}
Also used : CacheRemove(com.netflix.hystrix.contrib.javanica.cache.annotation.CacheRemove) MetaHolder(com.netflix.hystrix.contrib.javanica.command.MetaHolder) Test(org.junit.Test)

Example 2 with CacheRemove

use of com.netflix.hystrix.contrib.javanica.cache.annotation.CacheRemove 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)

Example 3 with CacheRemove

use of com.netflix.hystrix.contrib.javanica.cache.annotation.CacheRemove in project Hystrix by Netflix.

the class HystrixCacheAspect method methodsAnnotatedWithCacheRemove.

@Around("cacheRemoveAnnotationPointcut()")
public Object methodsAnnotatedWithCacheRemove(final ProceedingJoinPoint joinPoint) throws Throwable {
    Method method = getMethodFromTarget(joinPoint);
    Object obj = joinPoint.getTarget();
    Object[] args = joinPoint.getArgs();
    Validate.notNull(method, "failed to get method from joinPoint: %s", joinPoint);
    MetaHolder metaHolder = MetaHolder.builder().args(args).method(method).obj(obj).executionType(ExecutionType.SYNCHRONOUS).ajcMethod(isCompileWeaving() ? getAjcMethodAroundAdvice(obj.getClass(), method) : null).build();
    CacheInvocationContext<CacheRemove> context = CacheInvocationContextFactory.createCacheRemoveInvocationContext(metaHolder);
    HystrixRequestCacheManager.getInstance().clearCache(context);
    return joinPoint.proceed();
}
Also used : CacheRemove(com.netflix.hystrix.contrib.javanica.cache.annotation.CacheRemove) MetaHolder(com.netflix.hystrix.contrib.javanica.command.MetaHolder) Method(java.lang.reflect.Method) Around(org.aspectj.lang.annotation.Around)

Aggregations

CacheRemove (com.netflix.hystrix.contrib.javanica.cache.annotation.CacheRemove)3 MetaHolder (com.netflix.hystrix.contrib.javanica.command.MetaHolder)2 Method (java.lang.reflect.Method)2 MethodExecutionAction (com.netflix.hystrix.contrib.javanica.command.MethodExecutionAction)1 AopUtils.getDeclaredMethod (com.netflix.hystrix.contrib.javanica.utils.AopUtils.getDeclaredMethod)1 Around (org.aspectj.lang.annotation.Around)1 Test (org.junit.Test)1