use of org.aspectj.lang.reflect.MethodSignature in project free-framework by a601942905git.
the class DynamicDataSourceAspect method doAround.
/**
* 在切入点方法执行前后加入逻辑
* @param pjp
*/
@Around("pointCutMethod()")
public Object doAround(ProceedingJoinPoint pjp) {
Object obj = null;
Signature signature = pjp.getSignature();
MethodSignature methodSignature = (MethodSignature) signature;
Object target = pjp.getTarget();
try {
Method method = target.getClass().getMethod(methodSignature.getName(), methodSignature.getParameterTypes());
String methodName = method.getName();
setDataSourceType(methodName);
// 执行目标方法
obj = pjp.proceed();
// 释放当前线程中的资源
DataSourceHolder.removeDataSourceKey();
} catch (NoSuchMethodException e) {
log.error("======>DynamicDataSourceAspect.doAround,NoSuchMethodException:{}", e);
} catch (Throwable throwable) {
log.error("======>DynamicDataSourceAspect.doAround,throwable:{}", throwable);
}
return obj;
}
use of org.aspectj.lang.reflect.MethodSignature in project data-prep by Talend.
the class AsyncAspect method getExecutionId.
private String getExecutionId(ProceedingJoinPoint pjp) {
MethodSignature ms = (MethodSignature) pjp.getSignature();
Method m = ms.getMethod();
final AsyncOperation asyncOperationAnnotation = m.getAnnotation(AsyncOperation.class);
final Class<? extends ExecutionIdGenerator> executionIdGeneratorClass = asyncOperationAnnotation.executionIdGeneratorClass();
try {
return executionIdGeneratorClass.newInstance().getExecutionId(pjp);
} catch (Exception e) {
LOGGER.warn("could not get the async id from {} because {}, fall back to null", pjp.toLongString(), e);
return null;
}
}
use of org.aspectj.lang.reflect.MethodSignature in project data-prep by Talend.
the class AsyncAspect method getResultUrl.
/**
* Return the URL used to get the result of the asynchronous method
* @param pjp pjp the proceeding join point.
* @return the URL used to get the result of the asynchronous method
*/
private AsyncExecutionResult getResultUrl(ProceedingJoinPoint pjp) {
MethodSignature ms = (MethodSignature) pjp.getSignature();
Method m = ms.getMethod();
final AsyncOperation asyncOperationAnnotation = m.getAnnotation(AsyncOperation.class);
Class<? extends ResultUrlGenerator> resultUrlClass = asyncOperationAnnotation.resultUrlGenerator();
final ResultUrlGenerator resultUrlGenerator = applicationContext.getBean(resultUrlClass);
Object[] args = AnnotationUtils.extractAsyncParameter(pjp);
return resultUrlGenerator.generateResultUrl(args);
}
use of org.aspectj.lang.reflect.MethodSignature in project data-prep by Talend.
the class AsyncAspect method executeAsynchronously.
/**
* Return if we need to execute the method asynchronously by calling the conditionalClass definined on the annotation.
* By Default call the AlwaysTrueCondtion
* @param pjp pjp the proceeding join point.
* @return true if we need to execute the method asynchronously. False otherwise
*/
private Boolean executeAsynchronously(ProceedingJoinPoint pjp) {
MethodSignature ms = (MethodSignature) pjp.getSignature();
Method m = ms.getMethod();
final AsyncOperation asyncOperationAnnotation = m.getAnnotation(AsyncOperation.class);
Class<? extends ConditionalTest> conditionalTestGenerator = asyncOperationAnnotation.conditionalClass();
final ConditionalTest conditionalTest = applicationContext.getBean(conditionalTestGenerator);
Object[] args = AnnotationUtils.extractAsyncParameter(pjp);
return conditionalTest.apply(args);
}
use of org.aspectj.lang.reflect.MethodSignature in project data-prep by Talend.
the class AnnotationUtils method getAnnotatedParameterIndex.
/**
* Returns the id of the parameter annotated with <code>annotationClass</code> in all the <code>pjp</code>
* arguments. If multiple parameters hold the annotation, returns the index of the <b>last</b> parameter.
*
* @param pjp The {@link ProceedingJoinPoint} to check for annotation in parameters.
* @param annotationClass The annotation to look for.
* @return The index of the annotated parameter or -1 if not found.
*/
public static int getAnnotatedParameterIndex(ProceedingJoinPoint pjp, Class<? extends Annotation> annotationClass) {
MethodSignature ms = (MethodSignature) pjp.getSignature();
Method m = ms.getMethod();
Annotation[][] pa = m.getParameterAnnotations();
int idParameterIndex = -1;
int i = 0;
for (Annotation[] annotations : pa) {
for (Annotation annotation : annotations) {
if (annotation.annotationType().equals(annotationClass)) {
idParameterIndex = i;
}
}
i++;
}
return idParameterIndex;
}
Aggregations