use of org.aspectj.lang.reflect.MethodSignature in project micrometer by micrometer-metrics.
the class ScheduledMethodMetrics method timeScheduledOperation.
@Around("execution (@org.springframework.scheduling.annotation.Scheduled * *.*(..))")
public Object timeScheduledOperation(ProceedingJoinPoint pjp) throws Throwable {
Method method = ((MethodSignature) pjp.getSignature()).getMethod();
String signature = pjp.getSignature().toShortString();
if (method.getDeclaringClass().isInterface()) {
try {
method = pjp.getTarget().getClass().getDeclaredMethod(pjp.getSignature().getName(), method.getParameterTypes());
} catch (final SecurityException | NoSuchMethodException e) {
logger.warn("Unable to perform metrics timing on " + signature, e);
return pjp.proceed();
}
}
Timer shortTaskTimer = null;
LongTaskTimer longTaskTimer = null;
for (Timed timed : TimedUtils.findTimedAnnotations(method)) {
if (timed.longTask())
longTaskTimer = LongTaskTimer.builder(timed.value()).tags(timed.extraTags()).description("Timer of @Scheduled long task").register(registry);
else {
Timer.Builder timerBuilder = Timer.builder(timed.value()).tags(timed.extraTags()).description("Timer of @Scheduled task");
if (timed.percentiles().length > 0) {
timerBuilder = timerBuilder.publishPercentiles(timed.percentiles());
}
shortTaskTimer = timerBuilder.register(registry);
}
}
if (shortTaskTimer != null && longTaskTimer != null) {
final Timer finalTimer = shortTaskTimer;
// noinspection NullableProblems
return recordThrowable(longTaskTimer, () -> recordThrowable(finalTimer, pjp::proceed));
} else if (shortTaskTimer != null) {
// noinspection NullableProblems
return recordThrowable(shortTaskTimer, pjp::proceed);
} else if (longTaskTimer != null) {
// noinspection NullableProblems
return recordThrowable(longTaskTimer, pjp::proceed);
}
return pjp.proceed();
}
use of org.aspectj.lang.reflect.MethodSignature in project nextprot-api by calipho-sib.
the class InstrumentationAspect method logDao.
@Around("execution(* org.nextprot.api.*.dao.*.*(..))")
public Object logDao(ProceedingJoinPoint pjp) throws Throwable {
if (enableInstrumentation) {
MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
Annotation[][] annotations = methodSignature.getMethod().getParameterAnnotations();
Object[] arguments = pjp.getArgs();
StringBuilder sb = new StringBuilder();
sb.append("type=DAO;");
addMethodParameters(sb, methodSignature);
addArgumentsParameters(sb, arguments, annotations);
sb.append("DAOId=");
sb.append(daoIdCounter.incrementAndGet());
sb.append(";");
Long sId = serviceRequestId.get();
if (sId != null) {
sb.append("serviceRequestId=");
sb.append(sId);
sb.append(";");
}
Long cId = controllerRequestId.get();
if (cId != null) {
sb.append("controllerRequestId=");
sb.append(cId);
sb.append(";");
}
long start = System.currentTimeMillis();
try {
// LOGGER.info("aspect=before;" + sb);
Object result = pjp.proceed();
addTimeElapsed(sb, System.currentTimeMillis() - start);
addResultParameters(sb, result);
LOGGER.info("aspect=after;" + sb);
return result;
} catch (Exception e) {
addTimeElapsed(sb, System.currentTimeMillis() - start);
addExceptionParameters(sb, e);
LOGGER.info("aspect=after;" + sb);
throw e;
}
} else {
return pjp.proceed();
}
}
use of org.aspectj.lang.reflect.MethodSignature in project nextprot-api by calipho-sib.
the class InstrumentationAspect method logServiceInformaton.
@Around("execution(* org.nextprot.api.*.controller.*.*(..))")
public Object logServiceInformaton(ProceedingJoinPoint pjp) throws Throwable {
if (enableInstrumentation) {
controllerRequestId.set(controllerRequestIdCounter.incrementAndGet());
MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
Annotation[][] annotations = methodSignature.getMethod().getParameterAnnotations();
Object[] arguments = pjp.getArgs();
RequestInfo request = RequestInfoFactory.createRequestInfo(methodSignature.getDeclaringType().getSimpleName() + "#" + methodSignature.getName());
request.putAll(extractSecurityInfo());
request.putAll(extractHttpInfo());
clientRequestManager.startMonitoringClientRequest(request);
StringBuilder sb = new StringBuilder();
sb.append("type=Controller;");
addMethodParameters(sb, methodSignature);
addArgumentsParameters(sb, arguments, annotations);
sb.append("controllerRequestId=");
sb.append(controllerRequestIdCounter.get());
sb.append(";");
for (String key : request.keySet()) {
sb.append(key);
sb.append("=");
sb.append(request.get(key));
sb.append(";");
}
long start = System.currentTimeMillis();
// Proceed to method invocation
try {
// LOGGER.info("aspect=before;" + sb);
Object result = pjp.proceed();
addTimeElapsed(sb, System.currentTimeMillis() - start);
addResultParameters(sb, result);
LOGGER.info("aspect=after;" + sb);
clientRequestManager.stopMonitoringCurrentRequestInfo();
controllerRequestId.remove();
return result;
} catch (Exception e) {
addTimeElapsed(sb, System.currentTimeMillis() - start);
addExceptionParameters(sb, e);
LOGGER.info("aspect=after;" + sb);
clientRequestManager.stopMonitoringCurrentRequestInfo(e);
controllerRequestId.remove();
throw e;
}
} else {
return pjp.proceed();
}
}
use of org.aspectj.lang.reflect.MethodSignature in project rxlib by RockyLOMO.
the class FeignInterceptor method onProcess.
@Override
protected Object onProcess(ProceedingJoinPoint joinPoint, StringBuilder msg) throws Throwable {
Signature signature = joinPoint.getSignature();
if (!(signature instanceof MethodSignature)) {
return joinPoint.proceed();
}
Method method = ((MethodSignature) signature).getMethod();
RequestMapping apiMapping = method.getAnnotation(RequestMapping.class);
if (apiMapping == null) {
return joinPoint.proceed();
}
String url = "";
FeignClient feignClient = null;
for (Class<?> pi : joinPoint.getTarget().getClass().getInterfaces()) {
if ((feignClient = pi.getAnnotation(FeignClient.class)) != null) {
break;
}
}
if (feignClient != null) {
url += feignClient.url();
}
RequestMapping baseMapping = method.getDeclaringClass().getAnnotation(RequestMapping.class);
Function<RequestMapping, String> pf = p -> String.join(",", !ArrayUtils.isEmpty(p.value()) ? p.value() : p.path());
if (baseMapping != null) {
url += pf.apply(baseMapping);
}
url += pf.apply(apiMapping);
String httpMethod = ArrayUtils.isEmpty(apiMapping.method()) ? "POST" : String.join(",", Arrays.stream(apiMapping.method()).map(p -> p.name()).collect(Collectors.toList()));
msg.appendLine().appendLine("%s\t\t%s", httpMethod, resolveUrl(url, signature));
return super.onProcess(joinPoint, msg);
}
use of org.aspectj.lang.reflect.MethodSignature in project rxlib by RockyLOMO.
the class ValidateUtil method onProcess.
/**
* Annotation expression只对method有效
*
* @param joinPoint
* @param msg
* @return
* @throws Throwable
*/
@Override
protected Object onProcess(ProceedingJoinPoint joinPoint, StringBuilder msg) throws Throwable {
Class targetType = joinPoint.getTarget().getClass();
Signature signature = joinPoint.getSignature();
Executable member;
if (signature instanceof ConstructorSignature) {
member = ((ConstructorSignature) signature).getConstructor();
} else {
member = ((MethodSignature) signature).getMethod();
}
msg.setPrefix(String.format("[Valid] %s.%s ", targetType.getSimpleName(), signature.getName()));
EnableValid attr = member.getAnnotation(EnableValid.class);
if (attr == null) {
attr = (EnableValid) targetType.getAnnotation(EnableValid.class);
if (attr == null) {
msg.appendLine("skip validate..");
return joinPoint.proceed();
}
}
int flags = attr.value();
boolean validateValues = hasFlags(flags, EnableValid.ParameterValues);
if (hasFlags(flags, EnableValid.Method)) {
if (signature instanceof ConstructorSignature) {
ConstructorSignature cs = (ConstructorSignature) signature;
validateConstructor(cs.getConstructor(), joinPoint.getArgs(), validateValues);
return super.onProcess(joinPoint, msg);
}
MethodSignature ms = (MethodSignature) signature;
return validateMethod(ms.getMethod(), joinPoint.getTarget(), joinPoint.getArgs(), validateValues, p -> super.onProcess(joinPoint, msg));
}
if (validateValues) {
for (Object parameterValue : joinPoint.getArgs()) {
validateBean(parameterValue);
}
}
msg.appendLine("validate ok..").setPrefix(null);
return super.onProcess(joinPoint, msg);
}
Aggregations