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.aliyun.odps.OdpsDeprecatedLogger.java

License:Apache License

@Around("@annotation(Survey)")
public Object aroundOdpsImpl(ProceedingJoinPoint point) throws Throwable {
    //Thread Class
    //Deprecated Logger
    //Odps Implemention methods
    //User Code//from  ww w. j  av  a2s  .c  o  m

    // if usercode is not odps calling, log it.
    try {
        String callerClass = Thread.currentThread().getStackTrace()[3].getClassName();
        if (!callerClass.startsWith("com.aliyun.odps.")) {
            String methodSignature = point.getSignature().toString();
            Long calledTimes = getDeprecatedCalls().get(methodSignature);
            if (calledTimes == null) {
                calledTimes = 1L;
            } else {
                calledTimes += 1L;
            }
            getDeprecatedCalls().put(methodSignature, calledTimes);
        }
    } catch (Throwable e) {
        // do nothing
    }
    return point.proceed();
}

From source file:com.amazonaws.services.simpleworkflow.flow.aspectj.AsynchronousAspect.java

License:Open Source License

@SuppressWarnings({ "rawtypes", "unchecked" })
@Around("call(@com.amazonaws.services.simpleworkflow.flow.annotations.Asynchronous * *(..)) && @annotation(asynchronousAnnotation)")
public Object makeAsynchronous(ProceedingJoinPoint pjp, Asynchronous asynchronousAnnotation) throws Throwable {
    final Signature signature = pjp.getStaticPart().getSignature();
    if (signature instanceof MethodSignature) {
        final MethodSignature methodSignature = (MethodSignature) signature;
        int i = 0;
        Object[] methodArguments = pjp.getArgs();
        Annotation[][] parameterAnnotations = methodSignature.getMethod().getParameterAnnotations();
        List<Promise> valueParams = new ArrayList<Promise>();
        for (final Class<?> parameterType : methodSignature.getParameterTypes()) {
            if ((isPromise(parameterType) || isPromiseArray(parameterType)
                    || (isCollection(parameterType) && hasWaitAnnotation(parameterAnnotations[i])))
                    && !hasNoWaitAnnotation(parameterAnnotations[i])) {
                Object param = methodArguments[i];
                if (isPromise(parameterType)) {
                    valueParams.add((Promise) param);
                } else if (isCollection(parameterType)) {
                    valueParams.add(new AndPromise((Collection) param));
                } else {
                    valueParams.add(new AndPromise((Promise[]) param));
                }/*from  w  w  w .j a  v a2s .com*/
            } else {
                valueParams.add(null);
            }
            i++;
        }

        Promise[] values = valueParams.toArray(new Promise[0]);
        Boolean daemon = asynchronousAnnotation.daemon() ? true : null;
        AsynchronousAspectTask task = new AsynchronousAspectTask(daemon, pjp, values);
        return task.getReturnValue();
    }

    return pjp.proceed();
}

From source file:com.amazonaws.services.simpleworkflow.flow.aspectj.ExponentialRetryAspect.java

License:Open Source License

@Around("execution(@com.amazonaws.services.simpleworkflow.flow.annotations.ExponentialRetry * *(..)) && @annotation(retryAnnotation)")
public Object retry(final ProceedingJoinPoint pjp, ExponentialRetry retryAnnotation) throws Throwable {
    ExponentialRetryPolicy retryPolicy = createExponentialRetryPolicy(retryAnnotation);

    @SuppressWarnings("rawtypes")
    RetryCallable retryCallable = new RetryCallable() {

        @Override/*from   w w w. jav  a 2  s.co  m*/
        public Promise call() throws Throwable {
            return (Promise) pjp.proceed();
        }
    };

    boolean isVoidReturnType = false;
    final Signature signature = pjp.getStaticPart().getSignature();
    if (signature instanceof MethodSignature) {
        final MethodSignature methodSignature = (MethodSignature) signature;
        isVoidReturnType = (methodSignature != null) ? Void.TYPE.equals(methodSignature.getReturnType())
                : false;
    }

    RetryInterceptor interceptor = null;
    if (isVoidReturnType) {
        interceptor = new RetryInterceptorVoid(retryCallable, retryPolicy);
    } else {
        interceptor = new RetryInterceptorWithResult(retryCallable, retryPolicy);
    }

    return interceptor.execute();
}

From source file:com.amediamanager.metrics.MetricAspect.java

License:Apache License

@Around("sdkClients()")
public final Object logMetrics(ProceedingJoinPoint pjp) throws Throwable {
    final String service = pjp.getSignature().getDeclaringType().getSimpleName();
    final String operation = pjp.getSignature().getName();
    final long startTime = System.currentTimeMillis();

    Throwable exception = null;/*from   ww  w  . ja  va  2 s .c  o  m*/

    try {
        return pjp.proceed();
    } catch (Exception e) {
        exception = e;
        throw e;
    } finally {
        emitMetrics(service, operation, startTime, exception);
    }
}

From source file:com.androidenterprise.aspects.AspectAroundTest.java

License:Open Source License

@Around("execution(* eEnterpriseActivity+.new(..))")
public Object preceedingMethod(ProceedingJoinPoint p) throws Throwable {
    System.out.println("before instance");
    Object val = p.proceed();
    System.out.println("after instance");
    return val;
}

From source file:com.apress.progwt.server.gwt.GWTDebugAdvice.java

License:Apache License

/**
 * Make sure we realize what errors are being sent back to the client
 * /*from w ww  . j a v  a  2s  .c o  m*/
 * @param pjp
 * @return
 * @throws Throwable
 */
public Object wrapGWT(ProceedingJoinPoint pjp) throws Throwable {

    try {
        // start stopwatch
        Object retVal = pjp.proceed();

        return retVal;

    } catch (BusinessException e) {
        log.error("FAILURE: " + e + " " + e.getMessage());
        throw new BusinessException(e);
    } catch (Exception e) {
        log.error("FAILURE: " + e + " " + e.getMessage());
        if (log.isDebugEnabled()) {
            e.printStackTrace();
        }
        throw new BusinessException(e);
    }

}

From source file:com.apress.prospringintegration.corespring.aop.PurchaseOrderProcessorAspect.java

License:Apache License

@Around("execution(* com.apress.prospringintegration.corespring.aop.PurchaseOrderProcessor.processPurchaseOrder(..))")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
    String methodName = joinPoint.getSignature().getName();
    log.info(" Method: " + methodName);
    try {//from   www .j  a v  a 2s. c  o m
        Object result = joinPoint.proceed();
        log.info(" Method: " + methodName + "returns " + result);
        return result;
    } catch (IllegalArgumentException e) {
        log.error(e);
        throw e;
    }
}

From source file:com.apress.prospringintegration.corespring.aop.PurchaseOrderProcessorStatsAspect.java

License:Apache License

@Around("execution(* com.apress.prospringintegration.corespring.aop.PurchaseOrderProcessor.processPurchaseOrder(..))")
public Object aroundStatsAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
    String methodName = joinPoint.getSignature().getName();
    String classPackage = joinPoint.getSignature().getClass().getPackage().getName();

    String fullCall = classPackage + "." + methodName;
    try {/*  w w  w. j a  v  a 2 s . com*/
        long tStart = Calendar.getInstance().getTimeInMillis();
        Object result = joinPoint.proceed();
        long tEnd = Calendar.getInstance().getTimeInMillis();

        log.info(" Method: " + fullCall + " took " + (tEnd - tStart) + " miliseconds");
        return result;
    } catch (IllegalArgumentException e) {
        log.error(e);
        throw e;
    }
}

From source file:com.arto.core.intercepter.TxMessageAspect.java

License:Apache License

@Around("pointcutTxMessage()")
public Object doTransactionMessage(ProceedingJoinPoint pjp) throws Throwable {
    // ???/*from   w w  w . j a  v  a2 s.  c  om*/
    DataSource dataSource = transactionManager.getDataSource();
    // ??
    assertTransactional(dataSource);
    // ??
    ConnectionHolder conHolder = (ConnectionHolder) TransactionSynchronizationManager.getResource(dataSource);
    final Connection conn = conHolder.getConnection();
    // ???
    Method setterMethod = ReflectionUtils.findMethod(ConnectionHolder.class, "setConnection", Connection.class);
    ReflectionUtils.makeAccessible(setterMethod);
    // ?commit
    ReflectionUtils.invokeMethod(setterMethod, conHolder, Proxy.newProxyInstance(
            resourceLoader.getClassLoader(), new Class<?>[] { Connection.class }, new InvocationHandler() {
                @Override
                public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                    try {
                        return method.invoke(conn, args);
                    } finally {
                        // ?commit??????
                        if ("commit".equals(method.getName())) {
                            List<MqEvent> txMessages = TxMessageContextHolder.getTxMessages();
                            if (txMessages != null) {
                                MqEvent message;
                                for (int i = 0; i < txMessages.size(); i++) {
                                    message = txMessages.get(i);
                                    MqClient.getPipeline(message.getType()).offer(message);
                                }
                            }
                            TxMessageContextHolder.clear();
                        } else if ("rollback".equals(method.getName())) {
                            TxMessageContextHolder.clear();
                        }
                    }
                }
            }));
    // ?
    return pjp.proceed();
}

From source file:com.astonish.metrics.aspectj.MetricAdvice.java

License:Apache License

/**
 * Around advice for any metric-annotated {@link Method}.
 * @param pjp/*w  ww. ja  v  a  2  s  .c  o  m*/
 *            the {@link ProceedingJoinPoint}
 * @return the {@link Method} return object
 * @throws Throwable
 *             if any exception occurs
 */
@Around("scope() && (timedMethod() || meteredMethod() || exceptionMeteredMethod())")
public final Object aroundMetricAnnotatedMethod(ProceedingJoinPoint pjp) throws Throwable {
    final Method method = retrieveMethod(pjp);

    handleMeteredMethod(method);
    final ExceptionMeter exceptionMeter = handleExceptionMeteredMethod(method);
    final Context timerCtxt = handleTimedMethod(method);
    try {
        return pjp.proceed();
    } catch (Throwable t) {
        //@formatter:off
        if ((null != exceptionMeter)
                && (exceptionMeter.getExceptionClass().isAssignableFrom(t.getClass()) || (t.getCause() != null
                        && exceptionMeter.getExceptionClass().isAssignableFrom(t.getCause().getClass())))) {
            exceptionMeter.getMeter().mark();
        }
        //@formatter:on

        throw t;
    } finally {
        if (null != timerCtxt) {
            timerCtxt.stop();
        }
    }
}