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:de.codecentric.capturereplay.CaptureReplayAdvice.java

License:Apache License

@Around("execution(@de.codecentric.capturereplay.Capturable * *(..))")
public Object aroundCapturableMethod(ProceedingJoinPoint pjp) throws Throwable {
    MethodSignature signature = (MethodSignature) pjp.getSignature();
    if (Mode.CAPTURE.equals(mode)) {
        Object returnValue = pjp.proceed();
        dataMapper.writeCapturedData(signature, returnValue, pjp.getArgs());
        return returnValue;
    } else if (Mode.REPLAY.equals(mode)) {
        return dataMapper.getCapturedData(signature.getMethod().getName(), pjp.getArgs());
    } else if (Mode.DISABLED.equals(mode)) {
        return pjp.proceed();
    } else {//from  w w w  . j a  v  a  2  s. c o m
        throw new IllegalCaptureReplayUsageException(
                String.format("Capturing/replaying is switched off. You should not use %s directly.",
                        this.getClass().getSimpleName()));
    }
}

From source file:de.codecentric.spring.boot.chaos.monkey.watcher.SpringComponentAspect.java

License:Apache License

@Around("classAnnotatedWithComponentPointcut() && allPublicMethodPointcut() && !classInChaosMonkeyPackage()")
public Object intercept(ProceedingJoinPoint pjp) throws Throwable {
    // metrics/*from w w w  . j  a v  a  2 s  .c o  m*/
    if (metricEventPublisher != null)
        metricEventPublisher.publishMetricEvent(calculatePointcut(pjp.toShortString()), MetricType.COMPONENT);

    MethodSignature signature = (MethodSignature) pjp.getSignature();

    chaosMonkey.callChaosMonkey(createSignature(signature));

    return pjp.proceed();
}

From source file:de.codecentric.spring.boot.chaos.monkey.watcher.SpringControllerAspect.java

License:Apache License

@Around("classAnnotatedWithControllerPointcut() && allPublicMethodPointcut() && !classInChaosMonkeyPackage()")
public Object intercept(ProceedingJoinPoint pjp) throws Throwable {

    MethodSignature signature = (MethodSignature) pjp.getSignature();
    // metrics//w ww  . ja v a2 s.c o  m
    if (metricEventPublisher != null)
        metricEventPublisher.publishMetricEvent(calculatePointcut(pjp.toShortString()), MetricType.CONTROLLER);

    chaosMonkey.callChaosMonkey(createSignature(signature));

    return pjp.proceed();
}

From source file:de.codecentric.spring.boot.chaos.monkey.watcher.SpringRepositoryAspect.java

License:Apache License

@Around("implementsCrudRepository() && allPublicMethodPointcut() && !classInChaosMonkeyPackage()")
public Object intercept(ProceedingJoinPoint pjp) throws Throwable {

    // metrics/* w w w .  j  a v  a  2 s .c  o  m*/
    if (metricEventPublisher != null)
        metricEventPublisher.publishMetricEvent(calculatePointcut(pjp.toShortString()), MetricType.REPOSITORY);

    MethodSignature signature = (MethodSignature) pjp.getSignature();

    chaosMonkey.callChaosMonkey(createSignature(signature));

    return pjp.proceed();
}

From source file:de.codecentric.spring.boot.chaos.monkey.watcher.SpringRestControllerAspect.java

License:Apache License

@Around("classAnnotatedWithControllerPointcut() && allPublicMethodPointcut() && !classInChaosMonkeyPackage()")
public Object intercept(ProceedingJoinPoint pjp) throws Throwable {

    // metrics//from   w w  w.  ja  v a 2 s.  co m
    if (metricEventPublisher != null)
        metricEventPublisher.publishMetricEvent(calculatePointcut(pjp.toShortString()),
                MetricType.RESTCONTROLLER);

    MethodSignature signature = (MethodSignature) pjp.getSignature();

    chaosMonkey.callChaosMonkey(createSignature(signature));

    return pjp.proceed();
}

From source file:de.codecentric.spring.boot.chaos.monkey.watcher.SpringServiceAspect.java

License:Apache License

@Around("classAnnotatedWithControllerPointcut() && allPublicMethodPointcut() && !classInChaosMonkeyPackage()")
public Object intercept(ProceedingJoinPoint pjp) throws Throwable {
    LOGGER.debug(//w w  w.j av a 2 s. c  o  m
            LOGGER.isDebugEnabled() ? "Service class and public method detected: " + pjp.getSignature() : null);

    if (metricEventPublisher != null)
        metricEventPublisher.publishMetricEvent(calculatePointcut(pjp.toShortString()), MetricType.SERVICE);

    MethodSignature signature = (MethodSignature) pjp.getSignature();

    chaosMonkey.callChaosMonkey(createSignature(signature));

    return pjp.proceed();
}

From source file:de.cosmocode.palava.core.aop.NegateAspect.java

License:Apache License

/**
 * An advice which blocks methods annotated with {@link Negate}.
 *
 * @since 2.9/* w w w.j  a v  a  2 s.  co  m*/
 * @param point the proceeding join point
 * @return the new result
 */
@Around("call(@de.cosmocode.palava.core.aop.Negate * *.*())")
public Boolean block(ProceedingJoinPoint point) {
    checkInjected();
    LOG.trace("Negating {}", point.getStaticPart());

    try {
        return invert(point.proceed());
        /* CHECKSTYLE:OFF */
    } catch (Throwable e) {
        /* CHECKSTYLE:ON */
        throw Throwables.sneakyThrow(e);
    }
}

From source file:de.cosmocode.palava.jpa.aspectj.EntityTransactionAspect.java

License:Apache License

@Around("execution(@de.cosmocode.palava.jpa.Transactional * *.*(..))")
public Object transactional(ProceedingJoinPoint point) {
    checkInjected();/*from  w  w w .j  a  va  2 s . c om*/

    final EntityManager manager = currentManager.get();
    LOG.trace("Retrieved entitymanager {}", manager);
    final EntityTransaction tx = manager.getTransaction();
    LOG.trace("Using transaction {}", tx);

    final boolean local = !tx.isActive();

    if (local) {
        LOG.debug("Beginning automatic transaction {}", tx);
        tx.begin();
    } else {
        LOG.trace("Transaction {} already active", tx);
    }

    final Object returnValue;

    try {
        returnValue = point.proceed();
    } catch (Throwable e) {
        try {
            if (local && (tx.isActive() || tx.getRollbackOnly())) {
                LOG.debug("Rolling back local/active transaction {}", tx);
                tx.rollback();
            } else if (!tx.getRollbackOnly()) {
                LOG.debug("Setting transaction {} as rollback only", tx);
                tx.setRollbackOnly();
            }
        } catch (PersistenceException inner) {
            LOG.error("Rollback failed", inner);
        } finally {
            throw Throwables.sneakyThrow(e);
        }
    }

    if (local && tx.isActive()) {
        if (tx.getRollbackOnly()) {
            LOG.debug("Rolling back marked transaction {}", tx);
            tx.rollback();
        } else {
            try {
                tx.commit();
                LOG.debug("Committed automatic transaction {}", tx);
            } catch (PersistenceException e) {
                if (tx.isActive()) {
                    try {
                        LOG.debug("Rolling back transaction {}", tx);
                        tx.rollback();
                    } catch (PersistenceException inner) {
                        LOG.error("Rollback failed", inner);
                    }
                }
                throw e;
            }
        }
    } else {
        LOG.trace("Not committing non-local transaction {}", tx);
    }

    return returnValue;
}

From source file:de.cosmocode.palava.scope.AbstractUnitOfWorkScopeAspect.java

License:Apache License

private Object proceed(ProceedingJoinPoint point) {
    try {//from  ww  w .j a v  a2 s.c o  m
        return point.proceed();
        /* CHECKSTYLE:OFF */
    } catch (Throwable e) {
        /* CHECKSTYLE:ON */
        throw Throwables.sneakyThrow(e);
    }
}

From source file:de.dan_nrw.caching.CachingAspect.java

License:Open Source License

@Around("cachablePointcut()")
public Object aroundCachable(final ProceedingJoinPoint joinPoint) throws Throwable {
    MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
    Cachable cachableAnnotation = (Cachable) methodSignature.getMethod().getAnnotation(Cachable.class);
    Cache cache = Cache.getCurrent();//w  w  w.  java  2  s  .  c  om

    try {
        if (cache.containsKey(cachableAnnotation.key())) {
            // if key is already in cache and data is not expired
            return cache.get(cachableAnnotation.key());
        }
    } catch (IllegalArgumentException ex) {
        // if key does not exists, data must be retrieved
    } catch (CachedDataExpiredException ex) {
        // if data stored in cache is expired, it must be retrieved
    }

    // determinig data
    Object data = joinPoint.proceed();

    // cache is filled
    if (data != null) {
        cache.put(cachableAnnotation.key(), data, cachableAnnotation.durability());
    }

    // returning result
    return data;
}