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.ace.erp.extra.aop.UserCacheAspect.java

@Around(value = "userServicePointcut() && cacheablePointcut()")
public Object cacheableAdvice(ProceedingJoinPoint pjp) throws Throwable {

    String methodName = pjp.getSignature().getName();
    Object arg = pjp.getArgs().length >= 1 ? pjp.getArgs()[0] : null;

    String key = "";
    boolean isIdKey = false;
    if ("getUserById".equals(methodName)) {
        key = idKey(String.valueOf(arg));
        isIdKey = true;/*from w  ww .  j  a  v  a 2 s  . com*/
    } else if ("getUserByName".equals(methodName)) {
        key = usernameKey((String) arg);
    } else if ("getUserByEmail".equals(methodName)) {
        key = emailKey((String) arg);
    } else if ("getUserByMobilePhoneNumber".equals(methodName)) {
        key = mobilePhoneNumberKey((String) arg);
    }

    User user = null;
    if (isIdKey == true) {
        user = get(key);
    } else {
        Integer id = get(key);
        if (id != null) {
            key = idKey(String.valueOf(id));
            user = get(key);
        }
    }
    //cache hit
    if (user != null) {
        log.debug("cacheName:{}, hit key:{}", cacheName, key);
        return user;
    }
    log.debug("cacheName:{}, miss key:{}", cacheName, key);

    //cache miss
    user = (User) pjp.proceed();

    //put cache
    put(user);
    return user;

}

From source file:com.aeells.hibernate.profiling.HibernateProfilingInterceptor.java

License:Open Source License

private void logProfileCall(final ProceedingJoinPoint call, final Object model, final long duration) {
    // model is null on login
    if (model != null && model.getClass().isAnnotationPresent(HibernateProfiled.class)) {
        try {// ww  w  .j  a v a  2s .  com
            LOGGER.trace(new StringBuilder(
                    StringUtils.substringBefore(call.getSignature().getDeclaringType().getSimpleName(), "$"))
                            .append("|").append(call.getSignature().getName()).append("|")
                            .append(getClassNameAndPersistentId(model)).append("|").append(duration));
        } catch (final Exception e) {
            LOGGER.error("unable to profile class: " + model.getClass());
        }
    }
}

From source file:com.aeells.hibernate.profiling.HibernateProfilingInterceptor.java

License:Open Source License

private void logProfileCall(final ProceedingJoinPoint call, final List<Object> models, final long duration) {
    if (models != null && !models.isEmpty()) {
        LOGGER.trace(new StringBuilder(
                StringUtils.substringBefore(call.getSignature().getDeclaringType().getSimpleName(), "$"))
                        .append("|").append(call.getSignature().getName()).append("|")
                        .append(getClassNameAndPersistentIds(models)).append(duration));
    }// w  ww .  j a v  a 2s .  co m
}

From source file:com.aliyun.odps.OdpsDeprecatedLogger.java

License:Apache License

@Around("@annotation(Deprecated)")
public Object around(ProceedingJoinPoint point) throws Throwable {
    try {/*  w w w. j  a  v  a 2s  . co  m*/
        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.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   w w w .j ava  2s .  com*/

    // 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.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   w w w.ja  v a2s  .c  o m

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

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 {/*  w ww. j av a  2s  . co 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 {//from w w  w.  j a  v  a2 s. c  o  m
        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.astonish.metrics.aspectj.MetricAdvice.java

License:Apache License

/**
 * Retrieves the {@link Method} from the {@link ProceedingJoinPoint}.
 * @param pjp/*from   w  w  w  .j  a va  2  s  .  c o  m*/
 *            the {@link ProceedingJoinPoint}
 * @return the {@link Method}
 */
private Method retrieveMethod(ProceedingJoinPoint pjp) {
    final MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
    Method method = methodSignature.getMethod();

    if (method.getDeclaringClass().isInterface()) {
        try {
            method = pjp.getTarget().getClass().getDeclaredMethod(pjp.getSignature().getName(),
                    method.getParameterTypes());
        } catch (final SecurityException e) {
            LOGGER.warn("Could not retrieve method[{}] for metric interrogation.", method.getName(), e);
        } catch (final NoSuchMethodException e) {
            LOGGER.warn("Could not retrieve method[{}] for metric interrogation.", method.getName(), e);
        }
    }

    return method;
}

From source file:com.att.ajsc.common.trace.TrailLoggerAspect.java

License:BSD License

@Around("pointcut()")
public Object logTrail(ProceedingJoinPoint joinPoint) throws Throwable {

    long startTimeInMilliseconds = System.currentTimeMillis();
    TransactionTrail transactionTrail;//w w w. jav a  2 s  .c  o  m
    long endTimeInMilliseconds;
    long durationInMilliseconds;
    String message = null;
    String finalMessage = "";
    String executionDepth = "-";
    String identifier = "";
    String placeholder = "";
    try {
        transactionTrail = (TransactionTrail) context.getBean(TRANSACTION_TRAIL);
    } catch (Exception e1) {
        logger.error(InterceptorMessages.INTERCEPTOR_TRAIL_LOGGER_MESSAGE, e1,
                ((MethodSignature) joinPoint.getSignature()).getMethod().getName());
        return joinPoint.proceed();
    }

    try {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();
        identifier = method.getDeclaringClass().toString() + method.getName();
        transactionTrail.addInCompleteMethod(identifier);
        long line = transactionTrail.getTrail().split("\n").length + 1;
        placeholder = LINE + line + ":";
        transactionTrail.setTrail(transactionTrail.getTrail() + "\n" + placeholder);
        Tracable tracable = method.getAnnotation(Tracable.class);
        message = tracable.message();
        if (message.length() == 0) {
            message = signature.toString();
        }

        Object result = joinPoint.proceed();
        endTimeInMilliseconds = System.currentTimeMillis();
        int inCompleteMethods = incompleteMethods(transactionTrail.getInCompleteMethods());
        if (inCompleteMethods > 0) {
            for (int i = 0; i < inCompleteMethods; i++) {
                executionDepth = executionDepth + "-";
            }

        }
        durationInMilliseconds = endTimeInMilliseconds - startTimeInMilliseconds;
        finalMessage = executionDepth + durationInMilliseconds + MILLIS + message;
        transactionTrail.setTrail(transactionTrail.getTrail().replace(placeholder, finalMessage));
        transactionTrail.getInCompleteMethods().remove(identifier);
        return result;
    } catch (Throwable e) {
        logger.error(InterceptorMessages.INTERCEPTOR_TRAIL_LOGGER_MESSAGE, e,
                joinPoint.getSignature().toString());
        endTimeInMilliseconds = System.currentTimeMillis();
        int inCompleteMethods = incompleteMethods(transactionTrail.getInCompleteMethods());
        if (inCompleteMethods > 0) {
            for (int i = 0; i < inCompleteMethods; i++) {
                executionDepth = executionDepth + "-";
            }

        }
        durationInMilliseconds = endTimeInMilliseconds - startTimeInMilliseconds;
        finalMessage = executionDepth + durationInMilliseconds + MILLIS + message;
        transactionTrail.setTrail(transactionTrail.getTrail().replace(placeholder, finalMessage));
        transactionTrail.getInCompleteMethods().remove(identifier);
        throw e;
    }

}