Example usage for org.aspectj.lang ProceedingJoinPoint proceed

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

Introduction

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

Prototype

public Object proceed() throws Throwable;

Source Link

Document

Proceed with the next advice or target method invocation

Usage

From source file:com.att.ajsc.common.trace.TrailLoggerAspect.java

License:BSD License

@Around("pointcut()")
public Object logTrail(ProceedingJoinPoint joinPoint) throws Throwable {

    long startTimeInMilliseconds = System.currentTimeMillis();
    TransactionTrail transactionTrail;/*from   w  ww .ja  va  2s  .co m*/
    long endTimeInMilliseconds;
    long durationInMilliseconds;
    String message = null;
    String finalMessage = "";
    String executionDepth = "-";
    String identifier = "";
    String placeholder = "";
    try {
        transactionTrail = (TransactionTrail) context.getBean(TRANSACTION_TRAIL);
    } catch (Exception e1) {
        logger.error(InterceptorMessages.INTERCEPTOR_TRAIL_LOGGER_MESSAGE, e1,
                ((MethodSignature) joinPoint.getSignature()).getMethod().getName());
        return joinPoint.proceed();
    }

    try {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();
        identifier = method.getDeclaringClass().toString() + method.getName();
        transactionTrail.addInCompleteMethod(identifier);
        long line = transactionTrail.getTrail().split("\n").length + 1;
        placeholder = LINE + line + ":";
        transactionTrail.setTrail(transactionTrail.getTrail() + "\n" + placeholder);
        Tracable tracable = method.getAnnotation(Tracable.class);
        message = tracable.message();
        if (message.length() == 0) {
            message = signature.toString();
        }

        Object result = joinPoint.proceed();
        endTimeInMilliseconds = System.currentTimeMillis();
        int inCompleteMethods = incompleteMethods(transactionTrail.getInCompleteMethods());
        if (inCompleteMethods > 0) {
            for (int i = 0; i < inCompleteMethods; i++) {
                executionDepth = executionDepth + "-";
            }

        }
        durationInMilliseconds = endTimeInMilliseconds - startTimeInMilliseconds;
        finalMessage = executionDepth + durationInMilliseconds + MILLIS + message;
        transactionTrail.setTrail(transactionTrail.getTrail().replace(placeholder, finalMessage));
        transactionTrail.getInCompleteMethods().remove(identifier);
        return result;
    } catch (Throwable e) {
        logger.error(InterceptorMessages.INTERCEPTOR_TRAIL_LOGGER_MESSAGE, e,
                joinPoint.getSignature().toString());
        endTimeInMilliseconds = System.currentTimeMillis();
        int inCompleteMethods = incompleteMethods(transactionTrail.getInCompleteMethods());
        if (inCompleteMethods > 0) {
            for (int i = 0; i < inCompleteMethods; i++) {
                executionDepth = executionDepth + "-";
            }

        }
        durationInMilliseconds = endTimeInMilliseconds - startTimeInMilliseconds;
        finalMessage = executionDepth + durationInMilliseconds + MILLIS + message;
        transactionTrail.setTrail(transactionTrail.getTrail().replace(placeholder, finalMessage));
        transactionTrail.getInCompleteMethods().remove(identifier);
        throw e;
    }

}

From source file:com.autentia.wuija.aop.AopTracer.java

License:Open Source License

public Object traceMethod(ProceedingJoinPoint pjp) throws Throwable {
    if (!log.isTraceEnabled()) {
        log.warn("You are using " + AopTracer.class.getName()
                + ", but you are not using TRACE level in your log. So you will not see the trace messages.");
    }//from   w w w .j  a v  a2s.com
    log.trace("Entering: " + pjp.getSignature().toLongString());
    final long millis = System.currentTimeMillis();

    final Object retVal = pjp.proceed();

    final long methodTime = System.currentTimeMillis() - millis;
    log.trace("Exiting (" + methodTime + " millis): " + pjp.getSignature().toLongString());

    return retVal;
}

From source file:com.autentification_system.Aspects.TransactionalAspect.java

@Around("@annotation(com.autentification_system.Aspects.TransactionMethod)")
public Object transctionalContext(ProceedingJoinPoint proceed) {
    Session session = sessionFactory.getCurrentSession();
    Object result = null;//from www  . jav  a2  s .  c  o m
    try {
        session.beginTransaction();
        result = proceed.proceed();
        session.getTransaction().commit();
    } catch (Throwable e) {
        session.getTransaction().rollback();
    }
    return result;
}

From source file:com.baomidou.framework.aop.DataSourceAop.java

License:Apache License

@Around("@annotation(dataSourceManage)")
public Object doAround(ProceedingJoinPoint joinPoint, DataSourceManage dataSourceManage) throws Throwable {
    Object retVal = null;/*from w  w w. j a  va  2s .  c  om*/
    boolean selectedDataSource = false;
    try {
        if (null != dataSourceManage) {
            String dbName = dataSourceManage.name();
            int dbSize = dataSourceManage.dbSize();
            DynamicDataSource.use(dbName, dbSize);
            selectedDataSource = true;
        }
        retVal = joinPoint.proceed();
    } catch (Throwable e) {
        throw e;
    } finally {
        if (selectedDataSource) {
            DynamicDataSource.reset();
        }
    }
    return retVal;
}

From source file:com.baomidou.framework.aop.LogAspect.java

License:Apache License

/**
 * ??/*from  w w w  .  j  a va  2s  .  c  om*/
 *
 * @param joinPoint
 *            
 * @return 
 * @throws Throwable
 *             
 */
@Around(value = "@annotation(com.baomidou.framework.annotations.Log)")
public Object saveLog(ProceedingJoinPoint joinPoint) throws Throwable {
    /**
     * ?Log
     */
    String methodName = joinPoint.getSignature().getName();
    Method method = currentMethod(joinPoint, methodName);
    Log log = method.getAnnotation(Log.class);

    /**
     * 
     */
    if (log != null) {
        logPoint.saveLog(joinPoint, methodName, log.value());
    }

    /**
     * 
     */
    return joinPoint.proceed();
}

From source file:com.baomidou.framework.aop.ResubmitAspect.java

License:Apache License

/**
 * <p>//from www. j  a  v a2s .co  m
 * ?? token
 * </p>
 */
public void generate(ProceedingJoinPoint joinPoint, HttpServletRequest request, HttpSession session,
        String tokenFlag) throws Throwable {
    String uuid = UUID.randomUUID().toString();
    session.setAttribute(tokenFlag, uuid);
    request.setAttribute(PARAM_TOKEN, uuid);
    joinPoint.proceed();
}

From source file:com.baomidou.framework.aop.ResubmitAspect.java

License:Apache License

/**
 * <p>/*from w w w .  j av a2s.  c o  m*/
 * ?? token
 * </p>
 * <p>
 * ????token<br>
 * ????
 * </p>
 */
public void validation(ProceedingJoinPoint joinPoint, HttpServletRequest request, HttpSession session,
        String tokenFlag) throws Throwable {
    Object sessionFlag = session.getAttribute(tokenFlag);
    Object requestFlag = request.getParameter(PARAM_TOKEN);
    if (sessionFlag != null && sessionFlag.equals(requestFlag)) {
        session.removeAttribute(tokenFlag);
        joinPoint.proceed();
    }
}

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  a  v  a2  s .c  o m*/
        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.MonitoredMethodCall.java

License:Apache License

public Object call(ProceedingJoinPoint pjp, PassiveMethodMonitor monitor) throws Throwable {
    ErrorCountingPolicy errorCountingPolicy = monitor.getErrorCountingPolicy();

    Throwable error = null;//from w  ww. j av  a 2 s.c o  m
    Object ret = null;
    try {
        ret = pjp.proceed();
        return ret;
    } catch (Throwable t) {
        error = t;
        throw t;
    } finally {
        if (error != null) {

            if (LOG.isDebugEnabled()) {
                LOG.debug("Got a Throwable in monitor: " + monitor.getName(), error);
            }

            if (errorCountingPolicy.countsAsError(error)) {
                monitor.failure(error);
            } else {
                monitor.success();
            }
        } else {
            if (errorCountingPolicy.countsAsError(ret)) {
                monitor.failure("Got return value which is considered an error: " + ret);
            } else {
                monitor.success();
            }
        }
    }
}

From source file:com.boyuanitsm.fort.aop.logging.LoggingAspect.java

License:Apache License

@Around("loggingPointcut()")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
    if (log.isDebugEnabled()) {
        log.debug("Enter: {}.{}() with argument[s] = {}", joinPoint.getSignature().getDeclaringTypeName(),
                joinPoint.getSignature().getName(), Arrays.toString(joinPoint.getArgs()));
    }/*from  w w w.j  av  a2s.  c  om*/
    try {
        Object result = joinPoint.proceed();
        if (log.isDebugEnabled()) {
            log.debug("Exit: {}.{}() with result = {}", joinPoint.getSignature().getDeclaringTypeName(),
                    joinPoint.getSignature().getName(), result);
        }
        return result;
    } catch (IllegalArgumentException e) {
        log.error("Illegal argument: {} in {}.{}()", Arrays.toString(joinPoint.getArgs()),
                joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName());

        throw e;
    }
}