private CommandAction createCommandAction(MetaHolder metaHolder) { return new MethodExecutionAction(metaHolder.getObj(), metaHolder.getMethod(), metaHolder.getArgs(), metaHolder); }
/** * Invokes the method. Also private method also can be invoked. * * @return result of execution */ @Override public Object executeWithArgs(ExecutionType executionType, Object[] args) throws CommandActionExecutionException { if(ExecutionType.ASYNCHRONOUS == executionType){ Closure closure = AsyncClosureFactory.getInstance().createClosure(metaHolder, method, object, args); return executeClj(closure.getClosureObj(), closure.getClosureMethod()); } return execute(object, method, args); }
@Override public Object execute(ExecutionType executionType) throws CommandActionExecutionException { return executeWithArgs(executionType, _args); }
private Object executeClj(Object o, Method m, Object... args){ Object result = null; try { m.setAccessible(true); // suppress Java language access result = m.invoke(o, args); } catch (IllegalAccessException e) { propagateCause(e); } catch (InvocationTargetException e) { propagateCause(e); } return result; }
/** * Gets method name to be used to get a key for request caching. * * @return method name */ public String getCacheKeyMethodName() { return cacheKeyMethod != null ? cacheKeyMethod.getMethod().getName() : null; }
public HystrixGeneratedCacheKey generateCacheKey(CacheInvocationContext<? extends Annotation> cacheInvocationContext) throws HystrixCacheKeyGenerationException { MethodExecutionAction cacheKeyMethod = cacheInvocationContext.getCacheKeyMethod(); if (cacheKeyMethod != null) { try { return new DefaultHystrixGeneratedCacheKey((String) cacheKeyMethod.execute(cacheInvocationContext.getExecutionType())); } catch (Throwable throwable) { throw new HystrixCacheKeyGenerationException(throwable); } } else { if (cacheInvocationContext.hasKeyParameters()) { StringBuilder cacheKeyBuilder = new StringBuilder(); for (CacheInvocationParameter parameter : cacheInvocationContext.getKeyParameters()) { CacheKey cacheKey = parameter.getCacheKeyAnnotation(); if (cacheKey != null && StringUtils.isNotBlank(cacheKey.value())) { appendPropertyValue(cacheKeyBuilder, Arrays.asList(StringUtils.split(cacheKey.value(), ".")), parameter.getValue()); } else { cacheKeyBuilder.append(parameter.getValue()); } } return new DefaultHystrixGeneratedCacheKey(cacheKeyBuilder.toString()); } else { return DefaultHystrixGeneratedCacheKey.EMPTY; } } }
/** * Invokes the method. * * @return result of execution */ private Object execute(Object o, Method m, Object... args) throws CommandActionExecutionException { Object result = null; try { m.setAccessible(true); // suppress Java language access if (isCompileWeaving() && metaHolder.getAjcMethod() != null) { result = invokeAjcMethod(metaHolder.getAjcMethod(), o, metaHolder, args); } else { result = m.invoke(o, args); } } catch (IllegalAccessException e) { propagateCause(e); } catch (InvocationTargetException e) { propagateCause(e); } return result; }
/** * Gets method name to be used to get a key for request caching. * * @return method name */ public String getCacheKeyMethodName() { return cacheKeyMethod != null ? cacheKeyMethod.getMethod().getName() : null; }
public HystrixGeneratedCacheKey generateCacheKey(CacheInvocationContext<? extends Annotation> cacheInvocationContext) throws HystrixCacheKeyGenerationException { MethodExecutionAction cacheKeyMethod = cacheInvocationContext.getCacheKeyMethod(); if (cacheKeyMethod != null) { try { return new DefaultHystrixGeneratedCacheKey((String) cacheKeyMethod.execute(cacheInvocationContext.getExecutionType())); } catch (Throwable throwable) { throw new HystrixCacheKeyGenerationException(throwable); } } else { if (cacheInvocationContext.hasKeyParameters()) { StringBuilder cacheKeyBuilder = new StringBuilder(); for (CacheInvocationParameter parameter : cacheInvocationContext.getKeyParameters()) { CacheKey cacheKey = parameter.getCacheKeyAnnotation(); if (cacheKey != null && StringUtils.isNotBlank(cacheKey.value())) { appendPropertyValue(cacheKeyBuilder, Arrays.asList(StringUtils.split(cacheKey.value(), ".")), parameter.getValue()); } else { cacheKeyBuilder.append(parameter.getValue()); } } return new DefaultHystrixGeneratedCacheKey(cacheKeyBuilder.toString()); } else { return DefaultHystrixGeneratedCacheKey.EMPTY; } } }
/** * Invokes the method. Also private method also can be invoked. * * @return result of execution */ @Override public Object executeWithArgs(ExecutionType executionType, Object[] args) throws CommandActionExecutionException { if(ExecutionType.ASYNCHRONOUS == executionType){ Closure closure = AsyncClosureFactory.getInstance().createClosure(metaHolder, method, object, args); return executeClj(closure.getClosureObj(), closure.getClosureMethod()); } return execute(object, method, args); }
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; }
private Object executeClj(Object o, Method m, Object... args){ Object result = null; try { m.setAccessible(true); // suppress Java language access result = m.invoke(o, args); } catch (IllegalAccessException e) { propagateCause(e); } catch (InvocationTargetException e) { propagateCause(e); } return result; }
@Override public Object execute(ExecutionType executionType) throws CommandActionExecutionException { return executeWithArgs(executionType, _args); }
fallbackAction = new MethodExecutionAction(fmMetaHolder.getObj(), fMethod, fmMetaHolder.getArgs(), fmMetaHolder);
/** * Invokes the method. * * @return result of execution */ private Object execute(Object o, Method m, Object... args) throws CommandActionExecutionException { Object result = null; try { m.setAccessible(true); // suppress Java language access if (isCompileWeaving() && metaHolder.getAjcMethod() != null) { result = invokeAjcMethod(metaHolder.getAjcMethod(), o, metaHolder, args); } else { result = m.invoke(o, args); } } catch (IllegalAccessException e) { propagateCause(e); } catch (InvocationTargetException e) { propagateCause(e); } return result; }
private CommandAction createCommandAction(MetaHolder metaHolder) { return new MethodExecutionAction(metaHolder.getObj(), metaHolder.getMethod(), metaHolder.getArgs(), metaHolder); }
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; }
fallbackAction = new MethodExecutionAction(fmMetaHolder.getObj(), fMethod, fmMetaHolder.getArgs(), fmMetaHolder);