List of usage examples for org.aspectj.lang ProceedingJoinPoint proceed
public Object proceed() throws Throwable;
From source file:com.github.tddts.jet.config.aspect.SendSearchEventsAnnotationAspect.java
License:Apache License
@Around("@annotation(com.github.tddts.jet.config.spring.annotations.SendSearchEvents)") public Object annotationPointcut(ProceedingJoinPoint joinPoint) throws Throwable { SendSearchEvents annotation = SpringUtil.getMethod(joinPoint).getAnnotation(SendSearchEvents.class); checkAndSend(annotation.before());//www . ja v a 2 s. c o m Object value = joinPoint.proceed(); checkCollectionAndSend(value, annotation.onEmpty()); checkAndSend(annotation.after()); return value; }
From source file:com.github.tomschi.commons.aspect.logging.MethodExecutionLogger.java
License:Apache License
/** * This method is called, when a method is annotated with {@link LogExecution} or * a class is annotated with {@link LogExecution} and the called method is public. * * <br>// ww w . ja v a2s . c om * * The method calculates the execution time of the called method. For this purpose * the {@link StopWatch} is used. It will be only logged, if the execution time is * greater than the {@link LogExecution#limit()} and the {@link Logger} is enabled * for the class. The message will be logged with the {@link Logger} of the class, whose * method is called. * * @param joinPoint The {@link ProceedingJoinPoint}. * @return The method result of the called method. * @throws Throwable If error occurs. */ @Around("(publicMethod() && annotatedBean()) || annotatedMethod()") public Object proceed(ProceedingJoinPoint joinPoint) throws Throwable { Class<?> clazz = joinPoint.getTarget().getClass(); Method method = ((MethodSignature) joinPoint.getSignature()).getMethod(); LogExecution annotation = getAnnotation(clazz, method); Logger logger = LoggerFactory.getLogger(clazz); Object methodResult; if (!Slf4jUtils.isEnabled(logger, annotation.value())) { methodResult = joinPoint.proceed(); } else { StopWatch stopWatch = new StopWatch(); stopWatch.start(); methodResult = joinPoint.proceed(); stopWatch.stop(); if (shouldLog(annotation, stopWatch.getTime())) { Slf4jUtils.log(logger, annotation.value(), logMessage, method.getName(), DurationFormatUtils.formatDurationHMS(stopWatch.getTime())); } } return methodResult; }
From source file:com.github.trask.sandbox.isolation.ValueHolderAspect.java
License:Apache License
@Around("valueHolderGetPointcut()") public String aroundValueHolderGetPointcut(ProceedingJoinPoint joinPoint) throws Throwable { return joinPoint.proceed() + "/aspect-was-here"; }
From source file:com.github.trask.sandbox.jetty.TestAspect.java
License:Apache License
@Around("doGetPointcut() && args(request, response)") public void aroundTopLevelServletPointcut(ProceedingJoinPoint joinPoint, HttpServletRequest request, HttpServletResponse response) throws Throwable { joinPoint.proceed(); response.getWriter().print("/aspect-was-here"); }
From source file:com.goblingift.aspect.AspectManager.java
@Around(USERBEAN_METH_REF_TAKEOFF) public double aroundTakeOff(ProceedingJoinPoint joinPoint) throws Throwable { if ((double) Arrays.asList(joinPoint.getArgs()).get(0) >= 25.00) { System.out.println("WARNING: User tried to take-off more than 25 bucks: " + joinPoint.getTarget()); throw new IllegalStateException("THATS TOO MUCH!"); }// w w w . j a v a 2s .com return (double) joinPoint.proceed(); }
From source file:com.google.android.marvin.utils.TraceAspect.java
License:Apache License
@Around("methodAnnotatedWithDebugTrace() " + "|| talkbackAllMethods() " + "|| constructorAnnotatedDebugTrace()") public Object weaveJoinPoint(ProceedingJoinPoint joinPoint) throws Throwable { final Stopwatch stopWatch = new Stopwatch(); stopWatch.start();/* w ww . j a va 2s.co m*/ callLevel++; Object result = joinPoint.proceed(); stopWatch.stop(); log(joinPoint, stopWatch.elapsedMillis()); callLevel--; return result; }
From source file:com.google.code.ssm.aop.counter.ReadCounterFromCacheAdvice.java
License:Open Source License
@Around("readSingleCounter()") public Object readCounter(final ProceedingJoinPoint pjp) throws Throwable { if (isDisabled()) { getLogger().info("Cache disabled"); return pjp.proceed(); }/* www . j a va2 s . c o m*/ // This is injected caching. If anything goes wrong in the caching, LOG // the crap outta it, but do not let it surface up past the AOP injection itself. // It will be invoked only if underlying method completes successfully. String cacheKey = null; ReadCounterFromCache annotation; AnnotationData data; try { Method methodToCache = getCacheBase().getMethodToCache(pjp); verifyMethodSignature(methodToCache); annotation = methodToCache.getAnnotation(ReadCounterFromCache.class); data = AnnotationDataBuilder.buildAnnotationData(annotation, ReadCounterFromCache.class, methodToCache); cacheKey = getCacheBase().getCacheKeyBuilder().getCacheKey(data, pjp.getArgs(), methodToCache.toString()); Long result = getCacheBase().getCache(data).getCounter(cacheKey); if (result != null) { getLogger().debug("Cache hit."); return convertResult(methodToCache, result); } } catch (Exception ex) { warn(ex, "Caching on method %s and key [%s] aborted due to an error.", pjp.toShortString(), cacheKey); return pjp.proceed(); } final Object result = pjp.proceed(); // This is injected caching. If anything goes wrong in the caching, LOG // the crap outta it, but do not let it surface up past the AOP injection itself. try { if (checkData(result, pjp)) { long value = ((Number) result).longValue(); // tricky way to update counter getCacheBase().getCache(data).incr(cacheKey, 0, value, annotation.expiration()); } } catch (Exception ex) { warn(ex, "Caching on method %s and key [%s] aborted due to an error.", pjp.toShortString(), cacheKey); } return result; }
From source file:com.google.code.ssm.aop.InvalidateAssignCacheAdvice.java
License:Open Source License
@Around("invalidateAssign()") public Object cacheInvalidateAssign(final ProceedingJoinPoint pjp) throws Throwable { if (isDisabled()) { getLogger().info("Cache disabled"); return pjp.proceed(); }//from www . j a v a2s. co m final Object result = pjp.proceed(); // This is injected caching. If anything goes wrong in the caching, LOG // the crap outta it, but do not let it surface up past the AOP injection itself. String cacheKey = null; try { final Method methodToCache = getCacheBase().getMethodToCache(pjp); final InvalidateAssignCache annotation = methodToCache.getAnnotation(InvalidateAssignCache.class); final AnnotationData data = AnnotationDataBuilder.buildAnnotationData(annotation, InvalidateAssignCache.class, methodToCache); cacheKey = getCacheBase().getCacheKeyBuilder().getAssignCacheKey(data); getCacheBase().getCache(data).delete(cacheKey); } catch (Exception ex) { warn(ex, "Caching on method %s and key [%s] aborted due to an error.", pjp.toShortString(), cacheKey); } return result; }
From source file:com.google.code.ssm.aop.InvalidateMultiCacheAdvice.java
License:Open Source License
@Around("invalidateMulti()") public Object cacheInvalidateMulti(final ProceedingJoinPoint pjp) throws Throwable { if (isDisabled()) { getLogger().info("Cache disabled"); return pjp.proceed(); }/*from w w w . ja va2 s . com*/ // This is injected caching. If anything goes wrong in the caching, LOG // the crap outta it, but do not let it surface up past the AOP injection itself. Collection<String> cacheKeys = null; final AnnotationData data; final Method methodToCache; try { methodToCache = getCacheBase().getMethodToCache(pjp); final InvalidateMultiCache annotation = methodToCache.getAnnotation(InvalidateMultiCache.class); data = AnnotationDataBuilder.buildAnnotationData(annotation, InvalidateMultiCache.class, methodToCache); if (!data.isReturnKeyIndex()) { cacheKeys = getCacheBase().getCacheKeyBuilder().getCacheKeys(data, pjp.getArgs(), methodToCache.toString()); } } catch (Exception ex) { warn(ex, "Caching on method %s aborted due to an error.", pjp.toShortString()); return pjp.proceed(); } final Object result = pjp.proceed(); // This is injected caching. If anything goes wrong in the caching, LOG // the crap outta it, but do not let it surface up past the AOP injection itself. try { // If we have a -1 key index, then build the cacheKeys now. if (data.isReturnKeyIndex()) { if (!getCacheBase().verifyTypeIsList(result.getClass())) { throw new InvalidAnnotationException(String.format( "The return type is not a [%s]. " + "The method [%s] does not fulfill the requirements.", List.class.getName(), methodToCache.toString())); } @SuppressWarnings("unchecked") final List<Object> keyObjects = (List<Object>) result; cacheKeys = getCacheBase().getCacheKeyBuilder().getCacheKeys(keyObjects, data.getNamespace()); } getCacheBase().getCache(data).delete(cacheKeys); } catch (Exception ex) { warn(ex, "Caching on method %s aborted due to an error.", pjp.toShortString()); } return result; }
From source file:com.google.code.ssm.aop.InvalidateSingleCacheAdvice.java
License:Open Source License
@Around("invalidateSingle()") public Object cacheInvalidateSingle(final ProceedingJoinPoint pjp) throws Throwable { if (isDisabled()) { getLogger().info("Cache disabled"); return pjp.proceed(); }/*from w w w .j a v a2 s. co m*/ // This is injected caching. If anything goes wrong in the caching, LOG // the crap outta it, but do not let it surface up past the AOP injection itself. String cacheKey = null; final AnnotationData data; final Method methodToCache; try { methodToCache = getCacheBase().getMethodToCache(pjp); final InvalidateSingleCache annotation = methodToCache.getAnnotation(InvalidateSingleCache.class); data = AnnotationDataBuilder.buildAnnotationData(annotation, InvalidateSingleCache.class, methodToCache); if (!data.isReturnKeyIndex()) { cacheKey = getCacheBase().getCacheKeyBuilder().getCacheKey(data, pjp.getArgs(), methodToCache.toString()); } } catch (Exception ex) { warn(ex, "Caching on method %s and key [%s] aborted due to an error.", pjp.toShortString(), cacheKey); return pjp.proceed(); } final Object result = pjp.proceed(); // This is injected caching. If anything goes wrong in the caching, LOG // the crap outta it, but do not let it surface up past the AOP injection itself. try { if (data.isReturnKeyIndex()) { getCacheBase().verifyReturnTypeIsNoVoid(methodToCache, InvalidateSingleCache.class); cacheKey = getCacheBase().getCacheKeyBuilder().getCacheKey(result, data.getNamespace()); } getCacheBase().getCache(data).delete(cacheKey); } catch (Exception ex) { warn(ex, "Caching on method %s and key [%s] aborted due to an error.", pjp.toShortString(), cacheKey); } return result; }