List of usage examples for org.aspectj.lang ProceedingJoinPoint toShortString
String toShortString();
From source file:net.nelz.simplesm.aop.ReadThroughSingleCacheAdvice.java
License:Open Source License
@Around("getSingle()") public Object cacheGetSingle(final ProceedingJoinPoint pjp) throws Throwable { // 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 String cacheKey; final ReadThroughSingleCache annotation; try {/* www . j a v a 2 s . c o m*/ final Method methodToCache = getMethodToCache(pjp); annotation = methodToCache.getAnnotation(ReadThroughSingleCache.class); final AnnotationData annotationData = AnnotationDataBuilder.buildAnnotationData(annotation, ReadThroughSingleCache.class, methodToCache); final String objectId = getObjectId(annotationData.getKeyIndex(), pjp, methodToCache); cacheKey = buildCacheKey(objectId, annotationData); final Object result = cache.get(cacheKey); if (result != null) { LOG.debug("Cache hit."); return (result instanceof PertinentNegativeNull) ? null : result; } } catch (Throwable ex) { LOG.warn("Caching on " + pjp.toShortString() + " aborted due to an error.", ex); 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 = (result == null) ? new PertinentNegativeNull() : result; cache.set(cacheKey, annotation.expiration(), submission); } catch (Throwable ex) { LOG.warn("Caching on " + pjp.toShortString() + " aborted due to an error.", ex); } return result; }
From source file:org.ameba.aop.ServiceLayerAspect.java
License:Apache License
/** * Around intercepted methods do some logging and exception translation. <p> <ul> <li> Set log level of {@link * LoggingCategories#SERVICE_LAYER_ACCESS} to INFO to enable method tracing. <li>Set log level of {@link * LoggingCategories#SERVICE_LAYER_EXCEPTION} to ERROR to enable exception logging. </ul> </p> * * @param pjp The joinpoint//from w w w . j a v a 2 s . c o m * @return Method return value * @throws Throwable in case of errors */ @Around("org.ameba.aop.Pointcuts.servicePointcut()") public Object around(ProceedingJoinPoint pjp) throws Throwable { long startMillis = 0L; if (SRV_LOGGER.isDebugEnabled()) { SRV_LOGGER.debug("[S]>> Method call: {}", pjp.toShortString()); startMillis = System.currentTimeMillis(); } Object obj = null; try { obj = pjp.proceed(); } catch (Exception ex) { Exception e = translateException(ex); if (EXC_LOGGER.isErrorEnabled()) { EXC_LOGGER.error(e.getLocalizedMessage(), e); } throw e; } finally { if (SRV_LOGGER.isDebugEnabled()) { SRV_LOGGER.debug("[S]<< {} took {} [ms]", pjp.toShortString(), (System.currentTimeMillis() - startMillis)); } } return obj; }
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 . ja va2 s.c o m*/ 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 a v 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;//from w w w. j av a 2 s .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
/** * ? ./* w w w . j av a2 s. com*/ * * @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.eurekastreams.server.aop.PerformanceTimer.java
License:Apache License
/** * Method for logging timing data.//from w w w. j av a2 s .c om * * @param call * {@link ProceedingJoinPoint} * @return result of wrapped method. * @throws Throwable * on error. */ public Object profile(final ProceedingJoinPoint call) throws Throwable { StopWatch clock = null; // get the perf log for target object. Log log = LogFactory.getLog("perf.timer." + call.getTarget().getClass().getCanonicalName()); try { if (log.isInfoEnabled()) { clock = new StopWatch(); clock.start(call.toShortString()); } return call.proceed(); } finally { if (log.isInfoEnabled() && clock != null) { clock.stop(); Object[] args = call.getArgs(); StringBuffer params = new StringBuffer(); for (Object obj : args) { params.append("Param: " + ((obj == null) ? "null" : obj.toString()) + "\n\t"); } log.info(clock.getTotalTimeMillis() + " (ms) - " + call.getTarget().getClass().getSimpleName() + "." + call.getSignature().toShortString() + "\n\t" + params.toString()); } } }
From source file:org.flite.cach3.aop.L2ReadThroughAssignCacheAdvice.java
License:Open Source License
@Around("getL2SingleAssign()") public Object cacheL2Assign(final ProceedingJoinPoint pjp) throws Throwable { // If we've disabled the caching programmatically (or via properties file) just flow through. if (isCacheDisabled()) { LOG.debug("Caching is disabled."); return pjp.proceed(); }/*from www. j av a2 s . 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 String cacheKey; final AnnotationInfo info; try { final Method methodToCache = getMethodToCache(pjp); final L2ReadThroughAssignCache annotation = methodToCache.getAnnotation(L2ReadThroughAssignCache.class); info = getAnnotationInfo(annotation, methodToCache.getName()); cacheKey = buildCacheKey(info.getAsString(AType.ASSIGN_KEY), info.getAsString(AType.NAMESPACE), info.getAsString(AType.KEY_PREFIX)); final Map<String, Object> results = getCache().getBulk(Arrays.asList(cacheKey), info.<Duration>getAsType(AType.WINDOW, null)); final Object result = results == null ? null : results.get(cacheKey); if (result != null) { // LOG.debug("Cache hit for key " + cacheKey); return (result instanceof PertinentNegativeNull) ? null : result; } } catch (Throwable ex) { if (LOG.isDebugEnabled()) { LOG.warn("Caching on " + pjp.toShortString() + " aborted due to an error.", ex); } else { LOG.warn("Caching on " + pjp.toShortString() + " aborted due to an error: " + ex.getMessage()); } 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 = (result == null) ? new PertinentNegativeNull() : result; boolean cacheable = true; if (submission instanceof CacheConditionally) { cacheable = ((CacheConditionally) submission).isCacheable(); } if (cacheable) { getCache().setBulk(ImmutableMap.of(cacheKey, submission), info.<Duration>getAsType(AType.WINDOW, null)); } } catch (Throwable ex) { if (LOG.isDebugEnabled()) { LOG.warn("Caching on " + pjp.toShortString() + " aborted due to an error.", ex); } else { LOG.warn("Caching on " + pjp.toShortString() + " aborted due to an error: " + ex.getMessage()); } } return result; }
From source file:org.flite.cach3.aop.L2ReadThroughMultiCacheAdvice.java
License:Open Source License
@Around("getMulti()") public Object cacheMulti(final ProceedingJoinPoint pjp) throws Throwable { // If we've disabled the caching programmatically (or via properties file) just flow through. if (isCacheDisabled()) { LOG.debug("Caching is disabled."); return pjp.proceed(); }// w w w.j a v a 2s . co m AnnotationInfo info; final MultiCacheCoordinator coord = new MultiCacheCoordinator(); Object[] args = pjp.getArgs(); try { // Get the target method being invoked, and make sure it returns the correct info. coord.setMethod(getMethodToCache(pjp)); verifyReturnTypeIsList(coord.getMethod(), ReadThroughMultiCache.class); // Get the annotation associated with this method, and make sure the values are valid. final L2ReadThroughMultiCache annotation = coord.getMethod() .getAnnotation(L2ReadThroughMultiCache.class); info = getAnnotationInfo(annotation, coord.getMethod().getName()); // Get the list of objects that will provide the keys to all the cache values. coord.setKeyObjects(ReadThroughMultiCacheAdvice .getKeyObjectList(info.getAsInteger(AType.KEY_INDEX, null), pjp, coord.getMethod())); // Create key->object and object->key mappings. coord.setHolder(ReadThroughMultiCacheAdvice.convertIdObjectsToKeyMap(coord.getKeyObjects(), info.getAsString(AType.NAMESPACE), info.getAsString(AType.KEY_PREFIX), info.getAsString(AType.KEY_TEMPLATE), factory, methodStore, args)); // Get the full list of cache keys and ask the cache for the corresponding values. coord.setInitialKey2Result( getCache().getBulk(coord.getKey2Obj().keySet(), info.<Duration>getAsType(AType.WINDOW, null))); // We've gotten all positive cache results back, so build up a results list and return it. if (coord.getMissObjects().size() < 1) { return coord.generateResultList(); } // Create the new list of arguments with a subset of the key objects that aren't in the cache. args = coord.modifyArgumentList(args, info.getAsInteger(AType.KEY_INDEX, null)); } catch (Throwable ex) { // If there's an exception somewhere in the caching code, then just bail out // and call through to the target method with the original parameters. if (LOG.isDebugEnabled()) { LOG.warn("Caching on " + pjp.toShortString() + " aborted due to an error.", ex); } else { LOG.warn("Caching on " + pjp.toShortString() + " aborted due to an error: " + ex.getMessage()); } 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 results = (List) pjp.proceed(args); try { if (results.size() != coord.getMissObjects().size()) { throw new RuntimeException("Did not receive a correlated amount of data from the target method."); } final String[] cacheBaseIds = new String[results.size()]; final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); for (int ix = 0; ix < results.size(); ix++) { final Object keyObject = coord.getMissObjects().get(ix); final Object resultObject = results.get(ix) == null ? new PertinentNegativeNull() : results.get(ix); final String cacheKey = coord.getObj2Key().get(keyObject); final String cacheBase = coord.getObj2Base().get(keyObject); boolean cacheable = true; if (resultObject instanceof CacheConditionally) { cacheable = ((CacheConditionally) resultObject).isCacheable(); } if (cacheable) { builder.put(cacheKey, resultObject); } else { coord.getKey2Result().put(cacheKey, resultObject); } cacheBaseIds[ix] = cacheBase; } final ImmutableMap<String, Object> input = builder.build(); getCache().setBulk(input, info.<Duration>getAsType(AType.WINDOW, null)); coord.getKey2Result().putAll(input); return coord.generateResultList(); } catch (Throwable ex) { if (LOG.isDebugEnabled()) { LOG.warn("Caching on " + pjp.toShortString() + " aborted due to an error. (The underlying method will be called twice.)", ex); } else { LOG.warn("Caching on " + pjp.toShortString() + " aborted due to an error. (The underlying method will be called twice.): " + ex.getMessage()); } return pjp.proceed(); } }
From source file:org.flite.cach3.aop.L2ReadThroughSingleCacheAdvice.java
License:Open Source License
@Around("getSingle()") public Object cacheSingle(final ProceedingJoinPoint pjp) throws Throwable { // If we've disabled the caching programmatically (or via properties file) just flow through. if (isCacheDisabled()) { LOG.debug("Caching is disabled."); return pjp.proceed(); }/* w ww . j a va2 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 String baseKey; final String cacheKey; final L2ReadThroughSingleCache annotation; final AnnotationInfo info; final Object[] args = pjp.getArgs(); try { final Method methodToCache = getMethodToCache(pjp); annotation = methodToCache.getAnnotation(L2ReadThroughSingleCache.class); info = getAnnotationInfo(annotation, methodToCache.getName()); baseKey = generateBaseKeySingle(args, info, methodToCache.toString()); cacheKey = buildCacheKey(baseKey, info.getAsString(AType.NAMESPACE, null), info.getAsString(AType.KEY_PREFIX, null)); final Map<String, Object> results = getCache().getBulk(Arrays.asList(cacheKey), info.<Duration>getAsType(AType.WINDOW, null)); final Object result = results == null ? null : results.get(cacheKey); if (result != null) { // LOG.debug("Cache hit for key " + cacheKey); return (result instanceof PertinentNegativeNull) ? null : result; } } catch (Throwable ex) { if (LOG.isDebugEnabled()) { LOG.warn("Caching on " + pjp.toShortString() + " aborted due to an error.", ex); } else { LOG.warn("Caching on " + pjp.toShortString() + " aborted due to an error: " + ex.getMessage()); } 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 = (result == null) ? new PertinentNegativeNull() : result; boolean cacheable = true; if (submission instanceof CacheConditionally) { cacheable = ((CacheConditionally) submission).isCacheable(); } if (cacheable) { getCache().setBulk(ImmutableMap.of(cacheKey, submission), info.<Duration>getAsType(AType.WINDOW, null)); } } catch (Throwable ex) { if (LOG.isDebugEnabled()) { LOG.warn("Caching on " + pjp.toShortString() + " aborted due to an error.", ex); } else { LOG.warn("Caching on " + pjp.toShortString() + " aborted due to an error: " + ex.getMessage()); } } return result; }