List of usage examples for org.aspectj.lang ProceedingJoinPoint getArgs
Object[] getArgs();
From source file:org.cgiar.ccafs.marlo.logging.LoggingAspect.java
License:Open Source 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 ww .jav a 2 s . com*/ try { // TODO ensure the result is summarized for collections 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:org.codehaus.grepo.statistics.service.MethodStatisticsAspect.java
License:Apache License
/** * @param pjp The proceeding join point. * @param annotation The {@link MethodStatistics} annotation. * @return Returns the entry.//from w w w . ja v a2 s .co m */ private StatisticsEntry createEntry(ProceedingJoinPoint pjp, MethodStatistics annotation) { StatisticsEntry entry = null; try { MethodSignature methodSig = (MethodSignature) pjp.getSignature(); Method method = methodSig.getMethod(); MethodParameterInfo mpi = new MethodParameterInfoImpl(method, pjp.getArgs()); String identifier = statisticsIdentifierNamingStrategy.getIdentifier(mpi, annotation); entry = getStatisticsManager(annotation.manager()).createStatisticsEntry(identifier, annotation.origin()); } catch (Exception e) { logger.error("Unable to create StatisticsEntry: " + e.getMessage(), e); } return entry; }
From source file:org.craftercms.commons.logging.LoggedAspect.java
License:Open Source License
@Around("@within(org.craftercms.commons.logging.Logged) || @annotation(org.craftercms.commons.logging.Logged)") public Object logMethod(ProceedingJoinPoint pjp) throws Throwable { String className = pjp.getTarget().getClass().getName(); String methodName = pjp.getSignature().getName(); Object[] args = pjp.getArgs(); methodLogger.logEntry(className, methodName, args); try {//from www. j a v a2 s . c o m Object returnValue = pjp.proceed(); methodLogger.logExit(className, methodName, returnValue); return returnValue; } catch (Throwable e) { methodLogger.logException(className, methodName, e); throw e; } }
From source file:org.craftercms.commons.security.permissions.annotations.HasPermissionAnnotationHandler.java
License:Open Source License
protected Object getAnnotatedSecuredObject(Method method, ProceedingJoinPoint pjp) { Annotation[][] paramAnnotations = method.getParameterAnnotations(); Object[] params = pjp.getArgs(); for (int i = 0; i < paramAnnotations.length; i++) { for (Annotation a : paramAnnotations[i]) { if (a instanceof SecuredObject) { return params[i]; }//from ww w. j ava 2 s. com } } return null; }
From source file:org.cruk.genologics.api.cache.GenologicsAPICache.java
License:Open Source License
/** * Join point for changing the cach behaviour on the next call on the same thread. * Sets the thread local override behaviour to that given. * * <p>//ww w . j av a 2 s . c om * The behaviour will be reset on any call to another API method from this thread. * </p> * * @param pjp The join point object. * * @return <code>null</code> * * @throws Throwable if there is an error. * * @see GenologicsAPI#nextCallCacheOverride(CacheStatefulBehaviour) * @see #resetBehaviour(JoinPoint) */ public Object overrideBehaviour(ProceedingJoinPoint pjp) throws Throwable { Object[] args = pjp.getArgs(); behaviourOverride.set((CacheStatefulBehaviour) args[0]); if (args[0] != null) { logger.debug("Next call will override the cache behaviour from {} to {}.", behaviour, args[0]); } return pjp.proceed(); }
From source file:org.cruk.genologics.api.cache.GenologicsAPICache.java
License:Open Source License
/** * Join point for the {@code GenologicsAPI.retrieve} methods. Fetches the * object requested, either from the cache or from the API. * * @param pjp The join point object./* w w w .jav a2 s . c om*/ * * @return The object retrieved. * * @throws Throwable if there is an error. * * @see GenologicsAPI#retrieve(String, Class) * @see GenologicsAPI#retrieve(URI, Class) * @see #loadOrRetrieve(ProceedingJoinPoint, String, Class) */ public Object retrieve(ProceedingJoinPoint pjp) throws Throwable { assert pjp.getArgs().length == 2 : "Wrong number of arguments."; Object thing = pjp.getArgs()[0]; if (thing == null) { throw new IllegalArgumentException("uri cannot be null"); } Class<?> entityClass = (Class<?>) pjp.getArgs()[1]; String uri = thing.toString(); return loadOrRetrieve(pjp, uri, entityClass); }
From source file:org.cruk.genologics.api.cache.GenologicsAPICache.java
License:Open Source License
/** * Join point for the {@code GenologicsAPI.load} methods taking an id and a class. * Fetches the object requested, either from the cache or from the API. * * @param pjp The join point object.// w ww. j a v a 2 s.c o m * * @return The object retrieved. * * @throws Throwable if there is an error. * * @see GenologicsAPI#load(String, Class) * @see #loadOrRetrieve(ProceedingJoinPoint, String, Class) */ public Object loadById(ProceedingJoinPoint pjp) throws Throwable { Object[] args = pjp.getArgs(); Object id1, id2; Class<?> entityClass; String uri; switch (args.length) { case 2: id1 = args[0]; if (id1 == null) { throw new IllegalArgumentException("limsid cannot be null"); } entityClass = (Class<?>) args[1]; uri = toUriString(entityClass, id1.toString()); return loadOrRetrieve(pjp, uri, entityClass); case 3: id1 = args[0]; if (id1 == null) { throw new IllegalArgumentException("outerLimsid cannot be null"); } id2 = args[0]; if (id2 == null) { throw new IllegalArgumentException("innerLimsid cannot be null"); } entityClass = (Class<?>) args[2]; uri = toUriString(entityClass, id1.toString(), id2.toString()); return loadOrRetrieve(pjp, uri, entityClass); default: throw new AssertionError("Wrong number of arguments to a load by id method"); } }
From source file:org.cruk.genologics.api.cache.GenologicsAPICache.java
License:Open Source License
/** * Join point for the {@code GenologicsAPI.load} methods taking a {@code LimsLink}. * Fetches the object requested, either from the cache or from the API. * * @param pjp The join point object.// w ww . jav a 2 s. c om * * @return The object retrieved. * * @throws Throwable if there is an error. * * @see GenologicsAPI#load(LimsLink) * @see #loadOrRetrieve(ProceedingJoinPoint, String, Class) */ public Object loadByLink(ProceedingJoinPoint pjp) throws Throwable { assert pjp.getArgs().length == 1 : "Wrong number of arguments."; LimsLink<?> link = (LimsLink<?>) pjp.getArgs()[0]; if (link == null) { throw new IllegalArgumentException("link cannot be null"); } if (link.getUri() == null) { throw new IllegalArgumentException("link uri cannot be null"); } String uri = link.getUri().toString(); return loadOrRetrieve(pjp, uri, link.getEntityClass()); }
From source file:org.cruk.genologics.api.cache.GenologicsAPICache.java
License:Open Source License
/** * Join point for the {@code GenologicsAPI.loadAll} method. * Examines the cache for objects already loaded and only fetches those * that are not already seen (or, for stateful objects, those whose requested * state is later than that in the cache). * * @param <E> The type of LIMS entity referred to. * @param pjp The join point object.//from www . ja va 2 s . com * * @return The list of entities retrieved. * * @throws Throwable if there is an error. * * @see GenologicsAPI#loadAll(Collection) */ public <E extends Locatable> List<E> loadAll(ProceedingJoinPoint pjp) throws Throwable { @SuppressWarnings("unchecked") Collection<LimsLink<E>> links = (Collection<LimsLink<E>>) pjp.getArgs()[0]; List<E> results = new ArrayList<E>(links == null ? 0 : links.size()); if (links != null && !links.isEmpty()) { Ehcache cache = null; List<LimsLink<E>> toFetch = new ArrayList<LimsLink<E>>(links.size()); List<E> alreadyCached = new ArrayList<E>(links.size()); Boolean cacheable = null; String className = null; Boolean stateful = null; CacheStatefulBehaviour callBehaviour = behaviourOverride.get(); if (callBehaviour == null) { callBehaviour = behaviour; } behaviourLock.lock(); try { Iterator<LimsLink<E>> linkIterator = links.iterator(); // Loop through the links requested and accumulate two lists of links: // those that are not in the cache and need to be fetched and those that // have already been fetched. While doing this, assemble in "results" those // entities already in the cache that don't need to be fetch. This list will // have nulls inserted where the entity needs to be fetched. while (linkIterator.hasNext()) { LimsLink<E> link = linkIterator.next(); if (link == null) { throw new IllegalArgumentException("link contains a null"); } if (link.getUri() == null) { throw new IllegalArgumentException("A link in the collection has no URI set."); } if (className == null) { className = ClassUtils.getShortClassName(link.getEntityClass()); cacheable = isCacheable(link.getEntityClass()); stateful = isStateful(link.getEntityClass()); } E entity = null; if (!cacheable) { // Fetch always. toFetch.add(link); } else { if (cache == null) { cache = getCache(link.getEntityClass()); } String key = keyFromLocatable(link); Element wrapper = cache.get(key); if (wrapper == null) { toFetch.add(link); } else { long version = versionFromLocatable(link); switch (callBehaviour) { case ANY: entity = getFromWrapper(wrapper); alreadyCached.add(entity); break; case LATEST: if (version != NO_STATE_VALUE && version > wrapper.getVersion()) { toFetch.add(link); } else { entity = getFromWrapper(wrapper); alreadyCached.add(entity); } break; case EXACT: if (version != NO_STATE_VALUE && version != wrapper.getVersion()) { toFetch.add(link); } else { entity = getFromWrapper(wrapper); alreadyCached.add(entity); } break; } } } results.add(entity); } } finally { behaviourLock.unlock(); } if (logger.isWarnEnabled()) { if (cache.getCacheConfiguration().getMaxEntriesLocalHeap() < links.size()) { logger.warn( "{} {}s are requested, but the cache will only hold {}. Repeated fetches of this collection will always call through to the API.", links.size(), className, cache.getCacheConfiguration().getMaxEntriesLocalHeap()); } } if (logger.isDebugEnabled()) { if (alreadyCached.size() == links.size()) { logger.debug("All {} {}s requested are already in the cache.", links.size(), className); } else { logger.debug("Have {} {}s in the cache; {} to retrieve.", alreadyCached.size(), className, toFetch.size()); } } // If there is anything to fetch, perform the call to the API then // fill in the nulls in the "results" list from the entities returned // from the API. // The end result is that newly fetched items are put into the cache // and "results" is a fully populated list. if (!toFetch.isEmpty()) { assert cacheable != null : "No cacheable flag found"; assert stateful != null : "No stateful flag found"; Object[] args = { toFetch }; @SuppressWarnings("unchecked") List<E> fetched = (List<E>) pjp.proceed(args); ListIterator<E> resultIterator = results.listIterator(); ListIterator<E> fetchIterator = fetched.listIterator(); while (resultIterator.hasNext()) { E entity = resultIterator.next(); if (entity == null) { assert fetchIterator.hasNext() : "Run out of items in the fetched list."; entity = fetchIterator.next(); resultIterator.set(entity); if (cacheable) { if (!stateful) { // Entities without state will only have been fetched because they // were not in the cache. These should just be added. cache.put(createCacheElement(entity)); } else { // Stateful entities may already be in the cache but may have been // fetched because the requested version is newer or of a different // state. Some care needs to be taken to update its cached version // depending on how the cache normally behaves. String key = keyFromLocatable(entity); Element wrapper = cache.get(key); if (wrapper == null) { // Not already cached, so simply add this entity whatever // its state. cache.put(createCacheElement(entity)); } else { // As we have a stateful entity, there may be cause // to replace the object in the cache depending on how the // cache normally behaves. Typically this will be replacing the // existing with a newer version or replacing for a difference. // When we don't care about versions, the one already in the cache // can remain. long version = versionFromLocatable(entity); switch (behaviour) { case ANY: break; case LATEST: if (version > wrapper.getVersion()) { cache.put(createCacheElement(entity)); } break; case EXACT: if (version != wrapper.getVersion()) { cache.put(createCacheElement(entity)); } break; } } } } } } assert !fetchIterator.hasNext() : "Have further items fetched after populating results list."; } } return results; }
From source file:org.cruk.genologics.api.cache.GenologicsAPICache.java
License:Open Source License
/** * Join point for the {@code GenologicsAPI.reload} method. * Force a reload from the API of an object by fetching again and updating * its cache entry.//from www .j a va 2s . c om * * @param pjp The join point object. * * @throws Throwable if there is an error. * * @see GenologicsAPI#reload(LimsEntity) */ public void reload(ProceedingJoinPoint pjp) throws Throwable { Locatable entity = (Locatable) pjp.getArgs()[0]; pjp.proceed(); if (isCacheable(entity)) { Ehcache cache = getCache(entity.getClass()); cache.put(createCacheElement(entity)); } }