List of usage examples for org.aspectj.lang ProceedingJoinPoint getTarget
Object getTarget();
From source file:io.github.resilience4j.circuitbreaker.configure.CircuitBreakerAspect.java
License:Apache License
@Around(value = "matchAnnotatedClassOrMethod(circuitBreakerAnnotation)", argNames = "proceedingJoinPoint, circuitBreakerAnnotation") public Object circuitBreakerAroundAdvice(ProceedingJoinPoint proceedingJoinPoint, @Nullable CircuitBreaker circuitBreakerAnnotation) throws Throwable { Method method = ((MethodSignature) proceedingJoinPoint.getSignature()).getMethod(); String methodName = method.getDeclaringClass().getName() + "#" + method.getName(); if (circuitBreakerAnnotation == null) { circuitBreakerAnnotation = getCircuitBreakerAnnotation(proceedingJoinPoint); }//from w w w. jav a2s . c o m if (circuitBreakerAnnotation == null) { //because annotations wasn't found return proceedingJoinPoint.proceed(); } String backend = circuitBreakerAnnotation.name(); io.github.resilience4j.circuitbreaker.CircuitBreaker circuitBreaker = getOrCreateCircuitBreaker(methodName, backend); Class<?> returnType = method.getReturnType(); if (StringUtils.isEmpty(circuitBreakerAnnotation.fallbackMethod())) { return proceed(proceedingJoinPoint, methodName, circuitBreaker, returnType); } FallbackMethod fallbackMethod = FallbackMethod.create(circuitBreakerAnnotation.fallbackMethod(), method, proceedingJoinPoint.getArgs(), proceedingJoinPoint.getTarget()); return fallbackDecorators.decorate(fallbackMethod, () -> proceed(proceedingJoinPoint, methodName, circuitBreaker, returnType)).apply(); }
From source file:io.github.resilience4j.circuitbreaker.configure.CircuitBreakerAspect.java
License:Apache License
@Nullable private CircuitBreaker getCircuitBreakerAnnotation(ProceedingJoinPoint proceedingJoinPoint) { if (logger.isDebugEnabled()) { logger.debug("circuitBreaker parameter is null"); }//from ww w . ja v a 2 s. c o m return AnnotationExtractor.extract(proceedingJoinPoint.getTarget().getClass(), CircuitBreaker.class); }
From source file:io.github.resilience4j.ratelimiter.autoconfigure.RateLimiterAspect.java
License:Apache License
private RateLimiter getRateLimiterAnnotation(ProceedingJoinPoint proceedingJoinPoint) { RateLimiter rateLimiter = null;/*from www . ja va 2 s.c o m*/ Class<?> targetClass = proceedingJoinPoint.getTarget().getClass(); if (targetClass.isAnnotationPresent(RateLimiter.class)) { rateLimiter = targetClass.getAnnotation(RateLimiter.class); if (rateLimiter == null) { rateLimiter = targetClass.getDeclaredAnnotation(RateLimiter.class); } if (rateLimiter == null) { logger.debug("TargetClass has no declared annotation 'RateLimiter'"); } } return rateLimiter; }
From source file:io.github.resilience4j.ratelimiter.configure.RateLimiterAspect.java
License:Apache License
@Around(value = "matchAnnotatedClassOrMethod(rateLimiterAnnotation)", argNames = "proceedingJoinPoint, rateLimiterAnnotation") public Object rateLimiterAroundAdvice(ProceedingJoinPoint proceedingJoinPoint, @Nullable RateLimiter rateLimiterAnnotation) throws Throwable { Method method = ((MethodSignature) proceedingJoinPoint.getSignature()).getMethod(); String methodName = method.getDeclaringClass().getName() + "#" + method.getName(); if (rateLimiterAnnotation == null) { rateLimiterAnnotation = getRateLimiterAnnotation(proceedingJoinPoint); }/* w w w.j a v a 2 s .c o m*/ if (rateLimiterAnnotation == null) { //because annotations wasn't found return proceedingJoinPoint.proceed(); } String name = rateLimiterAnnotation.name(); io.github.resilience4j.ratelimiter.RateLimiter rateLimiter = getOrCreateRateLimiter(methodName, name); Class<?> returnType = method.getReturnType(); if (StringUtils.isEmpty(rateLimiterAnnotation.fallbackMethod())) { return proceed(proceedingJoinPoint, methodName, returnType, rateLimiter); } FallbackMethod fallbackMethod = FallbackMethod.create(rateLimiterAnnotation.fallbackMethod(), method, proceedingJoinPoint.getArgs(), proceedingJoinPoint.getTarget()); return fallbackDecorators .decorate(fallbackMethod, () -> proceed(proceedingJoinPoint, methodName, returnType, rateLimiter)) .apply(); }
From source file:io.github.resilience4j.ratelimiter.configure.RateLimiterAspect.java
License:Apache License
@Nullable private RateLimiter getRateLimiterAnnotation(ProceedingJoinPoint proceedingJoinPoint) { return AnnotationExtractor.extract(proceedingJoinPoint.getTarget().getClass(), RateLimiter.class); }
From source file:io.github.resilience4j.retry.configure.RetryAspect.java
License:Apache License
@Around(value = "matchAnnotatedClassOrMethod(retryAnnotation)", argNames = "proceedingJoinPoint, retryAnnotation") public Object retryAroundAdvice(ProceedingJoinPoint proceedingJoinPoint, @Nullable Retry retryAnnotation) throws Throwable { Method method = ((MethodSignature) proceedingJoinPoint.getSignature()).getMethod(); String methodName = method.getDeclaringClass().getName() + "#" + method.getName(); if (retryAnnotation == null) { retryAnnotation = getRetryAnnotation(proceedingJoinPoint); }//w w w. j av a 2 s . com if (retryAnnotation == null) { //because annotations wasn't found return proceedingJoinPoint.proceed(); } String backend = retryAnnotation.name(); io.github.resilience4j.retry.Retry retry = getOrCreateRetry(methodName, backend); Class<?> returnType = method.getReturnType(); if (StringUtils.isEmpty(retryAnnotation.fallbackMethod())) { return proceed(proceedingJoinPoint, methodName, retry, returnType); } FallbackMethod fallbackMethod = FallbackMethod.create(retryAnnotation.fallbackMethod(), method, proceedingJoinPoint.getArgs(), proceedingJoinPoint.getTarget()); return fallbackDecorators .decorate(fallbackMethod, () -> proceed(proceedingJoinPoint, methodName, retry, returnType)) .apply(); }
From source file:io.github.resilience4j.retry.configure.RetryAspect.java
License:Apache License
/** * @param proceedingJoinPoint the aspect joint point * @return the retry annotation/*from ww w .j a v a2 s . co m*/ */ @Nullable private Retry getRetryAnnotation(ProceedingJoinPoint proceedingJoinPoint) { return AnnotationExtractor.extract(proceedingJoinPoint.getTarget().getClass(), Retry.class); }
From source file:io.helixservice.feature.jpa.transaction.TransactionalAspect.java
License:Open Source License
@SuppressWarnings("DuplicateThrows") @Around(value = "(execution(public * *(..)) && @annotation(transactional))" + " || (execution(public * *(..)) && within(@javax.transaction.Transactional *) && @annotation(transactional))") public Object around(ProceedingJoinPoint pjp, Transactional transactional) throws Throwable, SuspendExecution { Object result;// ww w. j a v a 2 s. co m Signature method = pjp.getSignature(); Object target = pjp.getTarget(); LOG.info("Managing transaction for method=" + method.getName() + ", target=" + target.getClass().getName() + ", txType=" + transactional.value()); validateTransactionalAnnotation(target, method, transactional); boolean commit = false; String persistenceContextName = beginTransaction(target); try { result = pjp.proceed(); commit = true; } catch (Throwable t) { commit = shouldCommitOnThrowable(transactional, t); LOG.info("Caught throwable=" + t.getClass().getName() + ", which results in commit=" + commit); throw t; } finally { LOG.trace("Skipping non-transactional method=" + method.getName() + ", target=" + target.getClass().getName()); endTransaction(persistenceContextName, commit); } return result; }
From source file:io.micrometer.spring.scheduling.ScheduledMethodMetrics.java
License:Apache License
@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 {/* ww w.j a v a2 s .c om*/ 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(); }
From source file:io.pcp.parfait.spring.MonitoringAspect.java
License:Apache License
public Object profileMethod(ProceedingJoinPoint pjp) throws Throwable { Timeable timeable = map.get(pjp.getTarget()); if (timeable == null) { return pjp.proceed(); }/*from w w w. j av a2 s . co m*/ EventMetricCollector collector = timer.getCollector(); try { collector.startTiming(timeable, pjp.getSignature().getName()); return pjp.proceed(); } finally { collector.stopTiming(); } }