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.crossbusiness.resiliency.aspect.AbstractRetryAspect.java

License:Open Source License

public Object doRetry(ProceedingJoinPoint pjp, Retry retryConfig) throws Throwable {
    Class<? extends Exception>[] retryableExceptions = retryConfig.exceptions();

    int attempts = retryConfig.attempts();
    long delay = retryConfig.delay();
    if (!(attempts > 0)) {
        attempts = this.maxRetries;
    }/*w  w w  . ja  va2s .c  o  m*/

    log.info("Attempting operation with potential for {} with maximum {} retries", retryableExceptions,
            attempts);

    int numAttempts = 0;
    do {
        numAttempts++;
        try {
            return pjp.proceed();
        } catch (InterruptedException ex) {
            Thread.currentThread().interrupt();
            throw ex;
        } catch (Throwable ex) {
            // if the exception is not what we're looking for, pass it through
            if (!isRetryableException(ex, retryableExceptions))
                throw ex;

            // we caught the configured exception, retry unless we've reached the maximum
            if (numAttempts > attempts) {
                log.warn("Exceeded maximum retries ({}), rethrowing Exception [{}]", attempts, ex);
                throw ex;
            }

            log.info("Caught Exception: [{}]. \n\t\t Attempt#: {}, Will retry after {} {}",
                    new Object[] { ex, numAttempts, delay, retryConfig.unit() });

            if (delay > 0) {
                retryConfig.unit().sleep(delay);
            }
        }
    } while (numAttempts <= attempts);
    // this will never execute - we will have either succesfully returned or rethrown an exception
    return null;
}

From source file:com.crossbusiness.resiliency.aspect.AbstractTimeoutAspect.java

License:Open Source License

public Object doTimeout(final ProceedingJoinPoint point, Timeout timeoutConfig) throws Throwable {
    log.debug(point + " -> " + timeoutConfig);
    final AbstractTimeoutAspect.Call call = new AbstractTimeoutAspect.Call(point, timeoutConfig);
    this.calls.add(call);
    Object output;/*from ww  w .  ja  v  a  2 s .  c  o  m*/
    try {
        output = point.proceed();
    } finally {
        this.calls.remove(call);
    }
    return output;
}

From source file:com.crossbusiness.resiliency.aspect.spring.AnnotationFallbackAspect.java

License:Open Source License

public Object rerouteToFallback(ProceedingJoinPoint pjp, Fallback fallbackConfig) throws Throwable {

    String[] fallbacks = fallbackConfig.value();
    Class<? extends Throwable>[] fallbackableExceptions = fallbackConfig.exceptions();

    List<Object> fallbackBeans = new ArrayList<Object>(fallbacks.length);
    for (String fallback : fallbacks) {
        try {//  ww w .ja v a 2  s  .  c om
            fallbackBeans.add(context.getBean(fallback));
        } catch (BeansException be) {
            log.error("configuration error: cannot find bean with name: '{}'", fallback, be);
            //configuration errors should be fixed immediately.
            throw be;
        }
    }

    MethodSignature targetMethodSig = (MethodSignature) pjp.getSignature();
    Method targetMethod = targetMethodSig.getMethod();
    Class[] paramTypes = (Class[]) targetMethod.getParameterTypes();
    Object[] args = pjp.getArgs();

    log.debug("fallbacks: {} method: '{}'", fallbacks, targetMethod);

    try {
        return pjp.proceed();
    } catch (Throwable t) {

        // if the exception is not what we're looking for, rethrow it
        if (!isFallbackableException(t, fallbackableExceptions))
            throw t;

        log.debug("got exception while trying the targetBean method: '{}'. will try fallbackBean...",
                targetMethod);
        Iterator<Object> iter = fallbackBeans.iterator();
        while (iter.hasNext()) {
            Object fallbackBean = iter.next();
            Method fallbackMethod;
            try {
                fallbackMethod = fallbackBean.getClass().getMethod(targetMethod.getName(), paramTypes);
            } catch (NoSuchMethodException | SecurityException nsme) {
                log.error(
                        "configuration error: No matchig method found in fallbackBean: '{}' that matches to targetBean method: '{}'",
                        new Object[] { fallbackBean.getClass().getName(), targetMethod, nsme });
                //configuration errors should be fixed immediately.
                throw nsme;
            }
            try {
                log.debug("trying fallbackBean method: '{}'...", fallbackMethod);
                return fallbackMethod.invoke(fallbackBean, args);
            } catch (IllegalArgumentException | IllegalAccessException iae) {
                log.error(
                        "configuration error: arguments missmatch: fallbackBean method: '{}' arguments  missmatch to targetBean method: '{}' arguments",
                        new Object[] { fallbackMethod, targetMethod, iae });
                //configuration errors should be fixed immediately.
                throw iae;
            } catch (InvocationTargetException ite) {
                log.debug(
                        "got exception while trying the fallbackBean method: '{}'. will try next fallbackBean...",
                        fallbackMethod);
                //fallbackBean method thrown an exception. try next bean or throw exception if this is the last bean
                if (!iter.hasNext()) {
                    //TODO : do we still need to check isFallbackableException?
                    throw ite.getCause();
                }
            }
        }
        //code should never reach this line.
        throw t;
    }
}

From source file:com.crossbusiness.resiliency.aspect.spring.AnnotationTimeoutAspect.java

License:Open Source License

public Object doTimeout(final ProceedingJoinPoint point, Timeout timeoutConfig) throws Throwable {
    log.debug(point + " -> " + timeoutConfig);
    final AnnotationTimeoutAspect.Call call = new AnnotationTimeoutAspect.Call(point, timeoutConfig);
    this.calls.add(call);
    Object output;/*  w  w w . ja  va 2s .c o  m*/
    try {
        output = point.proceed();
    } finally {
        this.calls.remove(call);
    }
    return output;
}

From source file:com.daphne.es.extra.aop.ResourceMenuCacheAspect.java

License:Apache License

@Around(value = "resourceServicePointcut() && resourceCacheablePointcut(arg)", argNames = "pjp,arg")
public Object findRolesCacheableAdvice(ProceedingJoinPoint pjp, User arg) throws Throwable {

    User user = arg;/*  ww w.  j ava  2s .c o  m*/

    String key = menusKey(user.getId());
    Object retVal = get(key);

    if (retVal != null) {
        log.debug("cacheName:{}, method:findRolesCacheableAdvice, hit key:{}", cacheName, key);
        return retVal;
    }
    log.debug("cacheName:{}, method:findRolesCacheableAdvice, miss key:{}", cacheName, key);

    retVal = pjp.proceed();

    put(key, retVal);

    return retVal;
}

From source file:com.daphne.es.extra.aop.UserAuthCacheAspect.java

License:Apache License

@Around(value = "userAuthServicePointcut() && cacheFindRolesPointcut(arg)", argNames = "pjp,arg")
public Object findRolesCacheableAdvice(ProceedingJoinPoint pjp, User arg) throws Throwable {
    User user = arg;/*from w w w . j ava 2 s .  co m*/

    String key = null;
    if (user != null) {
        key = rolesKey(user.getId());
    }

    Object retVal = get(key);

    if (retVal != null) {
        log.debug("cacheName:{}, method:findRolesCacheableAdvice, hit key:{}", cacheName, key);
        return retVal;
    }

    log.debug("cacheName:{}, method:findRolesCacheableAdvice, miss key:{}", cacheName, key);

    retVal = pjp.proceed();

    this.put(key, retVal);

    return retVal;
}

From source file:com.daphne.es.extra.aop.UserAuthCacheAspect.java

License:Apache License

@Around(value = "userAuthServicePointcut() && cacheFindStringRolesPointcut(arg)", argNames = "pjp,arg")
public Object findStringRolesCacheableAdvice(ProceedingJoinPoint pjp, User arg) throws Throwable {
    User user = arg;//from ww  w  . j  a  va2s .c  o  m

    String key = null;
    if (user != null) {
        key = stringRolesKey(user.getId());
    }

    Object retVal = get(key);

    if (retVal != null) {
        log.debug("cacheName:{}, method:findStringRolesCacheableAdvice, hit key:{}", cacheName, key);
        return retVal;
    }
    log.debug("cacheName:{}, method:findStringRolesCacheableAdvice, miss key:{}", cacheName, key);

    retVal = pjp.proceed();

    this.put(key, retVal);

    return retVal;
}

From source file:com.daphne.es.extra.aop.UserAuthCacheAspect.java

License:Apache License

@Around(value = "userAuthServicePointcut() && cacheFindStringPermissionsPointcut(arg)", argNames = "pjp,arg")
public Object findStringPermissionsCacheableAdvice(ProceedingJoinPoint pjp, User arg) throws Throwable {
    User user = arg;//from   w w w .  j a  v  a 2  s  . c o m

    String key = stringPermissionsKey(user.getId());

    Object retVal = get(key);

    if (retVal != null) {
        log.debug("cacheName:{}, method:findStringPermissionsCacheableAdvice, hit key:{}", cacheName, key);
        return retVal;
    }
    log.debug("cacheName:{}, method:findStringPermissionsCacheableAdvice, miss key:{}", cacheName, key);

    retVal = pjp.proceed();

    this.put(key, retVal);

    return retVal;
}

From source file:com.daphne.es.extra.aop.UserCacheAspect.java

License:Apache License

@Around(value = "userServicePointcut() && cacheablePointcut()")
public Object cacheableAdvice(ProceedingJoinPoint pjp) throws Throwable {

    String methodName = pjp.getSignature().getName();
    Object arg = pjp.getArgs().length >= 1 ? pjp.getArgs()[0] : null;

    String key = "";
    boolean isIdKey = false;
    if ("findOne".equals(methodName)) {
        key = idKey(String.valueOf(arg));
        isIdKey = true;/*from  w w w  .  j  ava2s  .c  om*/
    } else if ("findByUsername".equals(methodName)) {
        key = usernameKey((String) arg);
    } else if ("findByEmail".equals(methodName)) {
        key = emailKey((String) arg);
    } else if ("findByMobilePhoneNumber".equals(methodName)) {
        key = mobilePhoneNumberKey((String) arg);
    }

    User user = null;
    if (isIdKey == true) {
        user = get(key);
    } else {
        Long id = get(key);
        if (id != null) {
            key = idKey(String.valueOf(id));
            user = get(key);
        }
    }
    //cache hit
    if (user != null) {
        log.debug("cacheName:{}, hit key:{}", cacheName, key);
        return user;
    }
    log.debug("cacheName:{}, miss key:{}", cacheName, key);

    //cache miss
    user = (User) pjp.proceed();

    //put cache
    put(user);
    return user;

}

From source file:com.dchq.docker.volume.driver.exceptions.ExceptionTranslator.java

License:Open Source License

@Around("bean(*Controller)")
public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {
    try {/*from  w ww  . jav  a 2 s .  c o m*/
        Object retVal = pjp.proceed();
        return retVal;
    } catch (DCHQRuntimeException e) {
        String logId = UUID.randomUUID().toString();
        logger.warn("ERROR-ID [{}]", logId);
        logger.warn(e.getLocalizedMessage());
        return new BaseResponse().withErr(e.getLocalizedMessage());
    } catch (Exception e) {
        String logId = UUID.randomUUID().toString();
        logger.warn("ERROR-ID [{}]", logId);
        logger.warn(e.getLocalizedMessage(), e);
        return new BaseResponse().withErr(e.getLocalizedMessage());
    }

}