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.vladmihalcea.concurrent.aop.OptimisticConcurrencyControlAspect.java

License:Apache License

private Object proceed(ProceedingJoinPoint pjp) throws Throwable {
    return pjp.proceed();
}

From source file:com.vmware.bdd.aop.lock.ClusterEntityConcurentWriteLockAdvice.java

License:Open Source License

public Object lock(ProceedingJoinPoint pjp) throws Throwable {
    Object[] objs = pjp.getArgs();
    String clusterName = (String) objs[0];
    logger.info("Lock competitive write for cluster " + clusterName);
    boolean locked = false;
    try {//  w  ww .  j a va  2s . c  o  m
        lockConcurrentWrite((String) clusterName);
        locked = true;
        return pjp.proceed();
    } finally {
        if (locked) {
            unlockConcurrentWrite(clusterName);
            logger.info("Unlock competitive write for cluster " + clusterName);
        }
    }
}

From source file:com.vmware.bdd.aop.lock.ClusterEntityExclusiveWriteLockAdvice.java

License:Open Source License

public Object lock(ProceedingJoinPoint pjp) throws Throwable {
    Object[] objs = pjp.getArgs();
    String clusterName = (String) objs[0];
    logger.info("Lock exclusive write for cluster " + clusterName);
    boolean locked = false;
    try {/*from www  .j av  a 2s  .  c  o m*/
        lockExclusiveWrite((String) clusterName);
        locked = true;
        return pjp.proceed();
    } finally {
        if (locked) {
            unlockExclusiveWrite(clusterName);
            logger.info("Unlock exclusive write for cluster " + clusterName);
        }
    }
}

From source file:com.vmware.bdd.aop.software.DefaultPreStartServicesAdvice.java

License:Open Source License

@Around("@annotation(com.vmware.bdd.software.mgmt.plugin.aop.PreConfiguration)")
public Object preClusterConfiguration(ProceedingJoinPoint pjp) throws Throwable {
    MethodSignature signature = (MethodSignature) pjp.getSignature();
    Method method = signature.getMethod();
    PreConfiguration beforeConfig = AnnotationUtils.findAnnotation(method, PreConfiguration.class);
    String nameParam = beforeConfig.clusterNameParam();

    String[] paramNames = signature.getParameterNames();
    Object[] args = pjp.getArgs();
    String clusterName = null;/*from  www. jav a  2s  .c  o m*/
    for (int i = 0; i < paramNames.length; i++) {
        if (paramNames[i].equals(nameParam)) {
            clusterName = (String) args[i];
        }
    }
    if (clusterName == null) {
        logger.error("Cluster name is not specified in method");
        throw BddException.INTERNAL(null, "Wrong annotation usage. Cluster name must be specified in method.");
    }
    ClusterEntity cluster = clusterEntityMgr.findByName(clusterName);
    if (cluster == null) {
        throw BddException.NOT_FOUND("Cluster", clusterName);
    }
    preStartServices(clusterName);
    return pjp.proceed();
}

From source file:com.vmware.bdd.aop.tx.RetryTransactionAdvice.java

License:Open Source License

public void retry(ProceedingJoinPoint pjp) throws Throwable {
    logger.info("retry transaction");
    int retriesLeft = 5;
    String methodName = pjp.getSignature().getName();
    MethodSignature signature = (MethodSignature) pjp.getSignature();
    Method method = signature.getMethod();
    if (method.getDeclaringClass().isInterface()) {
        method = pjp.getTarget().getClass().getDeclaredMethod(methodName, method.getParameterTypes());
    }/*from   w  w w.ja v  a  2s.  c o  m*/
    Annotation[] annotations = method.getDeclaredAnnotations();
    for (Annotation a : annotations) {
        if (a instanceof RetryTransaction) {
            RetryTransaction retryAnno = (RetryTransaction) a;
            retriesLeft = retryAnno.value();
        }
    }

    RetryTransaction retryTrx = AnnotationUtils.findAnnotation(method, RetryTransaction.class);
    retriesLeft = retryTrx.value();
    Throwable rootCause = null;
    boolean success = false;
    while (!success) {
        try {
            pjp.proceed();
            success = true;
        } catch (Throwable ex) {
            rootCause = (ex instanceof BddException) ? ex.getCause() : ex;
            if (isRetryable(rootCause)) {
                if (retriesLeft > 0) {
                    retriesLeft--;
                } else {
                    throw TxRetryException.wrap(rootCause, false);
                }
            } else if (isUniqViolation(rootCause)) {
                throw UniqueConstraintViolationException.wrap((ConstraintViolationException) rootCause);
            } else {
                throw BddException.wrapIfNeeded(ex, "Exception in a DAL transaction.");
            }
        }
    }
    if (!success) {
        if (rootCause != null) {
            logger.warn("retry transaction failed.", rootCause);
            throw rootCause;
        } else {
            logger.warn("retry transction failed.");
            throw new Exception("retry transaction failed");
        }
    } else {
        if (rootCause != null) {
            logger.warn("retry transaction completed. Failure root cause:" + rootCause.getMessage());
        } else {
            logger.info("normal operation");
        }
    }
}

From source file:com.vsct.supervision.notification.log.LoggingAspect.java

License:Open Source License

@Around(value = "@within(com.vsct.supervision.notification.log.Loggable) || @annotation(com.vsct.supervision.notification.log.Loggable)")
public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {

    final MethodSignature signature = (MethodSignature) proceedingJoinPoint.getSignature();
    final Method method = signature.getMethod();
    final Class clazz = signature.getClass();
    final Loggable loggableMethod = method.getAnnotation(Loggable.class);

    final Loggable loggableClass = proceedingJoinPoint.getTarget().getClass().getAnnotation(Loggable.class);

    //get current log level
    final LogLevel logLevel = loggableMethod != null ? loggableMethod.value() : loggableClass.value();

    final String service = StringUtils.isNotBlank(loggableClass.service()) ? loggableClass.service()
            : clazz.getName();//  w w w. j  a v  a  2s.  c  o  m
    final String methodName = StringUtils.isNotBlank(loggableClass.method()) ? loggableClass.method()
            : method.getName();

    final String star = "**********";
    //before
    LogWriter.write(proceedingJoinPoint.getTarget().getClass(), logLevel,
            star + service + "." + methodName + "() start execution" + star);

    //show traceParams
    final boolean showParams = loggableMethod != null ? loggableMethod.traceParams()
            : loggableClass.traceParams();
    if (showParams) {

        if (proceedingJoinPoint.getArgs() != null && proceedingJoinPoint.getArgs().length > 0) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < proceedingJoinPoint.getArgs().length; i++) {
                sb.append(method.getParameterTypes()[i].getName() + ":" + proceedingJoinPoint.getArgs()[i]);
                if (i < proceedingJoinPoint.getArgs().length - 1)
                    sb.append(", ");
            }

            LogWriter.write(proceedingJoinPoint.getTarget().getClass(), logLevel,
                    service + "." + methodName + "() args " + sb);
        }

    }

    final long startTime = System.currentTimeMillis();
    //start method execution
    final Object result = proceedingJoinPoint.proceed();

    final long endTime = System.currentTimeMillis();

    //show results
    if (result != null) {
        boolean showResults = loggableMethod != null ? loggableMethod.traceResult()
                : loggableClass.traceResult();
        if (showResults) {
            LogWriter.write(proceedingJoinPoint.getTarget().getClass(), logLevel,
                    service + "." + methodName + "() Result : " + result);
        }
    }

    //show after
    LogWriter.write(proceedingJoinPoint.getTarget().getClass(), logLevel, star + service + "." + methodName
            + "() finished execution and takes " + (endTime - startTime) + " millis time to execute " + star);

    return result;
}

From source file:com.weib.concert.pointcut.AnotherAudience.java

@Around("performance()")
public void watchPerformance(ProceedingJoinPoint jp) {
    try {//from   ww w  . j  ava  2  s. c o  m
        System.out.println("######################Silencing cell phones");
        System.out.println("######################Take seats");
        jp.proceed();
        System.out.println("######################CLAP CLAP CLAP");
    } catch (Throwable e) {
        System.out.println("######################Demanding a refund");
    }
}

From source file:com.willowtreeapps.respeeker.ResPeeker.java

License:Apache License

@Around("setContentView()")
public Object aroundSetContentView(ProceedingJoinPoint joinPoint) throws Throwable {
    Object result = joinPoint.proceed();

    Activity context = (Activity) joinPoint.getThis();
    int layoutRes = (Integer) joinPoint.getArgs()[0];
    View view = context.findViewById(android.R.id.content);

    attachTouchListener(view);/*from  w  ww.  j  a  va2 s .c  om*/

    ViewPeeker.put(view, layoutRes);

    Configurator configurator = new Configurator(context);
    Properties properties = configurator.getProperties();
    Log.v("__ResPeeker__", "config <<" + propertiesToString(properties) + ">>");

    return result;
}

From source file:com.willowtreeapps.respeeker.ResPeeker.java

License:Apache License

@Around("inflate()")
public Object aroundInflate(ProceedingJoinPoint joinPoint) throws Throwable {
    Object result = joinPoint.proceed();

    int layoutRes = (Integer) joinPoint.getArgs()[0];
    View layoutView = (View) joinPoint.getArgs()[1];
    View view = (View) result;

    attachTouchListener(view);/* w ww  .j  av  a  2  s  .  co  m*/

    ViewPeeker.put(layoutView, layoutRes);

    return result;
}

From source file:com.wms.studio.service.handler.GenericAopHandler.java

License:Apache License

/**
 * TODO ??/*from ww  w  .j a v  a 2 s  .  c  o m*/
 * 
 * @param point
 * @return
 * @throws Throwable
 */
@Around(value = TAG)
public Object process(ProceedingJoinPoint point) throws Throwable {

    String handlerName = getHandlerName(point);
    boolean isNeedHandler = StringUtils.isNotBlank(handlerName);
    HandlerData data = null;
    Object result = null;
    boolean handlerResult = false;

    if (isNeedHandler) {
        data = new HandlerData();
        data.setArgs(point.getArgs());
        handlerResult = beforeProcess(data, handlerName);
    }

    if (handlerResult) {
        return null;
    }

    try {
        result = point.proceed();
    } catch (Exception e) {
        if (isNeedHandler) {
            data.setException(e);
            handlerResult = exceptionProcess(data, handlerName);
        } else {
            throw e;
        }
    }

    if (isNeedHandler) {
        data.setResult(result);
        handlerResult = afterProcess(data, handlerName);
    }

    return result;
}