List of usage examples for org.aspectj.lang ProceedingJoinPoint getSignature
Signature getSignature();
getStaticPart().getSignature()
returns the same object 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())); }/*w w w . j ava 2 s .c o m*/ 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./* w w w. j a v a2s . c o 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.codelabor.system.advices.SnifferAdvice.java
License:Apache License
public Object getElapsedTime(ProceedingJoinPoint joinPoint) throws Throwable { String className = joinPoint.getTarget().getClass().getName(); String methodName = joinPoint.getSignature().getName() + "()"; StopWatch stopWatch = new StopWatch(getClass().getName()); stopWatch.start(joinPoint.toShortString()); Object returnValue = joinPoint.proceed(); stopWatch.stop();//from w w w . j a v a 2s . c om StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(System.getProperty("line.separator")); stringBuilder.append("class: ").append(className); stringBuilder.append(System.getProperty("line.separator")); stringBuilder.append("method: ").append(methodName); stringBuilder.append(System.getProperty("line.separator")); stringBuilder.append("total time (millis): ").append(stopWatch.getTotalTimeMillis()); log.debug(stringBuilder.toString()); return returnValue; }
From source file:org.codelabor.system.sniffer.advice.SniffingAdvice.java
License:Apache License
/** * ? .//from w w w .j av a 2 s . c o m * * @param joinPoint * ? ?? * @return * @throws Throwable * */ public Object dumpElapsedTime(ProceedingJoinPoint joinPoint) throws Throwable { Object retrunValue = null; StopWatch stopWatch = null; if (logger.isDebugEnabled()) { stopWatch = new StopWatch(getClass().getName()); stopWatch.start(joinPoint.toShortString()); } retrunValue = joinPoint.proceed(); if (logger.isDebugEnabled()) { stopWatch.stop(); long totalTimeMillis = stopWatch.getTotalTimeMillis(); logger.debug("class: {}", joinPoint.getTarget().getClass().getName()); logger.debug("method: {}", joinPoint.getSignature().getName()); logger.debug("total time (millis): {}", totalTimeMillis); } return retrunValue; }
From source file:org.codelabor.system.sniffer.advices.SnifferAdvice.java
License:Apache License
public Object getElapsedTime(ProceedingJoinPoint joinPoint) throws Throwable { Object returnValue = null;/*w w w. j ava 2s . c om*/ if (log.isDebugEnabled()) { String className = joinPoint.getTarget().getClass().getName(); String methodName = joinPoint.getSignature().getName() + "()"; StopWatch stopWatch = new StopWatch(getClass().getName()); stopWatch.start(joinPoint.toShortString()); returnValue = joinPoint.proceed(); stopWatch.stop(); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(System.getProperty("line.separator")); stringBuilder.append("class: ").append(className); stringBuilder.append(System.getProperty("line.separator")); stringBuilder.append("method: ").append(methodName); stringBuilder.append(System.getProperty("line.separator")); stringBuilder.append("total time (millis): ").append(stopWatch.getTotalTimeMillis()); log.debug(stringBuilder.toString()); } return returnValue; }
From source file:org.codelabor.system.sniffer.aspect.SniffingAspect.java
License:Apache License
/** * ? ./*from w w w . j a v a 2s . c o m*/ * * @param joinPoint * ? ?? * @return * @throws Throwable * */ public void dumpElapsedTime(ProceedingJoinPoint joinPoint) throws Throwable { if (logger.isInfoEnabled()) { StopWatch stopWatch = new StopWatch(getClass().getName()); stopWatch.start(joinPoint.toShortString()); joinPoint.proceed(); stopWatch.stop(); long totalTimeMillis = stopWatch.getTotalTimeMillis(); logger.info("target: {}", joinPoint.getTarget().getClass().getName()); logger.info("signature: {}", joinPoint.getSignature().getName()); logger.info("total time millis: {}", totalTimeMillis); } }
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 w ww. ja va 2 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.cruk.genologics.api.cache.GenologicsAPICache.java
License:Open Source License
/** * Fetch an object from the cache or, if it's not yet been seen, from the * API and store the result in the cache for future use. * * <p>/*from w w w .j a v a2s . co m*/ * Special consideration has to be made for objects that have a "state" * parameter to their URIs. See the class description for more details. * </p> * * @param pjp The join point object. * @param uri The URI of the object to fetch. * @param entityClass The type of object to fetch. * * @return The object retrieved. * * @throws Throwable if there is an error. */ protected Object loadOrRetrieve(ProceedingJoinPoint pjp, String uri, Class<?> entityClass) throws Throwable { if (!isCacheable(entityClass)) { return pjp.proceed(); } final boolean statefulEntity = isStateful(entityClass); final String className = ClassUtils.getShortClassName(entityClass); Ehcache cache = getCache(entityClass); CacheStatefulBehaviour callBehaviour = behaviourOverride.get(); if (callBehaviour == null) { callBehaviour = behaviour; } Locatable genologicsObject = null; String key = keyFromUri(uri); long version = NO_STATE_VALUE; Element wrapper = null; if (key != null) { wrapper = cache.get(key); if (wrapper != null) { if (!statefulEntity) { genologicsObject = getFromWrapper(wrapper); } else { version = versionFromUri(uri); switch (callBehaviour) { case ANY: genologicsObject = getFromWrapper(wrapper); break; case LATEST: if (version == NO_STATE_VALUE || version <= wrapper.getVersion()) { genologicsObject = getFromWrapper(wrapper); } break; case EXACT: if (version == NO_STATE_VALUE || version == wrapper.getVersion()) { genologicsObject = getFromWrapper(wrapper); } break; } } } } if (genologicsObject == null) { if (logger.isDebugEnabled()) { if (version == NO_STATE_VALUE) { logger.debug("Don't have {} {} - calling through to API {}", className, key, pjp.getSignature().getName()); } else { logger.debug("Have a different version of {} {} - calling through to API {}", className, key, pjp.getSignature().getName()); } } genologicsObject = (Locatable) pjp.proceed(); if (wrapper == null) { // Not already in the cache, so it needs to be stored. cache.put(createCacheElement(genologicsObject)); } else { // Most entities already in the cache will just stay there. // If though 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. if (statefulEntity) { switch (behaviour) { case ANY: break; case LATEST: if (version > wrapper.getVersion()) { cache.put(createCacheElement(genologicsObject)); } break; case EXACT: if (version != wrapper.getVersion()) { cache.put(createCacheElement(genologicsObject)); } break; } } } } else { if (logger.isDebugEnabled()) { logger.debug("Already have {} {} in the cache.", className, key); } } return genologicsObject; }
From source file:org.cruk.genologics.api.cache.GenologicsAPICacheTest.java
License:Open Source License
@Test public void testLoadOrRetrieveLatest() throws Throwable { checkCredentialsSet();//from w w w . j av a 2 s.co m cacheAspect.setStatefulBehaviour(CacheStatefulBehaviour.LATEST); //CacheManager mockCacheManager = EasyMock.createMock(CacheManager.class); //EasyMock.expect(mockCacheManager.getCache(Artifact.class.getName())).andReturn(value); cacheAspect.getCache(Artifact.class).removeAll(); String base = api.getServerApiAddress(); Signature jpSig = createSignatureMock(); Artifact a1 = new Artifact(); a1.setUri(new URI(base + "/artifacts/2-1771911?state=1294907")); a1.setLimsid("2-1771911"); Object[] a1args = { a1.getUri(), a1.getClass() }; ProceedingJoinPoint pjp1 = EasyMock.createStrictMock(ProceedingJoinPoint.class); EasyMock.expect(pjp1.getArgs()).andReturn(a1args).times(3); EasyMock.expect(pjp1.getSignature()).andReturn(jpSig).times(0, 1); EasyMock.expect(pjp1.proceed()).andReturn(a1).once(); EasyMock.replay(pjp1, jpSig); Object returned = cacheAspect.retrieve(pjp1); EasyMock.verify(pjp1, jpSig); assertSame("Did not return a1", a1, returned); Artifact a2 = new Artifact(); a2.setUri(new URI(base + "/artifacts/2-1771911?state=1500000")); a2.setLimsid("2-1771911"); Object[] a2args = { a2.getUri(), a2.getClass() }; jpSig = createSignatureMock(); ProceedingJoinPoint pjp2 = EasyMock.createStrictMock(ProceedingJoinPoint.class); EasyMock.expect(pjp2.getArgs()).andReturn(a2args).times(3); EasyMock.expect(pjp2.getSignature()).andReturn(jpSig).times(0, 1); EasyMock.expect(pjp2.proceed()).andReturn(a2).once(); EasyMock.replay(pjp2, jpSig); returned = cacheAspect.retrieve(pjp2); assertSame("Did not return a2", a2, returned); EasyMock.verify(pjp2, jpSig); // With an earlier state, expect the later version to be returned regardless. Object[] a3args = { base + "/artifacts/2-1771911?state=1101002", a1.getClass() }; jpSig = createSignatureMock(); ProceedingJoinPoint pjp3 = EasyMock.createStrictMock(ProceedingJoinPoint.class); EasyMock.expect(pjp3.getArgs()).andReturn(a3args).times(3); EasyMock.replay(pjp3, jpSig); returned = cacheAspect.retrieve(pjp3); EasyMock.verify(pjp3, jpSig); assertSame("Did not return a2", a2, returned); // With no state, expect whichever version is in the cache. Object[] a4args = { base + "/artifacts/2-1771911", Artifact.class }; jpSig = createSignatureMock(); ProceedingJoinPoint pjp4 = EasyMock.createStrictMock(ProceedingJoinPoint.class); EasyMock.expect(pjp4.getArgs()).andReturn(a4args).times(3); EasyMock.replay(pjp4, jpSig); returned = cacheAspect.retrieve(pjp4); EasyMock.verify(pjp4, jpSig); assertSame("Did not return a2", a2, returned); }
From source file:org.cruk.genologics.api.cache.GenologicsAPICacheTest.java
License:Open Source License
@Test public void testLoadOrRetrieveExact() throws Throwable { checkCredentialsSet();//from ww w . j av a 2 s .c o m cacheAspect.setStatefulBehaviour(CacheStatefulBehaviour.EXACT); cacheAspect.getCache(Artifact.class).removeAll(); String base = api.getServerApiAddress(); Signature jpSig = createSignatureMock(); Artifact a1 = new Artifact(); a1.setUri(new URI(base + "/artifacts/2-1771911?state=1294907")); a1.setLimsid("2-1771911"); Object[] a1args = { a1.getUri(), a1.getClass() }; ProceedingJoinPoint pjp1 = EasyMock.createStrictMock(ProceedingJoinPoint.class); EasyMock.expect(pjp1.getArgs()).andReturn(a1args).times(3); EasyMock.expect(pjp1.getSignature()).andReturn(jpSig).times(0, 1); EasyMock.expect(pjp1.proceed()).andReturn(a1).once(); EasyMock.replay(pjp1, jpSig); Object returned = cacheAspect.retrieve(pjp1); EasyMock.verify(pjp1, jpSig); assertSame("Did not return a1", a1, returned); Artifact a2 = new Artifact(); a2.setUri(new URI(base + "/artifacts/2-1771911?state=1500000")); a2.setLimsid("2-1771911"); Object[] a2args = { a2.getUri(), a2.getClass() }; jpSig = createSignatureMock(); ProceedingJoinPoint pjp2 = EasyMock.createStrictMock(ProceedingJoinPoint.class); EasyMock.expect(pjp2.getArgs()).andReturn(a2args).times(3); EasyMock.expect(pjp2.getSignature()).andReturn(jpSig).times(0, 1); EasyMock.expect(pjp2.proceed()).andReturn(a2).once(); EasyMock.replay(pjp2, jpSig); returned = cacheAspect.retrieve(pjp2); assertSame("Did not return a2", a2, returned); EasyMock.verify(pjp2, jpSig); // In exact, this request for an earlier version will require another fetch. Artifact a3 = new Artifact(); a3.setUri(new URI(base + "/artifacts/2-1771911?state=1101002")); a3.setLimsid("2-1771911"); Object[] a3args = { a3.getUri(), a3.getClass() }; jpSig = createSignatureMock(); ProceedingJoinPoint pjp3 = EasyMock.createStrictMock(ProceedingJoinPoint.class); EasyMock.expect(pjp3.getArgs()).andReturn(a3args).times(3); EasyMock.expect(pjp3.getSignature()).andReturn(jpSig).times(0, 1); EasyMock.expect(pjp3.proceed()).andReturn(a3).once(); EasyMock.replay(pjp3, jpSig); returned = cacheAspect.retrieve(pjp3); EasyMock.verify(pjp3, jpSig); assertSame("Did not return a3", a3, returned); // With no state, expect whichever version is in the cache. Object[] a4args = { base + "/artifacts/2-1771911", Artifact.class }; jpSig = createSignatureMock(); ProceedingJoinPoint pjp4 = EasyMock.createStrictMock(ProceedingJoinPoint.class); EasyMock.expect(pjp4.getArgs()).andReturn(a4args).times(3); EasyMock.replay(pjp4, jpSig); returned = cacheAspect.retrieve(pjp4); EasyMock.verify(pjp4, jpSig); assertSame("Did not return a3", a3, returned); }