Search in sources :

Example 36 with ProceedingJoinPoint

use of org.aspectj.lang.ProceedingJoinPoint in project data-prep by Talend.

the class AnnotationUtils method getAnnotatedParameterIndex.

/**
 * Returns the id of the parameter annotated with <code>annotationClass</code> in all the <code>pjp</code>
 * arguments. If multiple parameters hold the annotation, returns the index of the <b>last</b> parameter.
 *
 * @param pjp The {@link ProceedingJoinPoint} to check for annotation in parameters.
 * @param annotationClass The annotation to look for.
 * @return The index of the annotated parameter or -1 if not found.
 */
public static int getAnnotatedParameterIndex(ProceedingJoinPoint pjp, Class<? extends Annotation> annotationClass) {
    MethodSignature ms = (MethodSignature) pjp.getSignature();
    Method m = ms.getMethod();
    Annotation[][] pa = m.getParameterAnnotations();
    int idParameterIndex = -1;
    int i = 0;
    for (Annotation[] annotations : pa) {
        for (Annotation annotation : annotations) {
            if (annotation.annotationType().equals(annotationClass)) {
                idParameterIndex = i;
            }
        }
        i++;
    }
    return idParameterIndex;
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) Method(java.lang.reflect.Method) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Annotation(java.lang.annotation.Annotation)

Example 37 with ProceedingJoinPoint

use of org.aspectj.lang.ProceedingJoinPoint in project codekvast by crispab.

the class RestartableTransactionAspect method restartableOperation.

@Around("anyRestartable() && methodExecution() && withinCodekvast()")
public Object restartableOperation(ProceedingJoinPoint pjp) throws Throwable {
    String joinPoint = pjp.toShortString();
    logger.debug("Before {}", joinPoint);
    final int maxAttempt = 3;
    for (int attempt = 1; attempt < maxAttempt; attempt++) {
        Instant startedAt = Instant.now();
        try {
            Object result = pjp.proceed();
            logger.debug("After {}", joinPoint);
            return result;
        } catch (Throwable t) {
            if (isRetryableException(t)) {
                int delayMillis = getRandomInt(10, 50);
                logger.info("Deadlock #{} after {} in {}, will retry in {} ms. Cause={}.", attempt, humanReadableDuration(startedAt, Instant.now()), joinPoint, delayMillis, getCause(t));
                Thread.sleep(delayMillis);
            } else {
                throw t;
            }
        }
    }
    logger.warn("Executing a last retry attempt at {}", joinPoint);
    return pjp.proceed();
}
Also used : Instant(java.time.Instant) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Around(org.aspectj.lang.annotation.Around)

Example 38 with ProceedingJoinPoint

use of org.aspectj.lang.ProceedingJoinPoint in project spring-framework by spring-projects.

the class TestBeanAdvisor method doubleReturnValue.

@Around("execution(int *.getAge())")
public Object doubleReturnValue(ProceedingJoinPoint pjp) throws Throwable {
    ++this.invocations;
    int result = (Integer) pjp.proceed();
    return result * this.multiple;
}
Also used : JoinPoint(org.aspectj.lang.JoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Around(org.aspectj.lang.annotation.Around)

Example 39 with ProceedingJoinPoint

use of org.aspectj.lang.ProceedingJoinPoint in project spring-framework by spring-projects.

the class AspectJAroundAdvice method invoke.

@Override
public Object invoke(MethodInvocation mi) throws Throwable {
    if (!(mi instanceof ProxyMethodInvocation)) {
        throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
    }
    ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi;
    ProceedingJoinPoint pjp = lazyGetProceedingJoinPoint(pmi);
    JoinPointMatch jpm = getJoinPointMatch(pmi);
    return invokeAdviceMethod(pjp, jpm, null, null);
}
Also used : ProxyMethodInvocation(org.springframework.aop.ProxyMethodInvocation) JoinPointMatch(org.aspectj.weaver.tools.JoinPointMatch) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint)

Example 40 with ProceedingJoinPoint

use of org.aspectj.lang.ProceedingJoinPoint in project spring-framework by spring-projects.

the class AbstractAspectJAdvice method calculateArgumentBindings.

/**
	 * Do as much work as we can as part of the set-up so that argument binding
	 * on subsequent advice invocations can be as fast as possible.
	 * <p>If the first argument is of type JoinPoint or ProceedingJoinPoint then we
	 * pass a JoinPoint in that position (ProceedingJoinPoint for around advice).
	 * <p>If the first argument is of type {@code JoinPoint.StaticPart}
	 * then we pass a {@code JoinPoint.StaticPart} in that position.
	 * <p>Remaining arguments have to be bound by pointcut evaluation at
	 * a given join point. We will get back a map from argument name to
	 * value. We need to calculate which advice parameter needs to be bound
	 * to which argument name. There are multiple strategies for determining
	 * this binding, which are arranged in a ChainOfResponsibility.
	 */
public final synchronized void calculateArgumentBindings() {
    // The simple case... nothing to bind.
    if (this.argumentsIntrospected || this.parameterTypes.length == 0) {
        return;
    }
    int numUnboundArgs = this.parameterTypes.length;
    Class<?>[] parameterTypes = this.aspectJAdviceMethod.getParameterTypes();
    if (maybeBindJoinPoint(parameterTypes[0]) || maybeBindProceedingJoinPoint(parameterTypes[0])) {
        numUnboundArgs--;
    } else if (maybeBindJoinPointStaticPart(parameterTypes[0])) {
        numUnboundArgs--;
    }
    if (numUnboundArgs > 0) {
        // need to bind arguments by name as returned from the pointcut match
        bindArgumentsByName(numUnboundArgs);
    }
    this.argumentsIntrospected = true;
}
Also used : JoinPoint(org.aspectj.lang.JoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint)

Aggregations

ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)78 Around (org.aspectj.lang.annotation.Around)33 MethodSignature (org.aspectj.lang.reflect.MethodSignature)16 Method (java.lang.reflect.Method)14 Test (org.junit.Test)14 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)10 SimpleDateFormat (java.text.SimpleDateFormat)8 ArrayList (java.util.ArrayList)8 JoinPoint (org.aspectj.lang.JoinPoint)8 FaseDTO (com.tomasio.projects.trainning.dto.FaseDTO)7 OrganizacaoDTO (com.tomasio.projects.trainning.dto.OrganizacaoDTO)7 PessoaDTO (com.tomasio.projects.trainning.dto.PessoaDTO)7 MockProceedingJoinPoint (org.finra.herd.core.MockProceedingJoinPoint)7 Annotation (java.lang.annotation.Annotation)5 CancelamentoMatriculaDTO (com.tomasio.projects.trainning.dto.CancelamentoMatriculaDTO)4 MatriculaDTO (com.tomasio.projects.trainning.dto.MatriculaDTO)4 Date (java.util.Date)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 Action (org.apache.nifi.action.Action)4 MessageHeader (org.finra.herd.model.dto.MessageHeader)4