コード例 #1
0
 @Around("execution (@org.springframework.scheduling.annotation.Scheduled  * *.*(..))")
 public Object traceBackgroundThread(final ProceedingJoinPoint pjp) throws Throwable {
   Trace trace = this.tracer.startTrace(pjp.toShortString());
   try {
     return pjp.proceed();
   } finally {
     this.tracer.close(trace);
   }
 }
コード例 #2
0
  @Around("within(@org.springframework.stereotype.Repository *)")
  public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable {
    if (this.enabled) {
      StopWatch sw = new StopWatch(joinPoint.toShortString());

      sw.start("invoke");
      try {
        return joinPoint.proceed();
      } finally {
        sw.stop();
        synchronized (this) {
          this.callCount++;
          this.accumulatedCallTime += sw.getTotalTimeMillis();
        }
      }
    } else {
      return joinPoint.proceed();
    }
  }
コード例 #3
0
 public Object profile(ProceedingJoinPoint pjp) throws Throwable {
   StopWatch stopWatch = new StopWatch();
   stopWatch.start(pjp.toShortString());
   boolean isException = false;
   try {
     return pjp.proceed();
   } catch (RuntimeException exception) {
     isException = true;
     throw exception;
   } finally {
     stopWatch.stop();
     TaskInfo taskInfo = stopWatch.getLastTaskInfo();
     System.out.println(
         taskInfo.getTaskName()
             + ": "
             + taskInfo.getTimeMillis()
             + " ms"
             + (isException ? " (thrown Exception)" : ""));
   }
 }
コード例 #4
0
  public void setUp(final Object testService) {
    MockitoAnnotations.initMocks(this);
    when(cache.getName()).thenReturn(AnnotationConstants.DEFAULT_CACHE_NAME);
    when(cache.getProperties()).thenReturn(new CacheProperties());
    advice = createAdvice();
    CacheBase cacheBase = new CacheBase();
    cacheBase.addCache(cache);
    advice.setCacheBase(cacheBase);

    when(signature.getName()).thenReturn(methodName);
    when(signature.getParameterTypes()).thenReturn(paramTypes);
    when(pjp.getSignature()).thenReturn(signature);
    when(pjp.toShortString()).thenReturn(methodName);
    when(pjp.getArgs()).thenReturn(params);

    when(signature.getDeclaringType()).thenReturn(testService.getClass());
    when(pjp.getTarget()).thenReturn(testService);

    if (isValid && cacheKey == null) {
      cacheKey = getKey(getNamespace(), params);
    }
  }