use of org.aspectj.lang.reflect.MethodSignature in project spring-cloud-sleuth by spring-cloud.
the class TraceAsyncAspectTest method setup.
@Before
public void setup() throws NoSuchMethodException {
MethodSignature signature = Mockito.mock(MethodSignature.class);
BDDMockito.given(signature.getName()).willReturn("fooBar");
BDDMockito.given(signature.getMethod()).willReturn(TraceAsyncAspectTest.class.getMethod("setup"));
BDDMockito.given(this.point.getSignature()).willReturn(signature);
BDDMockito.given(this.point.getTarget()).willReturn("");
}
use of org.aspectj.lang.reflect.MethodSignature in project spring-cloud-sleuth by spring-cloud.
the class TraceAsyncAspect method getMethod.
private Method getMethod(ProceedingJoinPoint pjp, Object object) {
MethodSignature signature = (MethodSignature) pjp.getSignature();
Method method = signature.getMethod();
return ReflectionUtils.findMethod(object.getClass(), method.getName(), method.getParameterTypes());
}
use of org.aspectj.lang.reflect.MethodSignature in project herd by FINRAOS.
the class StopWatchAdvice method logMethodTime.
/**
* Around advice that logs methods times for all service methods.
*
* @param pjp the proceeding join point.
*
* @return the return value of the method we are advising.
* @throws Throwable if there were any problems executing the method.
*/
@Around("serviceMethods()")
public Object logMethodTime(ProceedingJoinPoint pjp) throws Throwable {
// Get the target class being called.
Class<?> targetClass = pjp.getTarget().getClass();
// Get the target method being called.
MethodSignature targetMethodSignature = (MethodSignature) pjp.getSignature();
Method targetMethod = targetMethodSignature.getMethod();
if (targetMethod.getDeclaringClass().isInterface()) {
// Get the underlying implementation if we are given an interface.
targetMethod = pjp.getTarget().getClass().getMethod(pjp.getSignature().getName(), targetMethod.getParameterTypes());
}
// Only keep a stop watch if the class and method aren't suppressing logging and the log level is info.
if ((AnnotationUtils.findAnnotation(targetClass, SuppressLogging.class) == null) && (AnnotationUtils.findAnnotation(targetMethod, SuppressLogging.class) == null) && (LOGGER.isInfoEnabled())) {
// Start the stop watch.
StopWatch stopWatch = new StopWatch();
stopWatch.start();
// Proceed to the join point (i.e. call the method and let it return).
Object returnValue = pjp.proceed();
// Log the duration.
long durationMilliseconds = stopWatch.getTime();
LOGGER.info("javaMethod=\"{}.{}\" javaMethodDurationTimeInMilliseconds={} javaMethodDurationTimeFormatted=\"{}\"", targetClass.getName(), targetMethodSignature.getName(), durationMilliseconds, HerdDateUtils.formatDuration(durationMilliseconds));
// Return the method return value.
return returnValue;
} else {
// Invoke the method normally.
return pjp.proceed();
}
}
use of org.aspectj.lang.reflect.MethodSignature in project herd by FINRAOS.
the class PublishNotificationMessagesAdvice method publishNotificationMessages.
/**
* Publishes all notification messages stored in the "in-memory" notification message queue.
*
* @param joinPoint the join point
*
* @return the return value of the method at the join point
* @throws Throwable if any errors were encountered
*/
@Around("serviceMethods()")
public Object publishNotificationMessages(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
Method method = methodSignature.getMethod();
boolean publishNotificationMessages = method.isAnnotationPresent(PublishNotificationMessages.class);
// Proceed to the join point (i.e. call the method and let it return).
try {
Object returnValue = joinPoint.proceed();
if (publishNotificationMessages) {
if (LOGGER.isDebugEnabled()) {
// Get the target class being called.
Class<?> targetClass = joinPoint.getTarget().getClass();
LOGGER.debug("Method is initiating notification message publishing. javaMethod=\"{}.{}\" notificationMessageInMemoryQueueSize={}", targetClass.getName(), methodSignature.getName(), notificationMessageInMemoryQueue.size());
}
// Publish all notification messages stored in the "in-memory" notification message queue.
while (!notificationMessageInMemoryQueue.isEmpty()) {
// Get notification message from the "in-memory" queue.
NotificationMessage notificationMessage = notificationMessageInMemoryQueue.remove();
// Publish the message.
try {
notificationMessagePublishingService.publishNotificationMessage(notificationMessage);
} catch (Exception sqsException) {
// On error, add this notification message to the database queue.
try {
notificationMessagePublishingService.addNotificationMessageToDatabaseQueue(notificationMessage);
} catch (Exception dbException) {
// Log the error.
LOGGER.error("Failed to add notification message to the database queue. messageType=\"{}\" messageDestination=\"{}\" messageText={}", notificationMessage.getMessageType(), notificationMessage.getMessageDestination(), notificationMessage.getMessageText(), dbException);
}
}
}
}
return returnValue;
} finally {
// Removes all of the elements from the queue, since the thread might be reused from the thread pool.
if (publishNotificationMessages) {
notificationMessageInMemoryQueue.clear();
}
}
}
use of org.aspectj.lang.reflect.MethodSignature in project herd by FINRAOS.
the class MethodLoggingAdvice method logMethodBeingInvoked.
/**
* Around advice that logs methods being invoked for all DAO operations methods.
*
* @param pjp the proceeding join point.
*
* @return the return value of the method we are advising.
* @throws Throwable if there were any problems executing the method.
*/
@Around("operationsMethods()")
public Object logMethodBeingInvoked(ProceedingJoinPoint pjp) throws Throwable {
// Get the target class being called.
Class<?> targetClass = pjp.getTarget().getClass();
// Get the target method being called.
MethodSignature targetMethodSignature = (MethodSignature) pjp.getSignature();
Method targetMethod = targetMethodSignature.getMethod();
if (targetMethod.getDeclaringClass().isInterface()) {
// Get the underlying implementation if we are given an interface.
targetMethod = pjp.getTarget().getClass().getMethod(pjp.getSignature().getName(), targetMethod.getParameterTypes());
}
// Only log the method if the class and method aren't suppressing logging and the log level is debug.
if ((AnnotationUtils.findAnnotation(targetClass, SuppressLogging.class) == null) && (AnnotationUtils.findAnnotation(targetMethod, SuppressLogging.class) == null) && (LOGGER.isDebugEnabled())) {
LOGGER.debug("javaMethod=\"{}.{}\"", targetClass.getName(), targetMethodSignature.getName());
}
// Proceed to the join point (i.e. call the method and let it return).
return pjp.proceed();
}
Aggregations