Example usage for org.aspectj.lang ProceedingJoinPoint getSignature

List of usage examples for org.aspectj.lang ProceedingJoinPoint getSignature

Introduction

In this page you can find the example usage for org.aspectj.lang ProceedingJoinPoint getSignature.

Prototype

Signature getSignature();

Source Link

Document

getStaticPart().getSignature() returns the same object

Usage

From source file:com.fernandocejas.frodo2.logger.single.SingleWeaver.java

License:Apache License

public static boolean methodAnnotatedWithRxLogSingle(ProceedingJoinPoint joinPoint) {
    return ((MethodSignature) joinPoint.getSignature()).getReturnType() == Single.class;
}

From source file:com.forsrc.aop.LogTracing.java

License:Apache License

/**
 * Do around object./*from  w  w  w  .  j av  a2  s  .  c o  m*/
 *
 * @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.genyherrera.performancelog.aspect.PerformanceLogAspect.java

License:Apache License

@Around("performanceMethod()")
public Object logPerformanceStats(ProceedingJoinPoint joinpoint) {
    try {//from w w  w  .  j  a v  a2s  . c o m
        PerfLog perfLog = retrievePerfLogAnnotation(joinpoint);
        Long start = null;
        Long end = null;
        Object result = null;

        switch (perfLog.timeStyle()) {
        case NANO_SECONDS:
            start = System.nanoTime();
            result = joinpoint.proceed();
            end = System.nanoTime();
            break;
        case MILI_SECONDS:
            start = System.currentTimeMillis();
            result = joinpoint.proceed();
            end = System.currentTimeMillis();
            break;
        case SECONDS:
            start = System.currentTimeMillis() / 1000;
            result = joinpoint.proceed();
            end = System.currentTimeMillis() / 1000;
            break;
        default:
            start = System.currentTimeMillis();
            result = joinpoint.proceed();
            end = System.currentTimeMillis();
            break;
        }

        switch (perfLog.severity()) {
        case DEBUG:
            logger.debug(String.format("%s took %d " + perfLog.timeStyle().toString(),
                    joinpoint.getSignature().toShortString(), (end - start)));
            break;
        case INFO:
            logger.info(String.format("%s took %d " + perfLog.timeStyle().toString(),
                    joinpoint.getSignature().toShortString(), (end - start)));
            break;
        case WARN:
            logger.warn(String.format("%s took %d " + perfLog.timeStyle().toString(),
                    joinpoint.getSignature().toShortString(), (end - start)));
            break;
        case ERROR:
            logger.error(String.format("%s took %d " + perfLog.timeStyle().toString(),
                    joinpoint.getSignature().toShortString(), (end - start)));
            break;
        default:
            logger.debug(String.format("%s took %d " + perfLog.timeStyle().toString(),
                    joinpoint.getSignature().toShortString(), (end - start)));
            break;
        }
        return result;
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
}

From source file:com.github.akutschera.maven.plugin.skiptest.aspect.SkipAspect.java

License:Apache License

private String getNameOfTestFrom(ProceedingJoinPoint pjp) {
    String className = pjp.getThis().getClass().getName();
    String testToExecute = pjp.getSignature().getName();
    return className + "." + testToExecute;
}

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.kopylec.rapidjdbc.SQLAspect.java

@Around("target(repository) && execution(* *(..)) && @annotation(query) && @annotation(update)")
public Object preventDuplicateSQL(Repository repository, ProceedingJoinPoint joinPoint, Query query,
        Update update) throws Throwable {
    throw new RapidJDBCException("Multiple SQLs on method " + joinPoint.getSignature().toShortString());
}

From source file:com.github.piasy.aopdemolib.TraceAspect.java

License:Open Source License

@Around("methodToTrace() || constructorToTrace()")
public Object trace(ProceedingJoinPoint joinPoint) throws Throwable {
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    String className = signature.getDeclaringType().getSimpleName();
    String methodName = signature.getName();

    long start = System.nanoTime();
    Object result = joinPoint.proceed();
    long stop = System.nanoTime();

    Log.d(className + "::" + methodName, "" + (stop - start));
    PrintWriter writer = new PrintWriter(
            new FileOutputStream(new File(Environment.getExternalStorageDirectory(), "reflect.log"), true));
    writer.println(className + "::" + methodName + (stop - start));
    writer.close();//from  ww w. j a  v  a  2s  .  c  om

    return result;
}

From source file:com.github.rozidan.springboot.logger.LoggerInterceptor.java

License:Apache License

private void log(LogLevel level, String message, ProceedingJoinPoint joinPoint, Loggable loggable) {
    if (loggable.name().isEmpty()) {
        logger.log(level, MethodSignature.class.cast(joinPoint.getSignature()).getMethod().getDeclaringClass(),
                message);// w w  w. j  a va  2s .  c  om
    } else {
        logger.log(level, loggable.name(), message);
    }
}

From source file:com.github.rozidan.springboot.logger.LoggerInterceptor.java

License:Apache License

private void log(String message, ProceedingJoinPoint joinPoint, Loggable loggable, Throwable ex) {
    if (loggable.name().isEmpty()) {
        logger.log(MethodSignature.class.cast(joinPoint.getSignature()).getMethod().getDeclaringClass(),
                message, ex);/*from w  w w. ja va  2  s .c  o  m*/
    } else {
        logger.log(LogLevel.ERROR, loggable.name(), message, ex);
    }
}

From source file:com.github.rozidan.springboot.logger.LoggerInterceptor.java

License:Apache License

private boolean isLevelEnabled(ProceedingJoinPoint joinPoint, Loggable loggable) {
    return loggable.name().isEmpty()
            ? logger.isEnabled(LogLevel.WARN,
                    MethodSignature.class.cast(joinPoint.getSignature()).getMethod().getDeclaringClass())
            : logger.isEnabled(LogLevel.WARN, loggable.name());
}