Example usage for org.aspectj.lang.reflect MethodSignature getMethod

List of usage examples for org.aspectj.lang.reflect MethodSignature getMethod

Introduction

In this page you can find the example usage for org.aspectj.lang.reflect MethodSignature getMethod.

Prototype

Method getMethod();

Source Link

Usage

From source file:jp.co.opentone.bsol.framework.core.MethodTraceAdvice.java

License:Apache License

private Method getMethod(ProceedingJoinPoint jp) {
    MethodSignature s = (MethodSignature) jp.getSignature();
    return s.getMethod();
}

From source file:jsst.core.client.aspects.DispatcherAspect.java

License:LGPL

@SuppressWarnings({ "unchecked" })
@Around(value = "method()")
public void dispatch(ProceedingJoinPoint joinPoint) throws Throwable {
    MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
    ServerResponse response = getDispatcher().dispatch(methodSignature.getMethod());
    getHandler().handle(response);/*  w w w . jav  a2s  . c om*/
}

From source file:net.greencoding.thysdrus.circuitbreaker.aspect.CircuitBreakerAspect.java

License:Apache License

@Around("execution(@net.greencoding.thysdrus.circuitbreaker.annotation.MonitoredByCircuitBreaker * * (..))")
public Object breakCircuit(final ProceedingJoinPoint pjp) throws Throwable {
    Object returnObject = null;/*  w w  w .j  av a 2 s .c om*/
    final String method = pjp.getSignature().toLongString();
    CircuitBreakerStatus status = null;
    try {
        final MethodSignature sig = (MethodSignature) pjp.getStaticPart().getSignature();
        final MonitoredByCircuitBreaker cbAnnotation = sig.getMethod()
                .getAnnotation(MonitoredByCircuitBreaker.class);
        registry.registerMehtodIfnecessary(method, cbAnnotation);
        status = registry.getStatusWithHalfOpenExclusiveLockTry(method);
        if (status.equals(CircuitBreakerStatus.OPEN)) {
            logger.info("CIRCUIT STATUS: OPEN. Method {} can not be executed. try later!", method);
            if (cbAnnotation.isSilientMode()) {
                return null;
            } else {
                throw new OpenCircuitException();
            }
        } else if (status.equals(CircuitBreakerStatus.HALF_OPEN)) {
            logger.info(
                    "CIRCUIT STATUS: HALF_OPEN. Another thread has the exclusive lock for half open. Method {} can not be executed.",
                    method);
            if (cbAnnotation.isSilientMode()) {
                return null;
            } else {
                throw new OpenCircuitException();
            }
        } else if (status.equals(CircuitBreakerStatus.CLOSED)) {
            logger.info("CIRCUIT STATUS: CLOSED. execute method {}", method);
            returnObject = proceed(pjp);
        } else if (status.equals(CircuitBreakerStatus.HALF_OPEN_EXCLUSIVE)) {
            logger.info(
                    "CIRCUIT STATUS: HALF_OPEN_EXCLUSIVE. This thread win the exclusive lock for the half open call. execute method: {}",
                    method);
            returnObject = proceed(pjp);
            logger.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 
                logger.info("dectected failure. failure indication: {} \nException:", clazz.getCanonicalName(),
                        throwable);
                if (status.equals(CircuitBreakerStatus.CLOSED)
                        && registry.sameClosedCycleInLocalAndGlobaleContext(method)) {
                    logger.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)) {
            logger.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 returnObject;
}

From source file:net.sf.oval.guard.GuardAspect2.java

License:Open Source License

@SuppressAjWarnings("adviceDidNotMatch")
@Around("execution(* (@net.sf.oval.guard.Guarded *).*(..))")
public Object allMethods(final ProceedingJoinPoint thisJoinPoint) throws Throwable {
    final MethodSignature signature = (MethodSignature) thisJoinPoint.getSignature();

    LOG.debug("aroundMethod() {1}", signature);

    final Method method = signature.getMethod();
    final Object[] args = thisJoinPoint.getArgs();
    final Object target = thisJoinPoint.getTarget();

    return guard.guardMethod(target, method, args, new ProceedInvocable(thisJoinPoint));
}

From source file:net.sourceforge.safr.core.interceptor.SecurityAspect.java

License:Apache License

private FilterAttribute getMethodFilterAttribute(MethodSignature signature) {
    return getSecurityAttributeSource().getMethodFilterAttribute(signature.getMethod(),
            signature.getDeclaringType());
}

From source file:net.sourceforge.safr.core.interceptor.SecurityAspect.java

License:Apache License

private SecureAttribute getMethodSecureAttribute(MethodSignature signature) {
    return getSecurityAttributeSource().getMethodSecureAttribute(signature.getMethod(),
            signature.getDeclaringType());
}

From source file:net.sourceforge.safr.core.interceptor.SecurityAspect.java

License:Apache License

private SecureAttribute[] getParameterSecureAttributes(MethodSignature signature) {
    return getSecurityAttributeSource().getParameterSecureAttributes(signature.getMethod(),
            signature.getDeclaringType());
}

From source file:net.sourceforge.safr.core.invocation.AspectJProceedingInvocation.java

License:Apache License

private static Method getMethod(ProceedingJoinPoint pjp) {
    MethodSignature signature = (MethodSignature) pjp.getSignature();
    return signature.getMethod();

}

From source file:org.a3badran.platform.logging.aspect.LogRequestAspect.java

License:MIT License

@Around(value = "@annotation(LogRequest)", argNames = "joinPoint,LogRequest")
public Object log(ProceedingJoinPoint joinPoint, LogRequest logRequest) throws Throwable {
    String name = logRequest.value();

    // use method name if @LogRequest(name) is null
    if (name == null || name.isEmpty()) {
        name = joinPoint.getSignature().getName();
        if (joinPoint.getTarget() != null && joinPoint.getTarget().getClass() != null) {
            name = joinPoint.getTarget().getClass().getSimpleName() + "." + name;
        }/* www . j  av  a  2s  . c  o m*/
    }

    // start the scope
    RequestScope scope = RequestLogger.startScope(name);
    try {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        String methodName = signature.getMethod().getName();
        Class<?>[] parameterTypes = signature.getMethod().getParameterTypes();
        Annotation[][] annotations;
        annotations = joinPoint.getTarget().getClass().getMethod(methodName, parameterTypes)
                .getParameterAnnotations();

        int i = 0;
        for (Object arg : joinPoint.getArgs()) {
            for (Annotation annotation : annotations[i]) {
                if (annotation.annotationType() == LogParam.class) {
                    String string = arg == null ? "null" : arg.toString();
                    RequestLogger.addInfo(((LogParam) annotation).value(), string);
                }
            }
            i++;
        }

        // run the method
        // NOTE: exceptions thrown before the actual method is called will result in failure.
        // TODO: configure the ability to bypass exception prior to method calling.
        return joinPoint.proceed();
    } catch (Throwable t) {
        if (RequestLogger.getRequestErrorHandler() != null) {
            RequestLogger.getRequestErrorHandler().handleError(t);
        } else {
            RequestLogger.addError(t.toString());
        }
        throw t;
    } finally {
        // close the scope no matter what
        RequestLogger.endScope(scope);
    }
}

From source file:org.alfresco.traitextender.AJExtender.java

License:Open Source License

/**
 * Around advice helper that matches the advised method with its
 * corresponding extension method, sets up aspectJ call contexts (egg. the
 * local-proceed context) and delegates to the extension method.
 * /*w w  w. j  a v a2s. c o  m*/
 * @param thisJoinPoint
 * @param extensible
 * @param extendAnnotation
 * @param extension
 * @return the result of the extended method
 */
static Object extendAroundAdvice(JoinPoint thisJoinPoint, Extensible extensible, Extend extendAnnotation,
        Object extension) {

    MethodSignature ms = (MethodSignature) thisJoinPoint.getSignature();
    Method method = ms.getMethod();
    try {
        ajLocalProceedingJoinPoints.get()
                .push(new ProceedingContext(extendAnnotation, (ProceedingJoinPoint) thisJoinPoint));

        Method extensionMethod = extension.getClass().getMethod(method.getName(), method.getParameterTypes());
        if (logger.isDebugEnabled()) {
            oneTimeLiveLog(AJExtender.logger, new ExtensionRoute(extendAnnotation, method, extensionMethod));
        }

        return extensionMethod.invoke(extension, thisJoinPoint.getArgs());
    } catch (IllegalAccessException error) {
        throw new InvalidExtension("Ivalid extension : " + error.getMessage(), error);
    } catch (IllegalArgumentException error) {
        throw new InvalidExtension("Ivalid extension : " + error.getMessage(), error);
    } catch (InvocationTargetException error) {
        Throwable targetException = error.getTargetException();
        if (targetException instanceof RuntimeException) {
            throw (RuntimeException) targetException;
        } else {
            throw new ExtensionTargetException(targetException);
        }
    } catch (NoSuchMethodException error) {
        throw new InvalidExtension("Ivalid extension : " + error.getMessage(), error);
    } catch (SecurityException error) {
        throw new InvalidExtension("Ivalid extension : " + error.getMessage(), error);
    } finally {
        ajLocalProceedingJoinPoints.get().pop();
    }

}