Example usage for org.aspectj.lang ProceedingJoinPoint getTarget

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

Introduction

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

Prototype

Object getTarget();

Source Link

Document

Returns the target object.

Usage

From source file:org.raspinloop.fmi.RILLogingAspect.java

License:Apache License

@Around("org.raspinloop.fmi.RILLogingAspect.rilTraceCall()")
public Object myTrace(ProceedingJoinPoint joinPoint) throws Throwable {

    StringBuilder sb = new StringBuilder("ril:--> " + joinPoint.getTarget().getClass().getName() + "."
            + joinPoint.getSignature().getName() + ": ");
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Method method = signature.getMethod();
    Annotation[][] annotations = method.getParameterAnnotations();
    for (int i = 0; i < annotations.length; ++i) {
        sb.append(joinPoint.getArgs()[i]);
        if (i != annotations.length - 1)
            sb.append(", ");
    }/* w  ww . jav  a2 s .co m*/
    logger.trace(sb.toString());

    Object retVal = null;
    try {
        retVal = joinPoint.proceed();
    } finally {

        logger.trace("ril:<-- " + joinPoint.getTarget().getClass().getName() + "."
                + joinPoint.getSignature().getName() + " retval=" + retVal);
    }
    return retVal;
}

From source file:org.slc.sli.dal.aspect.MongoTrackingAspect.java

License:Apache License

@Around("call(* org.springframework.data.mongodb.core.MongoTemplate.*(..)) && !this(MongoTrackingAspect) && !within(org..*Test) && !within(org..*MongoPerfRepository)")
public Object track(ProceedingJoinPoint pjp) throws Throwable {

    long start = System.currentTimeMillis();
    Object result = pjp.proceed();
    long end = System.currentTimeMillis();

    if (isEnabled()) {
        MongoTemplate mt = (MongoTemplate) pjp.getTarget();
        String collection = determineCollectionName(pjp);
        proceedAndTrack(pjp, mt.getDb().getName(), pjp.getSignature().getName(), collection, start, end);
    }//from w w w .  ja  va2s.  c  om
    if (Boolean.valueOf(dbCallTracking)) {
        dbCallTracker.incrementHitCount();
        // dbCallTracker.addMetric("t", pjp.getSignature().toShortString(), end-start);
    }

    return result;
}

From source file:org.slc.sli.dal.aspect.MongoTrackingAspect.java

License:Apache License

@Around("call(* com.mongodb.DBCollection.*(..)) && !this(MongoTrackingAspect) && !within(org..*Test) && !within(org..*MongoPerfRepository)")
public Object trackDBCollection(ProceedingJoinPoint pjp) throws Throwable {

    long start = System.currentTimeMillis();
    Object result = pjp.proceed();
    long end = System.currentTimeMillis();

    if (isEnabled()) {
        DBCollection col = (DBCollection) pjp.getTarget();
        proceedAndTrack(pjp, col.getDB().getName(), pjp.getSignature().getName(), col.getName(), start, end);
    }//from   w w w.  ja  va2 s .com
    if (Boolean.valueOf(dbCallTracking)) {
        dbCallTracker.incrementHitCount();
        // dbCallTracker.addMetric("t", pjp.getSignature().toShortString(), end-start);
    }
    return result;
}

From source file:org.smallmind.web.jersey.aop.ResourceMethodAspect.java

License:Open Source License

@Around(value = "execution(@org.smallmind.web.jersey.aop.ResourceMethod * * (..)) && @annotation(resourceMethod)", argNames = "thisJoinPoint, entityType")
public Object aroundEntityTypeMethod(ProceedingJoinPoint thisJoinPoint, ResourceMethod resourceMethod)
        throws Throwable {

    try {//from  ww  w .  jav a  2  s .  c om

        Object returnValue;

        if (resourceMethod.validate()) {
            EntityValidator.validateParameters(thisJoinPoint.getTarget(),
                    ((MethodSignature) thisJoinPoint.getSignature()).getMethod(), thisJoinPoint.getArgs());
        }

        returnValue = thisJoinPoint.proceed();

        if (resourceMethod.validate()) {
            EntityValidator.validateReturnValue(thisJoinPoint.getTarget(),
                    ((MethodSignature) thisJoinPoint.getSignature()).getMethod(), returnValue);
        }

        return returnValue;
    } finally {
        EntityTranslator.clearEntity();
    }
}

From source file:org.springframework.cloud.sleuth.instrument.async.TraceAsyncAspect.java

License:Apache License

@Around("execution (@org.springframework.scheduling.annotation.Async  * *.*(..))")
public Object traceBackgroundThread(final ProceedingJoinPoint pjp) throws Throwable {
    Span span = this.tracer.createSpan(SpanNameUtil.toLowerHyphen(pjp.getSignature().getName()));
    this.tracer.addTag(Span.SPAN_LOCAL_COMPONENT_TAG_NAME, ASYNC_COMPONENT);
    this.tracer.addTag(this.traceKeys.getAsync().getPrefix() + this.traceKeys.getAsync().getClassNameKey(),
            pjp.getTarget().getClass().getSimpleName());
    this.tracer.addTag(this.traceKeys.getAsync().getPrefix() + this.traceKeys.getAsync().getMethodNameKey(),
            pjp.getSignature().getName());
    try {//from  ww  w  .j a v  a 2 s. c o m
        return pjp.proceed();
    } finally {
        this.tracer.close(span);
    }
}

From source file:org.springframework.cloud.sleuth.instrument.async.TraceAsyncAspect.java

License:Apache License

@Around("execution (* org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.*(..))")
public Object traceThreadPoolTaskExecutor(final ProceedingJoinPoint pjp) throws Throwable {
    LazyTraceThreadPoolTaskExecutor executor = new LazyTraceThreadPoolTaskExecutor(this.beanFactory,
            (ThreadPoolTaskExecutor) pjp.getTarget());
    Method methodOnTracedBean = getMethod(pjp, executor);
    if (methodOnTracedBean != null) {
        return methodOnTracedBean.invoke(executor, pjp.getArgs());
    }/* ww  w  .  ja v a2 s.  co m*/
    return pjp.proceed();
}

From source file:org.springframework.cloud.sleuth.instrument.scheduling.TraceSchedulingAspect.java

License:Apache License

@Around("execution (@org.springframework.scheduling.annotation.Scheduled  * *.*(..))")
public Object traceBackgroundThread(final ProceedingJoinPoint pjp) throws Throwable {
    if (this.skipPattern.matcher(pjp.getTarget().getClass().getName()).matches()) {
        return pjp.proceed();
    }//from ww  w  . jav a2 s  . co  m
    String spanName = SpanNameUtil.toLowerHyphen(pjp.getSignature().getName());
    Span span = this.tracer.createSpan(spanName);
    this.tracer.addTag(Span.SPAN_LOCAL_COMPONENT_TAG_NAME, SCHEDULED_COMPONENT);
    this.tracer.addTag(this.traceKeys.getAsync().getPrefix() + this.traceKeys.getAsync().getClassNameKey(),
            pjp.getTarget().getClass().getSimpleName());
    this.tracer.addTag(this.traceKeys.getAsync().getPrefix() + this.traceKeys.getAsync().getMethodNameKey(),
            pjp.getSignature().getName());
    try {
        return pjp.proceed();
    } finally {
        this.tracer.close(span);
    }
}

From source file:org.springframework.cloud.sleuth.instrument.web.client.feign.TraceFeignAspect.java

License:Apache License

@Around("execution (* feign.Client.*(..)) && !within(is(FinalType))")
public Object feignClientWasCalled(final ProceedingJoinPoint pjp) throws Throwable {
    Object[] args = pjp.getArgs();
    Request request = (Request) args[0];
    Request.Options options = (Request.Options) args[1];
    Object bean = pjp.getTarget();
    if (!(bean instanceof TraceFeignClient)) {
        return new TraceFeignClient(this.beanFactory, (Client) bean).execute(request, options);
    }//from w ww .ja v  a2  s  . co m
    return pjp.proceed();
}

From source file:org.springframework.data.gemfire.serialization.json.JSONRegionAdvice.java

License:Apache License

@Around("execution(* org.apache.geode.cache.Region.get(..))"
        + " || execution(* org.apache.geode.cache.Region.remove(..))"
        + " || execution(* org.apache.geode.cache.Region.selectValue(..))")
public Object get(ProceedingJoinPoint pjp) {

    Object returnValue = null;/*from www  . jav a 2 s  . com*/

    try {
        if (isIncludedJsonRegion(pjp.getTarget())) {
            returnValue = pjp.proceed();
            logger.debug("converting {} to JSON string", returnValue);
            returnValue = convertToJson(returnValue);
        } else {
            returnValue = pjp.proceed();
        }
    } catch (Throwable cause) {
        handleThrowable(cause);
    }

    return returnValue;
}

From source file:org.springframework.data.gemfire.serialization.json.JSONRegionAdvice.java

License:Apache License

@SuppressWarnings("unchecked")
@Around("execution(* org.apache.geode.cache.Region.getAll(..))")
public Map<Object, Object> getAll(ProceedingJoinPoint pjp) {

    Map<Object, Object> result = null;

    try {/*from w  w w .  jav  a  2 s . c  o  m*/

        Map<Object, Object> returnValue = (Map<Object, Object>) pjp.proceed();

        if (!this.convertReturnedCollections || CollectionUtils.isEmpty(returnValue)
                || !isIncludedJsonRegion(pjp.getTarget())) {

            result = returnValue;
        } else {
            result = returnValue.entrySet().stream()
                    .collect(Collectors.toMap(Map.Entry::getKey, entry -> convertToJson(entry.getValue())));
        }
    } catch (Throwable t) {
        handleThrowable(t);
    }

    return result;
}