Example usage for org.aspectj.lang ProceedingJoinPoint getArgs

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

Introduction

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

Prototype

Object[] getArgs();

Source Link

Usage

From source file:com.google.code.ssm.aop.InvalidateSingleCacheAdvice.java

License:Open Source License

@Around("invalidateSingle()")
public Object cacheInvalidateSingle(final ProceedingJoinPoint pjp) throws Throwable {
    if (isDisabled()) {
        getLogger().info("Cache disabled");
        return pjp.proceed();
    }/*from  w  w w.  j  a  v a  2  s .com*/

    // This is injected caching. If anything goes wrong in the caching, LOG
    // the crap outta it, but do not let it surface up past the AOP injection itself.
    String cacheKey = null;
    final AnnotationData data;
    final Method methodToCache;
    try {
        methodToCache = getCacheBase().getMethodToCache(pjp);
        final InvalidateSingleCache annotation = methodToCache.getAnnotation(InvalidateSingleCache.class);
        data = AnnotationDataBuilder.buildAnnotationData(annotation, InvalidateSingleCache.class,
                methodToCache);
        if (!data.isReturnKeyIndex()) {
            cacheKey = getCacheBase().getCacheKeyBuilder().getCacheKey(data, pjp.getArgs(),
                    methodToCache.toString());
        }
    } catch (Exception ex) {
        warn(ex, "Caching on method %s and key [%s] aborted due to an error.", pjp.toShortString(), cacheKey);
        return pjp.proceed();
    }

    final Object result = pjp.proceed();

    // This is injected caching. If anything goes wrong in the caching, LOG
    // the crap outta it, but do not let it surface up past the AOP injection itself.
    try {
        if (data.isReturnKeyIndex()) {
            getCacheBase().verifyReturnTypeIsNoVoid(methodToCache, InvalidateSingleCache.class);
            cacheKey = getCacheBase().getCacheKeyBuilder().getCacheKey(result, data.getNamespace());
        }

        getCacheBase().getCache(data).delete(cacheKey);
    } catch (Exception ex) {
        warn(ex, "Caching on method %s and key [%s] aborted due to an error.", pjp.toShortString(), cacheKey);
    }
    return result;
}

From source file:com.google.code.ssm.aop.ReadThroughMultiCacheAdvice.java

License:Open Source License

@Around("getMulti()")
@SuppressWarnings("unchecked")
public Object cacheMulti(final ProceedingJoinPoint pjp) throws Throwable {
    if (isDisabled()) {
        getLogger().info("Cache disabled");
        return pjp.proceed();
    }// w w  w .  j  av a2 s .  co m

    // This is injected caching. If anything goes wrong in the caching, LOG
    // the crap outta it, but do not let it surface up past the AOP injection itself.
    final ReadThroughMultiCache annotation;
    final MultiCacheCoordinator coord;
    final AnnotationData data;
    final SerializationType serializationType;

    Object[] args = pjp.getArgs();
    try {
        // Get the target method being invoked, and make sure it returns the correct info.
        final Method methodToCache = getCacheBase().getMethodToCache(pjp);
        getCacheBase().verifyReturnTypeIsList(methodToCache, ReadThroughMultiCache.class);

        // Get the annotation associated with this method, and make sure the values are valid.
        annotation = methodToCache.getAnnotation(ReadThroughMultiCache.class);
        serializationType = getCacheBase().getSerializationType(methodToCache);

        data = AnnotationDataBuilder.buildAnnotationData(annotation, ReadThroughMultiCache.class,
                methodToCache);
        coord = new MultiCacheCoordinator(methodToCache, data);
        setMultiCacheOptions(coord, annotation.option());

        // Create key->object and object->key mappings.
        coord.setHolder(createObjectIdCacheKeyMapping(data, args, coord.getMethod()));

        List<Object> listKeyObjects = (List<Object>) Utils.getMethodArg(data.getListIndexInMethodArgs(), args,
                coord.getMethod().toString());
        coord.setListKeyObjects(listKeyObjects);

        // Get the full list of cache keys and ask the cache for the corresponding values.
        coord.setInitialKey2Result(
                getCacheBase().getCache(data).getBulk(coord.getKey2Obj().keySet(), serializationType));

        // We've gotten all positive cache results back, so build up a results list and return it.
        if (coord.getMissedObjects().isEmpty()) {
            return coord.generateResultList();
        }

        // Create the new list of arguments with a subset of the key objects that aren't in the cache. Do not modify
        // directly argument array from join point!
        args = coord.createModifiedArgumentList(args);
    } catch (Exception ex) {
        warn(ex, "Caching on %s aborted due to an error.", pjp.toShortString());
        return pjp.proceed();
    }

    /*
     * Call the target method with the new subset of arguments. We are calling this outside of the try/catch block
     * in case there are some 'not our fault' problems with the target method. (Connection issues, etc...) Though,
     * this decision could go either way, really.
     */
    final List<Object> results = (List<Object>) pjp.proceed(args);

    try {
        // there are no results
        if (results == null || results.isEmpty()) {
            if (coord.isAddNullsToCache()) {
                addNullValues(coord.getMissedObjects(), coord, serializationType);
            }
            return coord.generatePartialResultList();
        }

        if (coord.isGenerateKeysFromResult()) {
            return generateByKeysFromResult(results, coord, serializationType);
        } else {
            return generateByKeysProviders(results, coord, serializationType);
        }
    } catch (Exception ex) {
        warn(ex, "Caching on %s aborted due to an error. The underlying method will be called twice.",
                pjp.toShortString());
        // invoke underlying method again using unmodified arguments array
        return pjp.proceed(pjp.getArgs());
    }
}

From source file:com.google.code.ssm.aop.SingleReadCacheAdvice.java

License:Open Source License

protected Object cache(final ProceedingJoinPoint pjp) throws Throwable {
    if (isDisabled()) {
        getLogger().info("Cache disabled");
        return pjp.proceed();
    }/* w w  w  .j  a  v a 2s .  c o  m*/
    // This is injected caching. If anything goes wrong in the caching, LOG
    // the crap outta it, but do not let it surface up past the AOP injection itself.
    final T annotation;
    final AnnotationData data;
    final SerializationType serializationType;
    String cacheKey = null;
    try {
        final Method methodToCache = getCacheBase().getMethodToCache(pjp);
        getCacheBase().verifyReturnTypeIsNoVoid(methodToCache, annotationClass);
        annotation = methodToCache.getAnnotation(annotationClass);
        serializationType = getCacheBase().getSerializationType(methodToCache);
        data = AnnotationDataBuilder.buildAnnotationData(annotation, annotationClass, methodToCache);

        cacheKey = getCacheKey(data, pjp.getArgs(), methodToCache.toString());

        final Object result = getCacheBase().getCache(data).get(cacheKey, serializationType);
        if (result != null) {
            getLogger().debug("Cache hit.");
            return getCacheBase().getResult(result);
        }
    } catch (Exception ex) {
        warn(ex, "Caching on method %s and key [%s] aborted due to an error.", pjp.toShortString(), cacheKey);
        return pjp.proceed();
    }

    final Object result = pjp.proceed();

    // This is injected caching. If anything goes wrong in the caching, LOG
    // the crap outta it, but do not let it surface up past the AOP injection itself.
    try {
        final Object submission = getCacheBase().getSubmission(result);
        getCacheBase().getCache(data).set(cacheKey, data.getExpiration(), submission, serializationType);
    } catch (Exception ex) {
        warn(ex, "Caching on method %s and key [%s] aborted due to an error.", pjp.toShortString(), cacheKey);
    }
    return result;
}

From source file:com.googlecode.commonspringaspects.aspects.CachingAspect.java

License:Apache License

private String getCacheKey(ProceedingJoinPoint pjp) {
    String targetName = pjp.getTarget().getClass().getSimpleName();
    String methodName = pjp.getSignature().getName();
    Object[] arguments = pjp.getArgs();
    StringBuilder key = new StringBuilder();
    key.append(targetName).append(".").append(methodName);
    if (arguments != null) {
        for (Object argument : arguments) {
            key.append(".").append(argument);
        }/*from  w  w w .j av  a2 s  .c  o m*/
    }
    return key.toString();
}

From source file:com.googlecode.easiest.cache.ever.CacheAspect.java

License:Apache License

private MethodCall buildMethodCall(ProceedingJoinPoint joinPoint) {
    final MethodSignature methodSignature;

    if (joinPoint.getSignature() instanceof MethodSignature) {
        methodSignature = (MethodSignature) joinPoint.getSignature();
    } else {// ww w  .j a v a 2 s .c  o  m
        throw new RuntimeException(
                "Spring can only join on methods, so casting to MethodSignature should always work.");
    }

    final String concreteClassName = joinPoint.getTarget().getClass().getName();

    return new MethodCall(concreteClassName, methodSignature.getName(), methodSignature.getParameterTypes(),
            joinPoint.getArgs());
}

From source file:com.gxl.kratos.core.shard.SQLExecute.java

License:Apache License

/**
 * ??,?/*from w ww . j a  v a2 s. c om*/
 * 
 * @author gaoxianglong
 * 
 * @param proceedingJoinPoint
 *            ?
 * 
 * @param indexType
 *            truemaster?,falseslave?
 * 
 * @exception Throwable
 * 
 * @return Object
 */
protected Object execute(ProceedingJoinPoint proceedingJoinPoint, boolean indexType) {
    long befor = System.currentTimeMillis();
    Object obj = null;
    if (null != proceedingJoinPoint) {
        Object[] params = proceedingJoinPoint.getArgs();
        if (0 > params.length)
            return obj;
        Object param = params[0];
        /*
         * org.springframework.jdbc.core.JdbcTemplateupdate*()query*()
         * ?SQL
         */
        if (param instanceof String) {
            String sql = param.toString();
            logger.info("sharding?SQL-->" + sql);
            if (kJdbcTemplate.getIsShard()) {
                if (kJdbcTemplate.getShardMode()) {
                    params = route.dbRouteByOne(sql, params, indexType);
                } else {
                    params = route.dbRouteByMany(sql, params, indexType);
                }
                sql = params[0].toString();
                logger.info("sharding?SQL-->" + sql);
            } else {
                /* ?master/slave??? */
                final int INDEX = ResolveRWWeight.getIndex(kJdbcTemplate.getWr_weight(), indexType);
                setDataSource.setIndex(INDEX);
            }
        }
        try {
            obj = proceedingJoinPoint.proceed(params);
            logger.debug("->" + (System.currentTimeMillis() - befor) + "ms");
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    return obj;
}

From source file:com.gxl.kratos.jdbc.core.SwitchDataSource.java

License:Apache License

/**
 * ???//  w ww .  j av a 2 s .  c  o  m
 * 
 * @author gaoxianglong
 * 
 * @param proceedingJoinPoint
 *            ?
 * 
 * @param operation
 *            truemaster?falseslave?
 * 
 * @exception Throwable
 * 
 * @return Object
 */
public Object execute(ProceedingJoinPoint proceedingJoinPoint, boolean operation) {
    long befor = System.currentTimeMillis();
    Object result = null;
    /* ?? */
    Object[] params = proceedingJoinPoint.getArgs();
    Object param = params[0];
    if (param.getClass() == String.class) {
        final String SQL = (String) param;
        logger.info("??sql-->" + SQL);
        /* ??? */
        if (kJdbcTemplate.getIsShard()) {
            /* ? */
            if (kJdbcTemplate.getShardMode()) {
                /* ? */
                logger.debug("??");
                params = oneTbshard(SQL, params, operation).toArray();
            } else {
                /* ? */
                logger.debug("??");
                params = manyTbshard(SQL, params, operation).toArray();
            }
            String NEW_SQL = params[0].toString();
            logger.info("sharding??sql-->" + NEW_SQL);
        } else {
            /* ?/ */
            int index = WeightResolver.getIndex(kJdbcTemplate.getWr_weight(), operation);
            /* ???master */
            setRoutingIndex(index);
        }
        try {
            /*  */
            result = proceedingJoinPoint.proceed(params);
            logger.debug("->" + (System.currentTimeMillis() - befor) + "ms");
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    return result;
}

From source file:com.gxl.shark.core.shard.SQLExecute.java

License:Apache License

/**
 * ??,?//from   w ww.  j  a va 2  s . co m
 * 
 * @author gaoxianglong
 * 
 * @param proceedingJoinPoint
 *            ?
 * 
 * @param indexType
 *            truemaster?,falseslave?
 * 
 * @exception Throwable
 * 
 * @return Object
 */
protected Object execute(ProceedingJoinPoint proceedingJoinPoint, boolean indexType) {
    long befor = System.currentTimeMillis();
    Object obj = null;
    if (null != proceedingJoinPoint) {
        Object[] params = proceedingJoinPoint.getArgs();
        if (0 > params.length)
            return obj;
        Object param = params[0];
        /*
         * org.springframework.jdbc.core.JdbcTemplateupdate*()query*()
         * ?SQL
         */
        if (param instanceof String) {
            String sql = param.toString();
            logger.info("sharding?SQL-->" + sql);
            if (jdbcTemplate.getIsShard()) {
                if (jdbcTemplate.getShardMode()) {
                    params = route.dbRouteByOne(sql, params, indexType);
                } else {
                    params = route.dbRouteByMany(sql, params, indexType);
                }
                sql = params[0].toString();
                logger.info("sharding?SQL-->" + sql);
            } else {
                /* ?master/slave??? */
                final int INDEX = ResolveRWIndex.getIndex(jdbcTemplate.getWr_index(), indexType);
                setDataSource.setIndex(INDEX);
            }
        }
        try {
            obj = proceedingJoinPoint.proceed(params);
            logger.debug("->" + (System.currentTimeMillis() - befor) + "ms");
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    return obj;
}

From source file:com.heliosmi.portal.aspect.LoggingAspect.java

License:Apache License

@Around("allBeans()")
public Object profiler(ProceedingJoinPoint pjp) throws Throwable {

    long start = System.nanoTime();
    String classMethodName = pjp.getTarget().getClass().getSimpleName() + "." + pjp.getSignature().getName();
    log.info(classMethodName + " - called with param(s) " + ToStringBuilder.reflectionToString(pjp.getArgs()));

    Object returnValue = null;/*w w w  . jav  a2s  . c o  m*/
    try {
        returnValue = pjp.proceed();
    } catch (Exception exception) {
        log.error(ToStringBuilder.reflectionToString(ExceptionUtils.getRootCause(exception)));
        log.error(ExceptionUtils.getStackTrace(exception));
        throw exception;
    }

    long end = System.nanoTime();
    log.info(classMethodName + " - finished. Took " + (end - start) + " milliseconds. ");

    return returnValue;
}

From source file:com.ideabase.repository.core.aspect.DataAccessEventAdvice.java

License:Open Source License

/**
 * Find Signature class. now publish event based on the specific class and
 * method signature./* w  w w  .j  a va 2 s. c o m*/
 */
@Around("com.ideabase.repository.core.aspect.ArchitecturePointcuts.dataAccessOperation()")
public Object aroundOperation(final ProceedingJoinPoint pProceedingJoinPoint) throws Throwable {
    // Determine source class and mehtod.
    final Signature signature = pProceedingJoinPoint.getSignature();
    final Class signatureClass = signature.getDeclaringType();
    final String signatureMethod = signature.getName();
    final Object[] arguments = pProceedingJoinPoint.getArgs();

    // Execute the operation
    final Object returned = pProceedingJoinPoint.proceed();

    // publish event
    addEvent(returned, signatureClass, signatureMethod, arguments);

    // Return the executed output.
    return returned;
}