CatAopService.java 983 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package com.dianping.cat.aop;
  2. import java.lang.reflect.Method;
  3. import org.aspectj.lang.ProceedingJoinPoint;
  4. import org.aspectj.lang.annotation.Around;
  5. import org.aspectj.lang.annotation.Aspect;
  6. import org.aspectj.lang.reflect.MethodSignature;
  7. import com.dianping.cat.Cat;
  8. import com.dianping.cat.message.Transaction;
  9. @Aspect
  10. public class CatAopService {
  11. @Around(value = "execution(* *.*(..))")
  12. public void aroundMethod(ProceedingJoinPoint pjp) {
  13. MethodSignature joinPointObject = (MethodSignature) pjp.getSignature();
  14. Method method = joinPointObject.getMethod();
  15. boolean flag = method.isAnnotationPresent(CatAnnotation.class);
  16. if (flag) {
  17. Transaction t = Cat.newTransaction("method", method.getName());
  18. try {
  19. pjp.proceed();
  20. t.setSuccessStatus();
  21. t.complete();
  22. } catch (Throwable e) {
  23. t.setStatus(e);
  24. Cat.logError(e);
  25. } finally {
  26. t.complete();
  27. }
  28. } else {
  29. try {
  30. pjp.proceed();
  31. } catch (Throwable e) {
  32. }
  33. }
  34. }
  35. }