List of usage examples for org.aspectj.lang ProceedingJoinPoint getTarget
Object getTarget();
From source file:fi.helsinki.opintoni.aop.logging.LoggingAspect.java
License:Open Source License
private List<Annotation> getMethodAnnotations(ProceedingJoinPoint joinPoint) throws NoSuchMethodException { MethodSignature signature = (MethodSignature) joinPoint.getSignature(); String methodName = signature.getMethod().getName(); Class<?>[] parameterTypes = signature.getMethod().getParameterTypes(); return Lists.newArrayList( joinPoint.getTarget().getClass().getMethod(methodName, parameterTypes).getAnnotations()); }
From source file:fr.scolomfr.recette.cli.commands.ConsoleTestCaseExecutionTrackingAspect.java
License:Open Source License
@Around("execution(* fr.scolomfr.recette.model.tests.execution.result.Result.setState(..))") public void messageAdded(ProceedingJoinPoint joinPoint) { State state = (State) joinPoint.getArgs()[0]; if (state.equals(State.FINAL)) { tracker.notifyTestCaseTermination((Result) joinPoint.getTarget()); }/*from w w w . j av a 2 s .c o m*/ }
From source file:fr.scolomfr.recette.cli.commands.ConsoleTestCaseExecutionTrackingAspect.java
License:Open Source License
@Around("execution(* fr.scolomfr.recette.model.tests.execution.result.Result.setState(..))") public void testCaseStopped(ProceedingJoinPoint joinPoint) { State state = (State) joinPoint.getArgs()[0]; if (state.equals(State.FINAL)) { tracker.notifyTestCaseTermination((Result) joinPoint.getTarget()); }/* w w w. ja v a 2 s. co m*/ }
From source file:gov.fda.open.demo.service.loggable.LoggingAspect.java
License:Open Source License
/** * ********************./*from w w w. ja va 2 s . c om*/ * * @param joinPoint * the join point * @param annotation * the annotation * @return the object * @throws Throwable * the throwable */ @Around(value = "@annotation(annotation)") public Object logAround(final ProceedingJoinPoint joinPoint, final Loggable annotation) throws Throwable { final Object returnVal; Class<? extends Object> clazz = joinPoint.getTarget().getClass(); String name = joinPoint.getSignature().getName(); Object[] args = joinPoint.getArgs(); if (args == null || args.length == 0) { logger.log(annotation.value(), clazz, null, BEFORE_STRING, name, constructArgumentsString(clazz, joinPoint.getArgs())); } else { logger.log(annotation.value(), clazz, null, BEFORE_WITH_PARAMS_STRING, name, constructArgumentsString(clazz, joinPoint.getArgs())); } returnVal = joinPoint.proceed(); // Now Do The After Logging Part afterReturningLog(joinPoint, annotation, returnVal); return returnVal; }
From source file:gov.nih.nci.cabig.caaers.tools.logging.CaaersLoggingAspect.java
License:BSD License
@Around("execution(public * gov.nih.nci.cabig.caaers.api.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.api.impl.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.dao..*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.domain.repository.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.domain.repository.ajax.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.service..*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.validation..*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.workflow..*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.rules.business.service.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.rules.runtime.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.web.ae.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.web.study.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.web.admin.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.web.rule.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.web.participant.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.tools.Excel*.*(..))") public Object log(ProceedingJoinPoint call) throws Throwable { Log logger = (call.getTarget() == null) ? LogFactory.getLog(CaaersLoggingAspect.class) : LogFactory.getLog(call.getTarget().getClass()); //just proceed to call if Info is not enabled. if (logger == null || !logger.isInfoEnabled()) return call.proceed(); boolean traceEnabled = logger.isTraceEnabled(); String userName = ""; if (traceEnabled) { userName = "[" + getUserLoginName() + "] - "; log(logger, true, call, null, 0, userName); }//from w w w . j ava 2 s.c o m long startTime = System.currentTimeMillis(); //proceed with the call Object point = call.proceed(); long endTime = System.currentTimeMillis(); long executionTime = (endTime - startTime); if (executionTime > 500) { logger.info(userName + "More than 500ms [ " + call.toShortString() + " executionTime : " + executionTime + "]"); } if (traceEnabled) { log(logger, false, call, point, executionTime, userName); } return point; }
From source file:gov.nih.nci.ncicb.tcga.dcc.common.aspect.cache.CacheAspect.java
@Around("cache()") public Object aroundCachedMethods(ProceedingJoinPoint thisJoinPoint) throws Throwable { // generate the key under which cached value is stored // will look like package.class.method(arg1=val1;arg2=val2;) StringBuilder keyBuff = new StringBuilder(); // append name of the class keyBuff.append(thisJoinPoint.getTarget().getClass().getName()); // append name of the method keyBuff.append(".").append(thisJoinPoint.getSignature().getName()); keyBuff.append("("); // find method arguments for (final Object arg : thisJoinPoint.getArgs()) { // append argument type and value keyBuff.append(arg.getClass().getSimpleName() + "=" + arg + ";"); }// ww w. ja v a 2 s. c o m keyBuff.append(")"); String key = keyBuff.toString(); Element element = cache.get(key); if (element == null) { logger.info("[" + Thread.currentThread().getId() + "] Result not yet cached for " + key + " let's proceed"); // Synchronizing calls to only getUUIDRows API. Because calling multiple getUUIDRows at the same time // might take more memory if (key.contains("UUIDBrowserDAOImpl.getUUIDRows()")) { synchronized (refreshDataLock) { // doing this one more time so that the threads that are waiting in this lock, will // use the cache instead of db element = cache.get(key); if (element == null) { element = storeDataInCache(thisJoinPoint, key); } } } else { element = storeDataInCache(thisJoinPoint, key); } } return (element != null) ? element.getValue() : null; }
From source file:io.curly.commons.logging.MethodExecutionAspectInterceptor.java
License:Apache License
@SuppressWarnings("ArgNamesErrorsInspection") @Around(value = "execution(* *(..)) && @annotation(loggable)) ", argNames = "joinPoint, loggable") public Object invoke(ProceedingJoinPoint joinPoint, Loggable loggable) throws Throwable { if (executionEnabled) { StopWatch watch = new StopWatch(joinPoint.toShortString()); watch.start();/* w w w. ja v a2 s . c o m*/ try { return joinPoint.proceed(); } finally { watch.stop(); synchronized (this) { if (actuatorEnabled && (gaugeService != null)) { String gagueName = "gauge.execution." + joinPoint.getTarget() + "." + joinPoint.getSignature().getName(); gaugeService.submit(gagueName, watch.getLastTaskTimeMillis()); } log(loggable.value(), joinPoint.getTarget().getClass(), "Executed method {} in {} ms", joinPoint.getSignature().getName(), watch.getLastTaskTimeMillis()); } } } return joinPoint.proceed(); }
From source file:io.github.resilience4j.bulkhead.configure.BulkheadAspect.java
License:Apache License
@Around(value = "matchAnnotatedClassOrMethod(bulkheadAnnotation)", argNames = "proceedingJoinPoint, bulkheadAnnotation") public Object bulkheadAroundAdvice(ProceedingJoinPoint proceedingJoinPoint, @Nullable Bulkhead bulkheadAnnotation) throws Throwable { Method method = ((MethodSignature) proceedingJoinPoint.getSignature()).getMethod(); String methodName = method.getDeclaringClass().getName() + "#" + method.getName(); if (bulkheadAnnotation == null) { bulkheadAnnotation = geBulkheadAnnotation(proceedingJoinPoint); }//from ww w . j a v a 2 s.co m if (bulkheadAnnotation == null) { //because annotations wasn't found return proceedingJoinPoint.proceed(); } String backend = bulkheadAnnotation.name(); io.github.resilience4j.bulkhead.Bulkhead bulkhead = getOrCreateBulkhead(methodName, backend); Class<?> returnType = method.getReturnType(); if (StringUtils.isEmpty(bulkheadAnnotation.fallbackMethod())) { return proceed(proceedingJoinPoint, methodName, bulkhead, returnType); } FallbackMethod fallbackMethod = FallbackMethod.create(bulkheadAnnotation.fallbackMethod(), method, proceedingJoinPoint.getArgs(), proceedingJoinPoint.getTarget()); return fallbackDecorators .decorate(fallbackMethod, () -> proceed(proceedingJoinPoint, methodName, bulkhead, returnType)) .apply(); }
From source file:io.github.resilience4j.bulkhead.configure.BulkheadAspect.java
License:Apache License
@Nullable private Bulkhead geBulkheadAnnotation(ProceedingJoinPoint proceedingJoinPoint) { if (logger.isDebugEnabled()) { logger.debug("bulkhead parameter is null"); }/*from www. ja v a 2 s .co m*/ return AnnotationExtractor.extract(proceedingJoinPoint.getTarget().getClass(), Bulkhead.class); }
From source file:io.github.resilience4j.circuitbreaker.autoconfigure.CircuitBreakerAspect.java
License:Apache License
private CircuitBreaker getBackendMonitoredAnnotation(ProceedingJoinPoint proceedingJoinPoint) { if (logger.isDebugEnabled()) { logger.debug("circuitBreaker parameter is null"); }//from w ww . j av a 2s. c o m CircuitBreaker circuitBreaker = null; Class<?> targetClass = proceedingJoinPoint.getTarget().getClass(); if (targetClass.isAnnotationPresent(CircuitBreaker.class)) { circuitBreaker = targetClass.getAnnotation(CircuitBreaker.class); if (circuitBreaker == null) { if (logger.isDebugEnabled()) { logger.debug("TargetClass has no annotation 'CircuitBreaker'"); } circuitBreaker = targetClass.getDeclaredAnnotation(CircuitBreaker.class); if (circuitBreaker == null) { if (logger.isDebugEnabled()) { logger.debug("TargetClass has no declared annotation 'CircuitBreaker'"); } } } } return circuitBreaker; }