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.autentia.wuija.aop.AopTracer.java

License:Open Source License

public Object traceMethod(ProceedingJoinPoint pjp) throws Throwable {
    if (!log.isTraceEnabled()) {
        log.warn("You are using " + AopTracer.class.getName()
                + ", but you are not using TRACE level in your log. So you will not see the trace messages.");
    }//from  w w  w . j  ava 2 s. c  o m
    log.trace("Entering: " + pjp.getSignature().toLongString());
    final long millis = System.currentTimeMillis();

    final Object retVal = pjp.proceed();

    final long methodTime = System.currentTimeMillis() - millis;
    log.trace("Exiting (" + methodTime + " millis): " + pjp.getSignature().toLongString());

    return retVal;
}

From source file:com.baomidou.framework.aop.LogAspect.java

License:Apache License

/**
 * ??//  w w  w .  ja va 2 s . c  o  m
 *
 * @param joinPoint
 *            
 * @return 
 * @throws Throwable
 *             
 */
@Around(value = "@annotation(com.baomidou.framework.annotations.Log)")
public Object saveLog(ProceedingJoinPoint joinPoint) throws Throwable {
    /**
     * ?Log
     */
    String methodName = joinPoint.getSignature().getName();
    Method method = currentMethod(joinPoint, methodName);
    Log log = method.getAnnotation(Log.class);

    /**
     * 
     */
    if (log != null) {
        logPoint.saveLog(joinPoint, methodName, log.value());
    }

    /**
     * 
     */
    return joinPoint.proceed();
}

From source file:com.betfair.cougar.core.impl.kpi.KPIAsyncTimer.java

License:Apache License

@Around("cougarAsyncMethod(event, observer)")
public Object measureAsyncMethod(final ProceedingJoinPoint pjp, KPIAsyncTimedEvent event,
        ExecutionObserver observer) throws Throwable {
    final String eventValue = event.value();
    final String eventOperation = event.operation();
    final String name = eventValue.isEmpty() ? pjp.getTarget().getClass().getSimpleName() : eventValue;
    final String operation = eventOperation.isEmpty() ? pjp.getSignature().getName() : eventOperation;

    final KPITimer timer = new KPITimer();
    timer.start();/*from w w  w  .  j  a va2s .  co  m*/
    final PerformanceMonitoringExecutionObserver perfObserver = new PerformanceMonitoringExecutionObserver(
            observer, monitor, timer, event.catchFailures(), name, operation);

    return pjp.proceed(replaceObserver(perfObserver, pjp.getArgs()));
}

From source file:com.betfair.tornjak.kpi.aop.KPIMeasuringAspect.java

License:Apache License

@Around("@annotation(kpiTimedEvent)")
public Object measureDuration(final ProceedingJoinPoint pjp, KPITimedEvent kpiTimedEvent) throws Throwable {

    KPITimer timer = new KPITimer();
    boolean succeeded = true;
    try {//from  w  ww.j a v a  2 s  . c o  m
        timer.start();
        return pjp.proceed();

    } catch (Throwable t) {
        succeeded = false;
        throw t;

    } finally {
        // this looks like a reasonable and clean place to stop the clock, even if we've wasted a few nanos before
        //  we actually get here
        double duration = timer.stop();
        final String eventValue = kpiTimedEvent.value();
        final String name = eventValue.isEmpty() ? pjp.getTarget().getClass().getSimpleName() : eventValue;
        final String operation = kpiTimedEvent.operation().isEmpty() ? pjp.getSignature().getName()
                : kpiTimedEvent.operation();

        if (kpiTimedEvent.catchFailures()) {
            kpiMonitor.addEvent(name, operation, duration, succeeded);
        } else {
            kpiMonitor.addEvent(name, operation, duration);
        }
    }
}

From source file:com.betfair.tornjak.monitor.aop.MonitorAOP.java

License:Apache License

private MonitorMethod getAnnotation(final ProceedingJoinPoint pjp) {
    MethodSignature signature = (MethodSignature) pjp.getSignature();
    MonitorMethod fromSignature = signature.getMethod().getAnnotation(MonitorMethod.class);
    if (fromSignature != null) {
        return fromSignature;
    }// w  ww. j av a 2 s  .com
    // right, couldn't find it on the method signature, but we might be looking at an implementation of an interface
    // so now look at the target object/class
    try {
        Method m = pjp.getTarget().getClass().getDeclaredMethod(signature.getName(),
                signature.getParameterTypes());
        return m.getAnnotation(MonitorMethod.class);
    } catch (NoSuchMethodException e) {
        // hmm, not sure we should ever see this
        throw new IllegalStateException("Couldn't find method that was called on the object it was called on");
    }
}

From source file:com.boyuanitsm.fort.aop.logging.LoggingAspect.java

License:Apache License

@Around("loggingPointcut()")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
    if (log.isDebugEnabled()) {
        log.debug("Enter: {}.{}() with argument[s] = {}", joinPoint.getSignature().getDeclaringTypeName(),
                joinPoint.getSignature().getName(), Arrays.toString(joinPoint.getArgs()));
    }/*from  w w  w  .j  a  v  a  2 s .  c o  m*/
    try {
        Object result = joinPoint.proceed();
        if (log.isDebugEnabled()) {
            log.debug("Exit: {}.{}() with result = {}", joinPoint.getSignature().getDeclaringTypeName(),
                    joinPoint.getSignature().getName(), result);
        }
        return result;
    } catch (IllegalArgumentException e) {
        log.error("Illegal argument: {} in {}.{}()", Arrays.toString(joinPoint.getArgs()),
                joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName());

        throw e;
    }
}

From source file:com.brienwheeler.lib.monitor.work.impl.MonitoredWorkAspect.java

License:Open Source License

@SuppressWarnings({ "unchecked", "rawtypes" })
@Around("monitoredWorkPointcut()")
public Object aroundMonitoredWork(final ProceedingJoinPoint joinPoint) throws InterruptedException {
    ValidationUtils.assertTrue(joinPoint.getTarget() instanceof IWorkMonitorProvider,
            "@MonitoredWork target must be subclass of IWorkMonitorProvider");
    ValidationUtils.assertTrue(joinPoint.getSignature() instanceof MethodSignature,
            "@MonitoredWork signature must be a method");

    final WorkMonitor workMonitor = ((IWorkMonitorProvider) joinPoint.getTarget()).getWorkMonitor();
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    MonitoredWork annotation = signature.getMethod().getAnnotation(MonitoredWork.class);

    final String workName = annotation != null && !annotation.value().isEmpty() ? annotation.value()
            : signature.getName();//from  ww  w  .j av a  2s.c o m

    long start = System.currentTimeMillis();
    try {
        Object ret = joinPoint.proceed();
        workMonitor.recordWorkOk(workName, System.currentTimeMillis() - start);
        return ret;
    } catch (InterruptedException e) {
        workMonitor.recordWorkError(workName, System.currentTimeMillis() - start);
        Thread.currentThread().interrupt();
        throw e;
    } catch (RuntimeException e) {
        workMonitor.recordWorkError(workName, System.currentTimeMillis() - start);
        throw e;
    } catch (Error e) {
        workMonitor.recordWorkError(workName, System.currentTimeMillis() - start);
        throw e;
    } catch (Throwable e) {
        workMonitor.recordWorkError(workName, System.currentTimeMillis() - start);
        throw new RuntimeException(e);
    }
}

From source file:com.chnoumis.commons.log.LogAspect.java

License:Apache License

@Around("execution(* com.chnoumis..*.*(..))")
public Object doTrace(ProceedingJoinPoint pjp) throws Throwable {
    Log log = LogFactory.getLog(pjp.getSignature().getDeclaringType());
    Object retVal = null;/*from ww  w .  j  av  a 2s.c  o  m*/
    //if (log.isDebugEnabled()) {
    log.info("Starting method " + pjp.getSignature().toLongString());
    retVal = pjp.proceed();
    log.info("Ending method " + pjp.getSignature().toLongString());
    // log.info("Method returned " + retVal);
    //}
    return retVal;
}

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

License:Apache License

private Method getHandlerMethod(final ProceedingJoinPoint proceedingJoinPoint,
        final Class<? extends Throwable> thrownExceptionClass, final String[] handlerMethodNames) {
    final Class<?> targetClass = proceedingJoinPoint.getThis().getClass();
    final MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature();
    final Class<?>[] handlerParameterTypes = getExceptionHandlerParameterTypes(thrownExceptionClass,
            methodSignature.getParameterTypes());
    for (final String handlerMethodName : handlerMethodNames) {
        try {//from  www.j  a va2  s. c  o  m
            return targetClass.getMethod(handlerMethodName, handlerParameterTypes);
        } catch (final ReflectiveOperationException e) {
            // Exception handler method signature does not match - Skip this exception handler
        }
    }
    return null;
}

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

License:Apache License

@Test
public void shouldAttemptMethodAndCallExceptionHandler_withExceptionThrownAndExceptionHandlerNamed()
        throws Throwable {
    // Given//  w  ww .j  a  v a  2s. c o  m
    final RetryableAspect retryableAspect = new RetryableAspect();
    final ProceedingJoinPoint mockProceedingJoinPoint = setupSimpleProceedingJoinPointMock();
    final Retryable mockRetryable = setupSimpleRetryableMock();
    final RetryExceptionHandler retryExceptionHandler = new RetryExceptionHandler();
    final MethodSignature mockMethodSignature = mock(MethodSignature.class);
    final String exceptionHandlerName = "joinPointMethodExceptionHandlingMethod";

    RetryableConfiguration.setRetryableEnabled(false);
    when(mockProceedingJoinPoint.proceed()).thenThrow(new RetryAspectTestException());
    when(mockProceedingJoinPoint.getThis()).thenReturn(retryExceptionHandler);
    when(mockProceedingJoinPoint.getSignature()).thenReturn(mockMethodSignature);
    when(mockProceedingJoinPoint.getArgs()).thenReturn(new Object[] { "exampleArgument" });
    when(mockMethodSignature.getParameterTypes()).thenReturn(
            RetryExceptionHandler.class.getDeclaredMethod("joinPointMethod", String.class).getParameterTypes());
    when(mockRetryable.exceptionHandlers()).thenReturn(new String[] { exceptionHandlerName });

    // When
    retryableAspect.attemptMethodAndRetryIfNeeded(mockProceedingJoinPoint, mockRetryable);

    // Then
    verify(mockProceedingJoinPoint).proceed();

    assertTrue(retryExceptionHandler.exceptionHandlerBeenCalled);
}