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.sun.jersey.spring25.LoggingAdvice.java

License:Open Source License

@Around("execution(* com.sun.jersey.spring25.ProxiedResource.getBaseUri(..))")
public Object log(ProceedingJoinPoint pjp) throws Throwable {
    final Signature signature = pjp.getSignature();
    LOGGER.info("Starting to execute " + signature.getDeclaringTypeName() + "." + signature.getName());
    Object retVal = pjp.proceed();
    LOGGER.info("Finished to execute " + signature.getDeclaringTypeName() + "." + signature.getName());
    return retVal;
}

From source file:com.sun.jersey.spring25.LoggingAdvice.java

License:Open Source License

@Around("execution(* com.sun.jersey.spring25.ProxiedSubResource.getRequestUri(..))")
public Object logSubResource(ProceedingJoinPoint pjp) throws Throwable {
    final Signature signature = pjp.getSignature();
    LOGGER.info("Starting to execute " + signature.getDeclaringTypeName() + "." + signature.getName());
    Object retVal = pjp.proceed();
    LOGGER.info("Finished to execute " + signature.getDeclaringTypeName() + "." + signature.getName());
    return retVal;
}

From source file:com.swcguild.aspects.SimpleTimerAdvice.java

public Object timeMethod(ProceedingJoinPoint jp) {
    Object ret = null;// w w w  . j a va 2 s  .co m

    try {
        long start = System.currentTimeMillis();
        ret = jp.proceed();
        long end = System.currentTimeMillis();
        System.out.println("*************");
        System.out.println(jp.getSignature().getName() + " took " + (end - start) + "ms");
        System.out.println("*************");

    } catch (Throwable ex) {
        System.out.println("Exception occurred in SimpleTimerAdvice.timeMethod()");
    }

    return ret;

}

From source file:com.swcguild.flooringapp.Timer.java

public Object timeMethod(ProceedingJoinPoint jp) {
    Object obj = null;/*w w w. j a  v a  2  s.com*/

    try {
        long begin = System.currentTimeMillis();
        obj = jp.proceed();
        long end = System.currentTimeMillis();

        System.out.printf("%n" + jp.getSignature().getName() + " ran for " + (end - begin) + "ms.%n");
    } catch (Throwable ex) {
        System.out.println("Error: Timer failed in " + Timer.class.getName());
    }

    return obj;
}

From source file:com.swcguild.flooringmasteryspring.aspect.TimingAspect.java

public Object checkTimeElapsed(ProceedingJoinPoint jp) {
    Object ret = null;/*from  w w  w  .j av  a  2s  . co  m*/
    try {
        long start = System.currentTimeMillis();
        ret = jp.proceed();
        long end = System.currentTimeMillis();
        System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        System.out.println(jp.getSignature().getName() + " took " + (end - start) + " ms");
        System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
    } catch (Throwable t) {
        System.out.println("Exception in TimingAspect.checkTimeElapsed()");
    }
    return ret;
}

From source file:com.swcguild.olympian.SimpleTimerAspect.java

public Object timeMethod(ProceedingJoinPoint jp) {
    Object ret = null;//ww  w  .  j  a v  a 2  s  . c o  m

    try {
        long start = System.currentTimeMillis();

        ret = jp.proceed();

        long end = System.currentTimeMillis();
        System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        System.out.println(jp.getSignature().getName() + " took " + (end - start) + " ms");
        System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
    } catch (Throwable t) {
        System.out.println("Exception in SimpleTimerAspect.timeMethod()");
    }

    return ret;
}

From source file:com.swguild.olympians.OlympicOfficial.java

public Object timeMethod(ProceedingJoinPoint jp) throws Throwable {
    Object ret = null;// w w  w  .  j a  v a  2 s . c o  m

    try {
        // Note 2 - start timer
        long start = System.currentTimeMillis();
        // Note 3 - this allows the target method to execute
        ret = jp.proceed();
        // Note 4 - target method has returned, end timer and calc
        // elapsed time
        long end = System.currentTimeMillis();
        System.out.println("++++++++++++++++++++++++++++++++++++++++++");
        System.out.println(jp.getSignature().getName() + " took " + (end - start) + " ms");
        System.out.println("++++++++++++++++++++++++++++++++++++++++++");
    } catch (Throwable ex) {
        System.out.println("Exception in SimpleTimerAspect.timeMethod()");
    }
    // Note 5 - return whatever was returned by the target method (see
    // Note 3)
    return ret;
}

From source file:com.tacitknowledge.flip.aspectj.FlipAbstractAspect.java

License:Apache License

/**
 * Intercept calls to the methods marked with {@link Flippable} annotation.
 * Firstly it processes the method parameters marked with {@link FlipParam} 
 * annotation. Each parameter value is replaced with the value declared in
 * {@link FlipParam#disabledValue()} if the feature declared in {@link FlipParam#feature() }
 * is disabled.//from   ww  w.j  a v  a 2 s.com
 * After properties evaluation this method checks if the feature marked in
 * {@link Flippable#feature() } is disabled then the value from {@link Flippable#disabledValue() }
 * is returned.
 * 
 * @param flip the {@link Flippable} annotation instance which marks the method to intercept.
 * @param pjp the object obtained from AspectJ method interceptor.
 * @return the processed value of the method depending from feature state.
 * @throws Throwable 
 */
@Around(value = "anyMethod() && @annotation(flip)", argNames = "flip")
public Object aroundFlippableMethods(ProceedingJoinPoint pjp, Flippable flip) throws Throwable {
    MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
    Method method = methodSignature.getMethod();

    if (isFeatureEnabled(flip.feature())) {
        Annotation[][] paramAnnotations = method.getParameterAnnotations();
        Object[] params = pjp.getArgs();
        Class[] paramTypes = method.getParameterTypes();

        for (int i = 0; i < paramAnnotations.length; i++) {
            FlipParam flipParam = findFlipParamAnnoattion(paramAnnotations[i]);
            if (!isFeatureEnabled(flipParam.feature())) {
                params[i] = getProcessedDisabledValue(paramTypes[i], flipParam.disabledValue(), pjp.getThis());
            }
        }

        return pjp.proceed(params);
    } else {
        return getProcessedDisabledValue(method.getReturnType(), flip.disabledValue(), pjp.getThis());
    }
}

From source file:com.tacitknowledge.flip.aspectj.FlipAbstractAspect.java

License:Apache License

public Object aroundFlippableMethods(ProceedingJoinPoint pjp) throws Throwable {
    final Flippable flip = ((MethodSignature) pjp.getSignature()).getMethod().getAnnotation(Flippable.class);
    return aroundFlippableMethods(pjp, flip);
}

From source file:com.tasktop.c2c.server.common.service.ServiceLoggingAdvice.java

License:Open Source License

private void logCall(ProceedingJoinPoint pjp, Throwable t, Object result, StringBuilder msg)
        throws NoSuchMethodException {
    Method method = ((MethodSignature) pjp.getSignature()).getMethod();

    msg.append(pjp.getSignature().getDeclaringType().getSimpleName()).append(".")
            .append(pjp.getSignature().getName()).append("(");

    if (method.getAnnotation(NoLog.class) != null) {
        msg.append("***)");
        return;//  w  w w.  j  a va  2s . c om
    }

    boolean needSep = false;
    int i = 0;
    for (Object arg : pjp.getArgs()) {
        if (needSep) {
            msg.append(", ");
        } else {
            needSep = true;
        }

        if (!shouldLog(i++, method)) {
            msg.append("***");
        } else {
            msg.append(String.valueOf(arg));
        }
    }
    msg.append(") -> ");
    if (t != null) {
        msg.append("threw ").append(t.toString());
    } else {
        msg.append(result);
    }
}