use of org.aspectj.lang.reflect.MethodSignature in project data-prep by Talend.
the class AnnotationUtils method getAnnotatedParameterIndexes.
public static List<Integer> getAnnotatedParameterIndexes(ProceedingJoinPoint pjp, Class<? extends Annotation> annotationClass) {
MethodSignature ms = (MethodSignature) pjp.getSignature();
Method m = ms.getMethod();
Annotation[][] pa = m.getParameterAnnotations();
List<Integer> idParameterIndexes = new ArrayList<>();
int i = 0;
for (Annotation[] annotations : pa) {
for (Annotation annotation : annotations) {
if (annotation.annotationType().equals(annotationClass)) {
idParameterIndexes.add(i);
}
}
i++;
}
return idParameterIndexes;
}
use of org.aspectj.lang.reflect.MethodSignature in project Corgi by kevinYin.
the class AdminLoggerAspect method processLog.
/**
* 执行记录日志的操作
*
* @param jp
* @param adminLog
* @param result
* @throws Exception
*/
private void processLog(JoinPoint jp, AdminLog adminLog, Object result) throws Exception {
MethodSignature ms = (MethodSignature) jp.getSignature();
Method method = ms.getMethod();
// 日志类型,为空时取 MenuResource 的值
String type = adminLog.type();
if (StringUtils.isEmpty(type) && method.isAnnotationPresent(MenuResource.class)) {
MenuResource menuResource = method.getAnnotation(MenuResource.class);
type = menuResource.value();
}
if (doLog(adminLog, result)) {
// 执行结果的信息
String resultMessage = getResultMessage(adminLog, result);
// 参数
String arguments = getArguments(jp, method, adminLog);
// ip
// get admin id from AdminContext
logger.info("参数列表 | admin: {}, type: {}, arguments: {}, result: {}", AdminContext.getAccountId(), type, arguments, resultMessage);
// save log
AdminLogger adminLogger = SpringContextUtil.getBean(AdminLogger.class);
AdminOperationLog log = new AdminOperationLog();
log.setOperationType(type);
log.setResult(resultMessage);
log.setArguments(arguments);
log.setUid(AdminContext.getAccountId());
adminLogger.saveAdminLog(log);
} else {
logger.info("DONT LOG ...............");
}
}
use of org.aspectj.lang.reflect.MethodSignature in project mlib by myshzzx.
the class InvokeStatAspect method recStat.
@Around(value = "@annotation(InvokeStat)", argNames = "pjp, InvokeStat")
public Object recStat(final ProceedingJoinPoint pjp, InvokeStat invokeStat) throws Throwable {
MethodSignature signature = (MethodSignature) pjp.getSignature();
String recKey = StringUtils.isBlank(invokeStat.value()) ? pjp.getTarget().getClass().getSimpleName() + '.' + signature.getName() : invokeStat.value();
Tick tick = Tick.tick();
Object result = pjp.proceed();
long time = tick.nip();
String params = invokeStat.recParams() ? JSON.toJSONString(pjp.getArgs()) : null;
if (invokeStat.writeLog())
log.info("invoke-time-{}: {}ms, params:{}", recKey, time, params);
return result;
}
use of org.aspectj.lang.reflect.MethodSignature in project mlib by myshzzx.
the class PerformanceInspector method inspect.
public Object inspect(final ProceedingJoinPoint pjp) throws Throwable {
MethodSignature signature = (MethodSignature) pjp.getSignature();
InvokeInfo invokeInfo = invokeInfoThreadLocal.get();
boolean isRoot = false;
if (invokeInfo == null) {
invokeInfo = new InvokeInfo();
invokeInfoThreadLocal.set(invokeInfo);
isRoot = true;
}
MutableTriple<Integer, MethodSignature, Long> currInvokeInfo = MutableTriple.of(invokeInfo.currentLevel++, signature, 0L);
invokeInfo.infos.add(currInvokeInfo);
try {
Tick tick = Tick.tick();
Object result = pjp.proceed();
currInvokeInfo.setRight(tick.nip());
return result;
} finally {
invokeInfo.currentLevel--;
if (isRoot) {
for (MutableTriple<Integer, MethodSignature, Long> info : invokeInfo.infos) {
System.out.println(genInfoStr(info));
}
invokeInfoThreadLocal.set(null);
}
}
}
use of org.aspectj.lang.reflect.MethodSignature in project mlib by myshzzx.
the class LocalCacheAspect method getLocalCache.
@Around("local()")
public Object getLocalCache(final ProceedingJoinPoint pjp) throws Throwable {
MethodSignature signature = (MethodSignature) pjp.getSignature();
Method method = pjp.getTarget().getClass().getMethod(signature.getName(), signature.getMethod().getParameterTypes());
Object[] args = pjp.getArgs();
LocalCache conf = method.getAnnotation(LocalCache.class);
Cache<Object, AtomicReference<?>> cache = getCache(method, conf);
if (conf.isMultiKey()) {
// MultiKeyInvokeWrap keyInfo = parseMultiKey(conf.keyExp(), pjp.getTarget(), signature.getMethod(), args);
return null;
} else {
// single key
Object key;
if (StringUtils.isEmpty(conf.keyExp())) {
// 自动生成 key
key = genKey(args);
} else
key = parseSingleKey(conf.keyExp(), method, args);
try {
AtomicReference<?> resultWrapper = cache.get(key, new Callable<AtomicReference<?>>() {
@Override
public AtomicReference<?> call() throws Exception {
try {
return new AtomicReference<>(pjp.proceed());
} catch (Throwable t) {
if (t instanceof Exception)
throw (Exception) t;
else
throw new Exception(t);
}
}
});
return resultWrapper.get();
} catch (ExecutionException | UncheckedExecutionException | ExecutionError e) {
throw e.getCause();
}
}
}
Aggregations