Example usage for org.aspectj.lang ProceedingJoinPoint getSignature

List of usage examples for org.aspectj.lang ProceedingJoinPoint getSignature

Introduction

In this page you can find the example usage for org.aspectj.lang ProceedingJoinPoint getSignature.

Prototype

Signature getSignature();

Source Link

Document

getStaticPart().getSignature() returns the same object

Usage

From source file:com.clicktravel.cheddar.application.retry.RetryableAspectTest.java

License:Apache License

private ProceedingJoinPoint setupSimpleProceedingJoinPointMock() {
    final ProceedingJoinPoint mockProceedingJoinPoint = mock(ProceedingJoinPoint.class);
    final MethodSignature mockMethodSignature = mock(MethodSignature.class);

    when(mockProceedingJoinPoint.getThis()).thenReturn(mockProceedingJoinPoint);
    when(mockProceedingJoinPoint.getSignature()).thenReturn(mockMethodSignature);
    when(mockMethodSignature.getParameterTypes()).thenReturn(new Class[0]);
    return mockProceedingJoinPoint;
}

From source file:com.clicktravel.cheddar.server.application.logging.LoggingAspect.java

License:Apache License

private String methodCallDetail(final ProceedingJoinPoint point) {
    final StringBuilder sb = new StringBuilder();
    sb.append(point.getTarget().getClass().getSimpleName());
    sb.append('.');
    sb.append(((MethodSignature) (point.getSignature())).getMethod().getName());
    sb.append('(');
    boolean firstArg = true;
    for (final Object arg : point.getArgs()) {
        if (!firstArg) {
            sb.append(',');
        }//from  ww w. jav  a 2  s  .  c  om
        firstArg = false;
        sb.append(arg == null ? "null" : arg.toString());
    }
    sb.append(')');
    return sb.toString();
}

From source file:com.cloud.event.ActionEventInterceptor.java

License:Apache License

public Object AroundAnyMethod(ProceedingJoinPoint call) throws Throwable {
    MethodSignature methodSignature = (MethodSignature) call.getSignature();
    Method targetMethod = methodSignature.getMethod();
    if (needToIntercept(targetMethod)) {
        EventVO event = interceptStart(targetMethod);

        boolean success = true;
        Object ret = null;/*from   w ww  .  ja v a 2s  . c  o  m*/
        try {
            ret = call.proceed();
        } catch (Throwable e) {
            success = false;
            interceptException(targetMethod, event);
            throw e;
        } finally {
            if (success) {
                interceptComplete(targetMethod, event);
            }
        }
        return ret;
    }
    return call.proceed();
}

From source file:com.cloud.utils.db.TransactionContextBuilder.java

License:Apache License

public Object AroundAnyMethod(ProceedingJoinPoint call) throws Throwable {
    MethodSignature methodSignature = (MethodSignature) call.getSignature();
    Method targetMethod = methodSignature.getMethod();
    if (needToIntercept(targetMethod)) {
        Transaction txn = Transaction.open(call.getSignature().getName());
        Object ret = null;//from ww w .j  av a 2 s  .  co m
        try {
            ret = call.proceed();
        } finally {
            txn.close();
        }
        return ret;
    }
    return call.proceed();
}

From source file:com.create.aop.LoggingAspect.java

License:Apache License

private String getWatchId(ProceedingJoinPoint joinPoint) {
    final String className = getClassName(joinPoint.getTarget());
    final String methodName = getMethodName(joinPoint.getSignature());
    return String.format("%s - %s", className, methodName);
}

From source file:com.create.aop.LoggingAspect.java

License:Apache License

private String getQueryWatchId(ProceedingJoinPoint joinPoint) {
    final String methodName = getMethodName(joinPoint.getSignature());
    final String arguments = Arrays.toString(joinPoint.getArgs());
    return String.format("%s%s", methodName, arguments);
}

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

License:Open Source License

/**
 * Intercept the given method invocation, submit the actual calling of the method to
 * the correct task executor and return immediately to the caller.
 * @return {@link Future} if the original method returns {@code Future}; {@code null}
 * otherwise./*w w  w  .ja  va2 s  .  co  m*/
 */
// @Around("asyncMethodExecution()")
private Object doAsync(final ProceedingJoinPoint point, Async asyncConfig) throws Throwable {
    log.debug(point + " -> " + asyncConfig);

    String qualifier = asyncConfig.value();
    MethodSignature targetMethodSig = (MethodSignature) point.getSignature();
    AsyncTaskExecutor executor = getExecutor(targetMethodSig.getMethod(), qualifier);

    if (executor == null) {
        return point.proceed();
    }

    Callable<Object> callable = new Callable<Object>() {
        public Object call() throws Exception {
            try {
                Object result = point.proceed();
                if (result instanceof Future) {
                    return ((Future<?>) result).get();
                }
            } catch (Throwable ex) {
                ReflectionUtils.rethrowException(ex);
            }
            return null;
        }
    };

    Future<?> result = executor.submit(callable);

    if (Future.class.isAssignableFrom(targetMethodSig.getMethod().getReturnType())) {
        return result;
    } else {
        return null;
    }
}

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

License:Open Source License

public Object breakCircuit(final ProceedingJoinPoint pjp, CircuitBreaker circuitBreakerConfig)
        throws Throwable {
    Object result = null;/*  ww w .  jav  a  2  s  .c  o m*/
    final String method = pjp.getSignature().toLongString();
    CircuitBreakerStatus status = null;
    try {
        final MethodSignature sig = (MethodSignature) pjp.getStaticPart().getSignature();
        registry.registeredMehtodIfnecessary(method, circuitBreakerConfig);
        status = registry.getStatusWithHalfOpenExclusiveLockTry(method);
        if (status.equals(CircuitBreakerStatus.OPEN)) {
            log.info("CIRCUIT STATUS: OPEN. Method {} can not be executed. try later!", method);
            throw new OpenCircuitException();
        } else if (status.equals(CircuitBreakerStatus.HALF_OPEN)) {
            log.info(
                    "CIRCUIT STATUS: HALF_OPEN. Another thread has the exclusive lock for half open. Method {} can not be executed.",
                    method);
            throw new OpenCircuitException();
        } else if (status.equals(CircuitBreakerStatus.CLOSED)) {
            log.info("CIRCUIT STATUS: CLOSED. execute method {}", method);
            result = proceed(pjp);
        } else if (status.equals(CircuitBreakerStatus.HALF_OPEN_EXCLUSIVE)) {
            log.info(
                    "CIRCUIT STATUS: HALF_OPEN_EXCLUSIVE. This thread win the exclusive lock for the half open call. execute method: {}",
                    method);
            result = proceed(pjp);
            log.info(
                    "CIRCUIT STATUS: HALF_OPEN_EXCLUSIVE. method execution was successfull. now close circuit for method {}",
                    method);
            registry.closeAndUnlock(method);
        }

    } catch (CircuitBreakerMethodExecutionException e) {
        Throwable throwable = e.getCause();
        for (Class<? extends Throwable> clazz : registry.getfailureIndications(method)) {
            if (clazz.isAssignableFrom(throwable.getClass())) {
                // detected a failure
                log.info("detected failure. failure indication: {} \nException:", clazz.getCanonicalName(),
                        throwable);
                if (status.equals(CircuitBreakerStatus.CLOSED)
                        && registry.sameClosedCycleInLocalAndGlobaleContext(method)) {
                    log.info("Valid failure: method call and failure are in the same CLOSED cycle.");
                    registry.addFailureAndOpenCircuitIfThresholdAchived(method);
                } else if (status.equals(CircuitBreakerStatus.HALF_OPEN_EXCLUSIVE)) {
                    registry.keepOpenAndUnlock(method);
                }
                throw throwable;
            }
        }
        // thrown exception is not a failureIndication
        if (status.equals(CircuitBreakerStatus.HALF_OPEN_EXCLUSIVE)) {
            log.info(
                    "CIRCUIT STATUS: HALF_OPEN_EXCLUSIVE. method execution was successfull. now close circuit for method {}",
                    method);
            registry.closeAndUnlock(method);
        }
        // throw the original method execution exception upper to the method invoker
        throw throwable;
    } finally {
        registry.cleanUp(method);
    }
    return result;
}

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

License:Open Source License

private Object proceed(ProceedingJoinPoint pjp) throws CircuitBreakerMethodExecutionException {
    try {/*from  w w  w.  j a v  a2s .com*/
        return pjp.proceed();
    } catch (Throwable t) {
        log.debug("Exception while method execution: {}", pjp.getSignature().toLongString());
        throw new CircuitBreakerMethodExecutionException(t);
    }
}

From source file:com.crossbusiness.resiliency.aspect.AbstractFallbackAspect.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 {//from   w  ww  .  j  a  va 2s  . c o  m
            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;
    }
}