List of usage examples for org.aspectj.lang ProceedingJoinPoint getTarget
Object getTarget();
From source file:com.crossbusiness.resiliency.aspect.AbstractGovernorAspect.java
License:Open Source License
protected Object wrap(final ProceedingJoinPoint pjp, Governor governorConfig) throws Throwable { // throttle per instance, per method String throttleKey = pjp.getTarget().hashCode() + pjp.getSignature().toLongString(); if (!throttles.containsKey(throttleKey)) { switch (governorConfig.type()) { case CONCURRENCY: throttles.put(throttleKey,//from ww w . java 2 s. c o m new ConcurrencyThrottleDecorator(governorConfig.limit(), governorConfig.blocking())); break; case RATE: throttles.put(throttleKey, new RateThrottleDecorator(governorConfig.limit(), governorConfig.period(), governorConfig.unit(), governorConfig.blocking(), scheduler)); break; case ALL: //TODO break; default: log.error("Unknown Throttler type"); break; } } Throttler t = throttles.get(throttleKey); if (t != null) { return t.proceed(pjp); } else { log.error("no throttles found"); return pjp.proceed(); } }
From source file:com.datastax.hectorjpa.spring.ConsistencyLevelAspect.java
License:Open Source License
/** * Validates any method that has the valid annotation on it and is wired as * a spring service//w ww . j av a2 s . c om * * @param jp * @throws Throwable */ @Around("@annotation(com.datastax.hectorjpa.spring.Consistency)") public Object setConsistency(ProceedingJoinPoint pjp) throws Throwable { logger.debug("Invoking before advice for @Consistency annotation. Target object is {} on method {}", pjp.getTarget(), pjp.getSignature()); MethodSignature sig = (MethodSignature) pjp.getSignature(); Object[] args = pjp.getArgs(); Method signatureMethod = sig.getMethod(); Class<?>[] signatureTypes = signatureMethod.getParameterTypes(); // we do this because we want to get the best match from the child // classes Class<?>[] runtimeArgs = new Class<?>[signatureTypes.length]; for (int i = 0; i < signatureTypes.length; i++) { if (args[i] != null) { runtimeArgs[i] = args[i].getClass(); } else { runtimeArgs[i] = signatureTypes[i]; } } Class<?> runtimeClass = pjp.getTarget().getClass(); // check if this is annotated, if not proceed and execute it HConsistencyLevel level = consistency(runtimeClass, signatureMethod.getName(), runtimeArgs); if (level == null) { return pjp.proceed(args); } Stack<HConsistencyLevel> stack = threadStack.get(); stack.push(level); JPAConsistency.set(level); Object result = null; try { result = pjp.proceed(args); } finally { stack.pop(); if (stack.size() > 0) { JPAConsistency.set(stack.peek()); } else { JPAConsistency.remove(); } } return result; }
From source file:com.eryansky.core.aop.LogAspect.java
License:Apache License
/** * @param point // w ww . jav a2s . c o m */ @Around("execution(* com.eryansky.service..*Manager.*(..))") public Object logAll(ProceedingJoinPoint point) { Object result = null; // ?? String methodName = point.getSignature().getName(); String className = point.getTarget().getClass().getSimpleName(); String userName = null; Long start = 0L; Long end = 0L; String ip = null; // ? try { // start = System.currentTimeMillis(); result = point.proceed(); end = System.currentTimeMillis(); // ?? SessionInfo sessionInfo = SecurityUtils.getCurrentSessionInfo(); if (sessionInfo != null) { userName = sessionInfo.getLoginName(); ip = sessionInfo.getIp(); } else { userName = ""; ip = "127.0.0.1"; logger.warn("sessionInfo."); } } catch (Throwable e) { logger.error(e.getMessage()); // e.printStackTrace(); } String name = null; // ? if (className.indexOf("Resource") > -1) { name = "??"; } else if (className.indexOf("Role") > -1) { name = "?"; } else if (className.indexOf("User") > -1) { name = "?"; } else if (className.indexOf("Organ") > -1) { name = "?"; } else { name = className; } // ? String opertype = methodName; if (StringUtils.isNotBlank(opertype) && (opertype.indexOf("save") > -1 || opertype.indexOf("update") > -1 || opertype.indexOf("delete") > -1 || opertype.indexOf("merge") > -1)) { Long time = end - start; Log log = new Log(); log.setType(LogType.operate.getValue()); log.setLoginName(userName); log.setModule(name); log.setAction(opertype); log.setOperTime(new Date(start)); log.setActionTime(time.toString()); log.setIp(ip); defaultEntityManager.save(log); } if (logger.isDebugEnabled()) { logger.debug(":{},?{},?{},{}ms.", new Object[] { userName, className, methodName, end - start }); } return result; }
From source file:com.facultyshowcase.app.model.helpers.TransactionAspect.java
License:Open Source License
@Around("daoMethod() && @annotation(withTransaction)") public Object wrapWithTransaction(ProceedingJoinPoint pjp, WithTransaction withTransaction) throws Throwable { _logger.trace("wrapWithTransaction()"); DAOHelper dao = (DAOHelper) pjp.getTarget(); try {/*from w ww . j ava2s .c o m*/ beginTransaction.invoke(dao); Object ret = pjp.proceed(); commitTransaction.invoke(dao); return ret; } catch (Throwable e) { try { rollbackTransaction.invoke(dao); } catch (Throwable e2) { e.addSuppressed(e2); } throw e; } }
From source file:com.feilong.spring.aop.ProceedingJoinPointUtil.java
License:Apache License
/** * map for log./* w w w . j a v a 2s . c o m*/ * * @param proceedingJoinPoint * the proceeding join point * @return the map for log */ public final static Map<String, Object> getMapForLog(ProceedingJoinPoint proceedingJoinPoint) { Map<String, Object> map = new LinkedHashMap<String, Object>(); Signature signature = proceedingJoinPoint.getSignature(); MethodSignature methodSignature = (MethodSignature) signature; Method method = methodSignature.getMethod(); Object[] args = proceedingJoinPoint.getArgs(); Object target = proceedingJoinPoint.getTarget(); Class<?> declaringType = methodSignature.getDeclaringType(); Class<? extends Object> targetClass = target.getClass(); map.put("target", targetClass.getCanonicalName()); map.put("method", method.getName()); map.put("args", args); return map; }
From source file:com.feilong.spring.jdbc.datasource.MultipleGroupReadWriteDataSourceAspect.java
License:Apache License
/** * Point./*from w w w .j av a2 s .c o m*/ * * @param proceedingJoinPoint * the proceeding join point * @return the object * @throws Throwable * the throwable */ @Around("this(loxia.dao.ReadWriteSupport)") public Object point(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { Signature signature = proceedingJoinPoint.getSignature(); MethodSignature methodSignature = (MethodSignature) signature; // TransactionAttribute transactionAttribute = null; if (null != transactionAttributeSouce) { transactionAttribute = transactionAttributeSouce.getTransactionAttribute(methodSignature.getMethod(), proceedingJoinPoint.getTarget().getClass()); } MultipleGroupDataSource multipleGroupDataSourceAnnotation = getAnnotation(proceedingJoinPoint, MultipleGroupDataSource.class); //?? String groupName; //?multipleGroupDataSourceAnnotation //? ? if (null == multipleGroupDataSourceAnnotation || Validator.isNullOrEmpty(multipleGroupDataSourceAnnotation.value())) { //nothing to do groupName = null; } else { groupName = multipleGroupDataSourceAnnotation.value(); } return this.proceed(proceedingJoinPoint, transactionAttribute, groupName); }
From source file:com.forsrc.aop.LogTracing.java
License:Apache License
/** * Do around object.//from w w w .j a v a 2 s . com * * @param proceedingJoinPoint the proceeding join point * @return the object * @throws Throwable the throwable */ public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { long ms = System.currentTimeMillis(); long time = System.nanoTime(); Object retVal = proceedingJoinPoint.proceed(); time = System.nanoTime() - time; ms = System.currentTimeMillis() - ms; StringBuilder msg = new StringBuilder("[TIME] method: ") .append(proceedingJoinPoint.getSignature().getName()).append("() -> ") .append(new Double(1.0d * time / (1000000000d)).toString()).append(" s (").append(ms) .append(" ms) --> ").append(proceedingJoinPoint.getTarget().getClass()); this.appendMessage(msg); LOGGER.info(msg); return retVal; }
From source file:com.github.eemmiirr.redisdata.signalizer.RedisDataSignalizerAspect.java
License:LGPL
@Around("redisTransactionalPointcut()") public Object redisTransactionalAroundAdvice(ProceedingJoinPoint pjp) throws Throwable { // Retrieve the RedisData annotation from either the Type or the Method // If both are present the Method will override the Type annotation final MethodSignature methodSignature = (MethodSignature) pjp.getSignature(); final Method method = pjp.getTarget().getClass().getMethod(methodSignature.getName(), methodSignature.getParameterTypes()); final RedisData redisData = retrieveRedisTransactionalAnnotation(method); try {// w w w . j av a 2s . c om redisTransactionalBeforeAdvice(redisData); final Object returnValue = pjp.proceed(); redisTransactionalAfterAdvice(redisData); return returnValue; } catch (Throwable t) { redisTransactionalAfterThrowing(t, redisData); throw t; } }
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>//from w ww.j a v a2 s. c o m * * 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.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!"); }/*from w w w. j av a 2s . com*/ return (double) joinPoint.proceed(); }