List of usage examples for org.aspectj.lang ProceedingJoinPoint getTarget
Object getTarget();
From source file:com.astonish.metrics.aspectj.MetricAdvice.java
License:Apache License
/** * Retrieves the {@link Method} from the {@link ProceedingJoinPoint}. * @param pjp//from ww w .ja v a 2 s .c om * the {@link ProceedingJoinPoint} * @return the {@link Method} */ private Method retrieveMethod(ProceedingJoinPoint pjp) { final MethodSignature methodSignature = (MethodSignature) pjp.getSignature(); Method method = methodSignature.getMethod(); if (method.getDeclaringClass().isInterface()) { try { method = pjp.getTarget().getClass().getDeclaredMethod(pjp.getSignature().getName(), method.getParameterTypes()); } catch (final SecurityException e) { LOGGER.warn("Could not retrieve method[{}] for metric interrogation.", method.getName(), e); } catch (final NoSuchMethodException e) { LOGGER.warn("Could not retrieve method[{}] for metric interrogation.", method.getName(), e); } } return method; }
From source file:com.baomidou.framework.aop.LogAspect.java
License:Apache License
/** * ??/*from ww w . j a va 2 s . c om*/ * * @param joinPoint * * @param methodName * ?? * @return */ private Method currentMethod(ProceedingJoinPoint joinPoint, String methodName) { /** * ??? */ Method[] methods = joinPoint.getTarget().getClass().getMethods(); Method resultMethod = null; for (Method method : methods) { if (method.getName().equals(methodName)) { resultMethod = method; break; } } return resultMethod; }
From source file:com.baomidou.framework.aop.ResubmitAspect.java
License:Apache License
/** * <p>/*w w w. j a va2 s. c o m*/ * ? * </p> * * @param joinPoint * ? * @param formToken * ?? * @throws Throwable */ @Around("@annotation(formToken)") public void execute(ProceedingJoinPoint joinPoint, FormToken formToken) throws Throwable { Object[] args = joinPoint.getArgs(); String className = joinPoint.getTarget().getClass().getName(); for (Object arg : args) { if (arg != null && arg instanceof HttpServletRequest) { HttpServletRequest request = (HttpServletRequest) arg; HttpSession session = request.getSession(true); if (formToken != null) { if ("GET".equalsIgnoreCase(request.getMethod())) { /* GET ? token */ this.generate(joinPoint, request, session, PARAM_TOKEN_FLAG + className); } else { /* POST ? token */ this.validation(joinPoint, request, session, PARAM_TOKEN_FLAG + className); } } } } }
From source file:com.betfair.cougar.core.impl.kpi.KPIAsyncTimer.java
License:Apache License
@Around("cougarAsyncMethod(event, observer)") public Object measureAsyncMethod(final ProceedingJoinPoint pjp, KPIAsyncTimedEvent event, ExecutionObserver observer) throws Throwable { final String eventValue = event.value(); final String eventOperation = event.operation(); final String name = eventValue.isEmpty() ? pjp.getTarget().getClass().getSimpleName() : eventValue; final String operation = eventOperation.isEmpty() ? pjp.getSignature().getName() : eventOperation; final KPITimer timer = new KPITimer(); timer.start();// ww w . j a va 2s . com final PerformanceMonitoringExecutionObserver perfObserver = new PerformanceMonitoringExecutionObserver( observer, monitor, timer, event.catchFailures(), name, operation); return pjp.proceed(replaceObserver(perfObserver, pjp.getArgs())); }
From source file:com.betfair.tornjak.kpi.aop.KPIMeasuringAspect.java
License:Apache License
@Around("@annotation(kpiTimedEvent)") public Object measureDuration(final ProceedingJoinPoint pjp, KPITimedEvent kpiTimedEvent) throws Throwable { KPITimer timer = new KPITimer(); boolean succeeded = true; try {/*from w w w .j av a 2 s. com*/ timer.start(); return pjp.proceed(); } catch (Throwable t) { succeeded = false; throw t; } finally { // this looks like a reasonable and clean place to stop the clock, even if we've wasted a few nanos before // we actually get here double duration = timer.stop(); final String eventValue = kpiTimedEvent.value(); final String name = eventValue.isEmpty() ? pjp.getTarget().getClass().getSimpleName() : eventValue; final String operation = kpiTimedEvent.operation().isEmpty() ? pjp.getSignature().getName() : kpiTimedEvent.operation(); if (kpiTimedEvent.catchFailures()) { kpiMonitor.addEvent(name, operation, duration, succeeded); } else { kpiMonitor.addEvent(name, operation, duration); } } }
From source file:com.betfair.tornjak.monitor.aop.MonitorAOP.java
License:Apache License
private MonitorMethod getAnnotation(final ProceedingJoinPoint pjp) { MethodSignature signature = (MethodSignature) pjp.getSignature(); MonitorMethod fromSignature = signature.getMethod().getAnnotation(MonitorMethod.class); if (fromSignature != null) { return fromSignature; }/* w ww .j a v a2 s. co m*/ // right, couldn't find it on the method signature, but we might be looking at an implementation of an interface // so now look at the target object/class try { Method m = pjp.getTarget().getClass().getDeclaredMethod(signature.getName(), signature.getParameterTypes()); return m.getAnnotation(MonitorMethod.class); } catch (NoSuchMethodException e) { // hmm, not sure we should ever see this throw new IllegalStateException("Couldn't find method that was called on the object it was called on"); } }
From source file:com.brienwheeler.lib.monitor.work.impl.MonitoredWorkAspect.java
License:Open Source License
@SuppressWarnings({ "unchecked", "rawtypes" }) @Around("monitoredWorkPointcut()") public Object aroundMonitoredWork(final ProceedingJoinPoint joinPoint) throws InterruptedException { ValidationUtils.assertTrue(joinPoint.getTarget() instanceof IWorkMonitorProvider, "@MonitoredWork target must be subclass of IWorkMonitorProvider"); ValidationUtils.assertTrue(joinPoint.getSignature() instanceof MethodSignature, "@MonitoredWork signature must be a method"); final WorkMonitor workMonitor = ((IWorkMonitorProvider) joinPoint.getTarget()).getWorkMonitor(); MethodSignature signature = (MethodSignature) joinPoint.getSignature(); MonitoredWork annotation = signature.getMethod().getAnnotation(MonitoredWork.class); final String workName = annotation != null && !annotation.value().isEmpty() ? annotation.value() : signature.getName();/*from www . j a v a2 s .c o m*/ long start = System.currentTimeMillis(); try { Object ret = joinPoint.proceed(); workMonitor.recordWorkOk(workName, System.currentTimeMillis() - start); return ret; } catch (InterruptedException e) { workMonitor.recordWorkError(workName, System.currentTimeMillis() - start); Thread.currentThread().interrupt(); throw e; } catch (RuntimeException e) { workMonitor.recordWorkError(workName, System.currentTimeMillis() - start); throw e; } catch (Error e) { workMonitor.recordWorkError(workName, System.currentTimeMillis() - start); throw e; } catch (Throwable e) { workMonitor.recordWorkError(workName, System.currentTimeMillis() - start); throw new RuntimeException(e); } }
From source file:com.brienwheeler.lib.svc.impl.GracefulShutdownAspect.java
License:Open Source License
@SuppressWarnings({ "unchecked", "rawtypes" }) @Around("gracefulShutdownPointcut()") public Object aroundGracefulShutdown(final ProceedingJoinPoint joinPoint) { ValidationUtils.assertTrue(joinPoint.getTarget() instanceof StartableServiceBase, "@GracefulShutdown target must be subclass of StartableServiceBase"); ServiceWork work = new ServiceWork() { @Override/*from w w w . ja va 2 s. c o m*/ public Object doServiceWork() throws InterruptedException { try { return joinPoint.proceed(); } catch (InterruptedException e) { throw e; } catch (RuntimeException e) { throw e; } catch (Error e) { throw e; } catch (Throwable e) { throw new RuntimeException(e); } } }; StartableServiceBase service = (StartableServiceBase) joinPoint.getTarget(); return service.executeWithGracefulShutdown(work); }
From source file:com.clicktravel.cheddar.server.application.logging.LoggingAspect.java
License:Apache License
private String methodCallDetail(final ProceedingJoinPoint point) { final StringBuilder sb = new StringBuilder(); sb.append(point.getTarget().getClass().getSimpleName()); sb.append('.'); sb.append(((MethodSignature) (point.getSignature())).getMethod().getName()); sb.append('('); boolean firstArg = true; for (final Object arg : point.getArgs()) { if (!firstArg) { sb.append(','); }/* ww w .j a v a2 s .c om*/ firstArg = false; sb.append(arg == null ? "null" : arg.toString()); } sb.append(')'); return sb.toString(); }
From source file:com.create.aop.LoggingAspect.java
License:Apache License
private String getWatchId(ProceedingJoinPoint joinPoint) { final String className = getClassName(joinPoint.getTarget()); final String methodName = getMethodName(joinPoint.getSignature()); return String.format("%s - %s", className, methodName); }