List of usage examples for org.aspectj.lang ProceedingJoinPoint getSignature
Signature getSignature();
getStaticPart().getSignature()
returns the same object From source file:com.zhaimi.message.aop.AbstractSendMessageAdvice.java
License:Apache License
/** * Get method of joinpoint/* w ww.jav a 2s. c om*/ * @param pjp * @return */ protected Method getMethod(ProceedingJoinPoint pjp) { Class<?> clazz = pjp.getTarget().getClass(); String methodName = pjp.getSignature().getName(); Method method = null; int argCount = pjp.getArgs().length; // Object[] args = pjp.getArgs(); // Class<?>[] argClasses = new Class[args.length]; // for (int i = 0; i < args.length; i++) { // Class<?> argClass = args[i].getClass(); // // argClass = convertActualClass( argClass ); // argClasses[i] = args[i]!=null ? args[i].getClass() : null; // } try { String key = clazz.getName() + "." + methodName + "#" + argCount; if ((method = methodCache.get(key)) == null) { method = getMethodFromClass(clazz, methodName, argCount); if (method != null) { methodCache.put(key, method); } else { log.error("AOP pointcut method not found! methodName={},argCount={}", methodName, argCount); } } } catch (Exception e) { throw new RuntimeException("Method not found!" + clazz.getName() + "." + methodName, e); } return method; }
From source file:com.zte.spring.service.LogService.java
@Around("methodCachePointcut()") public Object around(ProceedingJoinPoint point) throws Throwable { Object result = null;/*from w ww . ja v a 2 s .c o m*/ String methodName = point.getSignature().getName(); // ? if (methodName.equals("login")) { result = point.proceed(); } if (logMethodsMap.containsKey(methodName)) { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest(); String loginName = (String) request.getSession().getAttribute("userid"); String roleName = (String) request.getSession().getAttribute("uname"); String clientIP = (String) request.getSession().getAttribute("clientIP"); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm"); Calendar ca = Calendar.getInstance(); String operDate = df.format(ca.getTime()); StringBuffer operDetail = new StringBuffer(); operDetail.append(roleName).append(loginName).append("(").append(clientIP).append(")"); Object[] method_param = point.getArgs(); // ?? // ???? if (!methodName.equals("addUser") && !methodName.equals("saveNews") && !methodName.equals("saveOrUpdateRole") && !methodName.equals("saveOrUpdateParam") && !methodName.equals("updateParam")) { operDetail.append(logMethodsMap.get(methodName)); } operDetail.append(getOperContent(method_param, methodName)); SysLog log = new SysLog(); log.setType("oper"); log.setCreatime(operDate); log.setUname(loginName); log.setUid(""); log.setOper(logMethodsMap.get(methodName)); log.setContent(operDetail.toString()); logger.info(log.getContent()); logService.saveLog(log); } if (!methodName.equals("login")) { result = point.proceed(); } return result; }
From source file:cs544.aspect.LoggingAspect.java
@Around("execution(public * cs544.bank.service.*.*(..))") public Object measureInvocationTime(ProceedingJoinPoint call) throws Throwable { StopWatch clock = new StopWatch(); clock.start(call.getSignature().getName()); Object retval = call.proceed(); clock.stop();//from www. j a va 2s .co m long totaltime = clock.getLastTaskTimeMillis(); System.out.println("Total time to execute: " + call.getSignature().getName() + ": " + totaltime); return retval; }
From source file:curly.commons.logging.MethodExecutionAspectInterceptor.java
License:Apache License
@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 ww . j av a 2 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:de.accso.performancetesting.tools.PerformanceLogger.java
License:Apache License
private Object measureTime(ProceedingJoinPoint thisJoinPoint, String tag) throws Throwable { StopWatch sp = new StopWatch(); sp.start();/*from w ww .j a v a 2s.c o m*/ Object result = thisJoinPoint.proceed(); sp.stop(); logger.info(append("durationinmillis", sp.getTotalTimeMillis()).and(append("tag", tag)) .and(append("req_id", CTX_HOLDER.get().reqId)).and(append("url", getCtxUrl())) .and(append("servicename", thisJoinPoint.getTarget().getClass().getCanonicalName() + "." + thisJoinPoint.getSignature().getName())), "Performance"); return result; }
From source file:de.alexandria.cms.frontend.webapp.aop.AopMethodLogger.java
License:Apache License
/** * * Protokolliert die Laufzeit des join points. Das logging ist nur aktiv, wenn {@link #logger} mindestens * debug-Level hat.// w w w .j a v a 2 s . co m * * @param call * @return * @throws Throwable */ @Around("methodsToBeLogged()") public Object logMethodDuration(ProceedingJoinPoint call) throws Throwable { // NOSONAR // proceed bentigt das Weiterreichen der Exception (throws Throwable)... Object returnValue; if (logger.isDebugEnabled()) { String targetClassName = call.getTarget().getClass().getName(); String targetMethodName = call.getSignature().getName(); Logger targetLog = LoggerFactory.getLogger(targetClassName); if (targetLog.isDebugEnabled()) { StopWatch clock = new StopWatch(getClass().getName()); try { clock.start(call.toShortString()); returnValue = call.proceed(); } finally { clock.stop(); String msg = createMsgForLogMethodDuration(targetMethodName, clock.getTotalTimeMillis()); targetLog.debug(msg); } } else { returnValue = call.proceed(); } } else { returnValue = call.proceed(); } return returnValue; }
From source file:de.bstreit.java.springaop.observablebean.PropertyChangeSupportWithInterface.java
License:Apache License
/** * Retrieve old and new value, invoke setter and finally fire property change * event.//from w ww .ja va2s. com * * @param pjp * @throws Throwable */ void handleSetterInvocation(ProceedingJoinPoint pjp) throws Throwable { // the method name is "setPropertyName", hence stripping of the "set" // from the beginning gives us "PropertyName" final String propertyName = pjp.getSignature().getName().substring(3); final Object oldValue = beanWrapper.getPropertyValue(propertyName); final Object newValue = pjp.getArgs()[0]; // perform the setting pjp.proceed(); // fire property change, if no exception occurred pcs.firePropertyChange(propertyName, oldValue, newValue); }
From source file:de.codecentric.batch.metrics.AbstractBatchMetricsAspect.java
License:Apache License
protected Object profileMethod(ProceedingJoinPoint pjp) throws Throwable { StopWatch stopWatch = startStopWatch(); try {/*from w w w .j a va2 s. c om*/ return pjp.proceed(); } finally { gaugeService.submit(TIMER_PREFIX + getStepIdentifier() + "." + ClassUtils.getShortName(pjp.getTarget().getClass()) + "." + pjp.getSignature().getName(), getTotalTimeMillis(stopWatch)); } }
From source file:de.codecentric.capturereplay.CaptureReplayAdvice.java
License:Apache License
@Around("execution(@de.codecentric.capturereplay.Capturable * *(..))") public Object aroundCapturableMethod(ProceedingJoinPoint pjp) throws Throwable { MethodSignature signature = (MethodSignature) pjp.getSignature(); if (Mode.CAPTURE.equals(mode)) { Object returnValue = pjp.proceed(); dataMapper.writeCapturedData(signature, returnValue, pjp.getArgs()); return returnValue; } else if (Mode.REPLAY.equals(mode)) { return dataMapper.getCapturedData(signature.getMethod().getName(), pjp.getArgs()); } else if (Mode.DISABLED.equals(mode)) { return pjp.proceed(); } else {/* w ww .j a va2 s.c o m*/ throw new IllegalCaptureReplayUsageException( String.format("Capturing/replaying is switched off. You should not use %s directly.", this.getClass().getSimpleName())); } }
From source file:de.codecentric.spring.boot.chaos.monkey.watcher.SpringComponentAspect.java
License:Apache License
@Around("classAnnotatedWithComponentPointcut() && allPublicMethodPointcut() && !classInChaosMonkeyPackage()") public Object intercept(ProceedingJoinPoint pjp) throws Throwable { // metrics/*from www . ja va 2 s . c o m*/ if (metricEventPublisher != null) metricEventPublisher.publishMetricEvent(calculatePointcut(pjp.toShortString()), MetricType.COMPONENT); MethodSignature signature = (MethodSignature) pjp.getSignature(); chaosMonkey.callChaosMonkey(createSignature(signature)); return pjp.proceed(); }