List of usage examples for org.aspectj.lang ProceedingJoinPoint getSignature
Signature getSignature();
getStaticPart().getSignature()
returns the same object From source file:com.github.tddts.jet.config.aspect.ProfilingAnnotationAspect.java
License:Apache License
@Around("@annotation(com.github.tddts.jet.config.spring.annotations.Profiling)") public Object annotationPointcut(ProceedingJoinPoint joinPoint) throws Throwable { long time = System.currentTimeMillis(); Object value = joinPoint.proceed(); long duration = (System.currentTimeMillis() - time) / 1000; long minutes = (duration % (60 * 60)) / 60; long seconds = duration % 60; logger.debug(joinPoint.getSignature().getDeclaringType().getSimpleName() + "." + joinPoint.getSignature().getName() + "() execution time is: " + minutes + " m. " + seconds + " s."); 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>/* w w w . j a v a2s.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.google.android.marvin.utils.TraceAspect.java
License:Apache License
private void log(ProceedingJoinPoint joinPoint, long elapsedMillis) { if (elapsedMillis >= LATENCY_THRESHOLD_MS) { MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); String className = methodSignature.getMethod().getDeclaringClass().getCanonicalName(); String methodName = methodSignature.getName(); LogUtils.log(className, Log.DEBUG, "%s %s.%s -->%dms", Strings.repeat(" ", callLevel > 0 ? callLevel : 0), className, methodName, elapsedMillis); }/*from w ww. ja va 2 s. co m*/ }
From source file:com.googlecode.commonspringaspects.aspects.CachingAspect.java
License:Apache License
private String getCacheKey(ProceedingJoinPoint pjp) { String targetName = pjp.getTarget().getClass().getSimpleName(); String methodName = pjp.getSignature().getName(); Object[] arguments = pjp.getArgs(); StringBuilder key = new StringBuilder(); key.append(targetName).append(".").append(methodName); if (arguments != null) { for (Object argument : arguments) { key.append(".").append(argument); }//from w w w . j a v a2s . co m } return key.toString(); }
From source file:com.googlecode.commonspringaspects.aspects.JamonAspect.java
License:Apache License
private String createInvocationTraceName(ProceedingJoinPoint pjp) { String longSignatureString = pjp.getSignature().toLongString(); int lastIndexOfThrows = longSignatureString.lastIndexOf("throws"); if (lastIndexOfThrows > 0) { longSignatureString = longSignatureString.substring(0, lastIndexOfThrows); }// w w w. j a v a 2 s.c o m String[] split = longSignatureString.split(" "); return split[split.length - 1]; }
From source file:com.googlecode.easiest.cache.ever.CacheAspect.java
License:Apache License
private MethodCall buildMethodCall(ProceedingJoinPoint joinPoint) { final MethodSignature methodSignature; if (joinPoint.getSignature() instanceof MethodSignature) { methodSignature = (MethodSignature) joinPoint.getSignature(); } else {//w ww.j a v a2s. c o m throw new RuntimeException( "Spring can only join on methods, so casting to MethodSignature should always work."); } final String concreteClassName = joinPoint.getTarget().getClass().getName(); return new MethodCall(concreteClassName, methodSignature.getName(), methodSignature.getParameterTypes(), joinPoint.getArgs()); }
From source file:com.haulmont.cuba.core.sys.MBeanInterceptor.java
License:Apache License
@SuppressWarnings("UnusedDeclaration") private Object aroundInvoke(ProceedingJoinPoint ctx) throws Throwable { Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); if (log.isTraceEnabled()) log.trace("Invoking: " + ctx.getSignature()); try {/* www.j a v a 2 s . co m*/ Object res = ctx.proceed(); return res; } catch (Throwable e) { log.error("MBeanInterceptor caught exception: ", e); throw e; } }
From source file:com.haulmont.cuba.core.sys.PerformanceLogInterceptor.java
License:Apache License
@SuppressWarnings({ "UnusedDeclaration", "UnnecessaryLocalVariable" }) private Object aroundInvoke(ProceedingJoinPoint ctx) throws Throwable { StopWatch stopWatch = new Slf4JStopWatch(ctx.getSignature().toShortString()); try {// ww w .ja v a2s . c o m stopWatch.start(); Object res = ctx.proceed(); return res; } finally { stopWatch.stop(); } }
From source file:com.haulmont.cuba.core.sys.ServiceInterceptor.java
License:Apache License
private Object aroundInvoke(ProceedingJoinPoint ctx) throws Throwable { SecurityContext securityContext = AppContext.getSecurityContextNN(); boolean internalInvocation = securityContext.incServiceInvocation() > 0; try {/*from ww w .ja va2 s. c o m*/ if (internalInvocation) { if (logInternalServiceInvocation) { log.warn("Invoking '{}' from another service", ctx.getSignature()); } ValidateServiceMethodContext validatedContext = getValidateServiceMethodContext(ctx); validateMethodParameters(ctx, validatedContext); Object res = ctx.proceed(); validateMethodResult(ctx, validatedContext, res); return res; } else { statisticsAccumulator.incMiddlewareRequestsCount(); try { // Using UserSessionsAPI directly to make sure the session's "last used" timestamp is propagated to the cluster UserSession userSession = userSessions.getAndRefresh(securityContext.getSessionId(), true); if (userSession == null) { throw new NoUserSessionException(securityContext.getSessionId()); } ValidateServiceMethodContext validatedContext = getValidateServiceMethodContext(ctx); validateMethodParameters(ctx, validatedContext); boolean checkTransactionOnExit = Stores.getAdditional().isEmpty() && !persistence.isInTransaction(); log.trace("Invoking: {}, session={}", ctx.getSignature(), userSession); Object res = ctx.proceed(); validateMethodResult(ctx, validatedContext, res); if (checkTransactionOnExit && persistence.isInTransaction()) { log.warn("Open transaction left in {}", ctx.getSignature().toShortString()); } return res; } catch (Throwable e) { logException(e, ctx); // Propagate the special exception to avoid serialization errors on remote clients throw new RemoteException(e); } } } finally { securityContext.decServiceInvocation(); } }
From source file:com.haulmont.cuba.core.sys.ServiceInterceptor.java
License:Apache License
@Nullable protected ValidateServiceMethodContext getValidateServiceMethodContext(ProceedingJoinPoint ctx) { ValidateServiceMethodContext validatedContext = null; if (ctx instanceof MethodInvocationProceedingJoinPoint) { MethodInvocationProceedingJoinPoint methodInvocationCtx = (MethodInvocationProceedingJoinPoint) ctx; Method method = ((MethodSignature) ctx.getSignature()).getMethod(); Validated validated = getValidated(method, ctx.getSignature().getDeclaringType()); if (validated != null) { Object[] args = methodInvocationCtx.getArgs(); ExecutableValidator validator = beanValidation.getValidator().forExecutables(); validatedContext = new ValidateServiceMethodContext(validator, ctx.getThis(), method, args, validated.value());//w w w . j a v a 2s .co m } } return validatedContext; }