List of usage examples for org.aspectj.lang ProceedingJoinPoint toShortString
String toShortString();
From source file:de.forsthaus.backend.util.db.logging.ServiceLogging.java
License:Open Source License
public Object logging(ProceedingJoinPoint call) throws Throwable { startTimes.add(Long.valueOf(System.nanoTime())); try {/*from ww w . jav a 2 s. c o m*/ // LOG.info("Start call: " + call.toShortString()); return call.proceed(); } finally { methodName = call.toShortString(); finishTime = (System.nanoTime() - startTimes.remove().longValue()) / 1000000; if (startTimes.isEmpty()) { methodName = StringUtils.substring(methodName, 10, -1); // LOG.info("Execution time: " + finishTime + "ms " + // methodName); loggingService.saveStatistics(statistics, methodName, finishTime); init(); } } }
From source file:de.unioninvestment.eai.portal.portlet.crud.aspects.SqlContainerLoggingAspect.java
License:Apache License
private Object runAndLogDuration(ProceedingJoinPoint pjp) throws Throwable { if (LOG.isInfoEnabled()) { long startTime = System.currentTimeMillis(); try {/*from w w w .j ava 2s. c om*/ if (LOG.isDebugEnabled()) { LOG.debug("Starting " + pjp.toShortString()); } return pjp.proceed(); } finally { long endTime = System.currentTimeMillis(); long duration = endTime - startTime; if (duration > SLOW_CALL_DURATION_MS) { LOG.info("Leaving " + pjp.toShortString() + " (" + duration + "ms)"); } else if (LOG.isDebugEnabled()) { LOG.debug("Leaving " + pjp.toShortString() + " (" + duration + "ms)"); } } } else { return pjp.proceed(); } }
From source file:gov.nih.nci.cabig.caaers.tools.logging.CaaersLoggingAspect.java
License:BSD License
@Around("execution(public * gov.nih.nci.cabig.caaers.api.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.api.impl.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.dao..*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.domain.repository.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.domain.repository.ajax.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.service..*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.validation..*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.workflow..*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.rules.business.service.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.rules.runtime.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.web.ae.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.web.study.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.web.admin.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.web.rule.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.web.participant.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.tools.Excel*.*(..))") public Object log(ProceedingJoinPoint call) throws Throwable { Log logger = (call.getTarget() == null) ? LogFactory.getLog(CaaersLoggingAspect.class) : LogFactory.getLog(call.getTarget().getClass()); //just proceed to call if Info is not enabled. if (logger == null || !logger.isInfoEnabled()) return call.proceed(); boolean traceEnabled = logger.isTraceEnabled(); String userName = ""; if (traceEnabled) { userName = "[" + getUserLoginName() + "] - "; log(logger, true, call, null, 0, userName); }/*from ww w. jav a2 s. co m*/ long startTime = System.currentTimeMillis(); //proceed with the call Object point = call.proceed(); long endTime = System.currentTimeMillis(); long executionTime = (endTime - startTime); if (executionTime > 500) { logger.info(userName + "More than 500ms [ " + call.toShortString() + " executionTime : " + executionTime + "]"); } if (traceEnabled) { log(logger, false, call, point, executionTime, userName); } return point; }
From source file:gov.nih.nci.cabig.caaers.tools.logging.CaaersLoggingAspect.java
License:BSD License
private void log(Log logger, boolean entry, ProceedingJoinPoint call, Object retVal, long time, String userName) {//from w w w . j a v a2 s .co m try { StringBuilder sb = new StringBuilder("[").append(userName).append("] - "); if (entry) { Object[] args = call.getArgs(); sb.append(entryMsgPrefix).append(" [").append(call.toShortString()).append(" ] with params { ") .append(String.valueOf(args != null && args.length > 0 ? args[0] : "")).append("}"); } else { sb.append(exitMsgPrefix).append(" [").append(call.toShortString()).append(" ] with return as: {") .append(String.valueOf(retVal)).append("} - executionTime : ").append(time); } logger.trace(sb.toString()); } catch (Exception e) { } }
From source file:io.curly.commons.logging.MethodExecutionAspectInterceptor.java
License:Apache License
@SuppressWarnings("ArgNamesErrorsInspection") @Around(value = "execution(* *(..)) && @annotation(loggable)) ", argNames = "joinPoint, loggable") public Object invoke(ProceedingJoinPoint joinPoint, Loggable loggable) throws Throwable { if (executionEnabled) { StopWatch watch = new StopWatch(joinPoint.toShortString()); watch.start();/*from w w w. j a v a 2s .c om*/ try { return joinPoint.proceed(); } finally { watch.stop(); synchronized (this) { if (actuatorEnabled && (gaugeService != null)) { String gagueName = "gauge.execution." + joinPoint.getTarget() + "." + joinPoint.getSignature().getName(); gaugeService.submit(gagueName, watch.getLastTaskTimeMillis()); } log(loggable.value(), joinPoint.getTarget().getClass(), "Executed method {} in {} ms", joinPoint.getSignature().getName(), watch.getLastTaskTimeMillis()); } } } return joinPoint.proceed(); }
From source file:net.nelz.simplesm.aop.InvalidateAssignCacheAdvice.java
License:Open Source License
@Around("invalidateAssign()") public Object cacheInvalidateAssign(final ProceedingJoinPoint pjp) throws Throwable { 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 {/*from w w w .j a v a 2s. co m*/ final Method methodToCache = getMethodToCache(pjp); final InvalidateAssignCache annotation = methodToCache.getAnnotation(InvalidateAssignCache.class); final AnnotationData annotationData = AnnotationDataBuilder.buildAnnotationData(annotation, InvalidateAssignCache.class, methodToCache); final String cacheKey = buildCacheKey(annotationData.getAssignedKey(), annotationData); if (cacheKey == null || cacheKey.trim().length() == 0) { throw new InvalidParameterException("Unable to find a cache key"); } cache.delete(cacheKey); } catch (Throwable ex) { LOG.warn("Caching on " + pjp.toShortString() + " aborted due to an error.", ex); } return result; }
From source file:net.nelz.simplesm.aop.InvalidateMultiCacheAdvice.java
License:Open Source License
@Around("invalidateMulti()") public Object cacheInvalidateMulti(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. List<String> cacheKeys = null; final AnnotationData annotationData; final String methodDescription; try {//from w w w. j a va2s. c om final Method methodToCache = getMethodToCache(pjp); methodDescription = methodToCache.toString(); final InvalidateMultiCache annotation = methodToCache.getAnnotation(InvalidateMultiCache.class); annotationData = AnnotationDataBuilder.buildAnnotationData(annotation, InvalidateMultiCache.class, methodToCache); if (annotationData.getKeyIndex() > -1) { final Object keyObject = getIndexObject(annotationData.getKeyIndex(), pjp, methodToCache); final List<Object> keyObjects = convertToKeyObjects(keyObject, annotationData.getKeyIndex(), methodDescription); cacheKeys = getCacheKeys(keyObjects, annotationData); } } 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 { // If we have a -1 key index, then build the cacheKeys now. if (annotationData.getKeyIndex() == -1) { final List<Object> keyObjects = convertToKeyObjects(result, annotationData.getKeyIndex(), methodDescription); cacheKeys = getCacheKeys(keyObjects, annotationData); } if (cacheKeys != null && cacheKeys.size() > 0) { for (final String key : cacheKeys) { if (key != null && key.trim().length() > 0) { cache.delete(key); } } } } catch (Throwable ex) { LOG.warn("Caching on " + pjp.toShortString() + " aborted due to an error.", ex); } return result; }
From source file:net.nelz.simplesm.aop.InvalidateSingleCacheAdvice.java
License:Open Source License
@Around("invalidateSingle()") public Object cacheInvalidateSingle(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. String cacheKey = null;/*from w w w . jav a 2s .co m*/ final AnnotationData annotationData; try { final Method methodToCache = getMethodToCache(pjp); final InvalidateSingleCache annotation = methodToCache.getAnnotation(InvalidateSingleCache.class); annotationData = AnnotationDataBuilder.buildAnnotationData(annotation, InvalidateSingleCache.class, methodToCache); if (annotationData.getKeyIndex() > -1) { final Object keyObject = getIndexObject(annotationData.getKeyIndex(), pjp, methodToCache); final Method keyMethod = getKeyMethod(keyObject); final String objectId = generateObjectId(keyMethod, keyObject); cacheKey = buildCacheKey(objectId, annotationData); } } 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 { // If we have a -1 key index, then build the cacheKey now. if (annotationData.getKeyIndex() == -1) { final Method keyMethod = getKeyMethod(result); final String objectId = generateObjectId(keyMethod, result); cacheKey = buildCacheKey(objectId, annotationData); } if (cacheKey == null || cacheKey.trim().length() == 0) { throw new InvalidParameterException("Unable to find a cache key"); } cache.delete(cacheKey); } catch (Throwable ex) { LOG.warn("Caching on " + pjp.toShortString() + " aborted due to an error.", ex); } return result; }
From source file:net.nelz.simplesm.aop.ReadThroughAssignCacheAdvice.java
License:Open Source License
@Around("getSingleAssign()") public Object cacheSingleAssign(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 AnnotationData annotationData; try {//from w ww . ja v a 2 s .c o m final Method methodToCache = getMethodToCache(pjp); final ReadThroughAssignCache annotation = methodToCache.getAnnotation(ReadThroughAssignCache.class); annotationData = AnnotationDataBuilder.buildAnnotationData(annotation, ReadThroughAssignCache.class, methodToCache); cacheKey = buildCacheKey(annotationData.getAssignedKey(), 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, annotationData.getExpiration(), submission); } catch (Throwable ex) { LOG.warn("Caching on " + pjp.toShortString() + " aborted due to an error.", ex); } return result; }
From source file:net.nelz.simplesm.aop.ReadThroughMultiCacheAdvice.java
License:Open Source License
@Around("getMulti()") public Object cacheMulti(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 MultiCacheCoordinator coord = new MultiCacheCoordinator(); Object[] args = pjp.getArgs(); try {//from www .j a v a 2 s . c o m // 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 ReadThroughMultiCache annotation = coord.getMethod().getAnnotation(ReadThroughMultiCache.class); coord.setAnnotationData(AnnotationDataBuilder.buildAnnotationData(annotation, ReadThroughMultiCache.class, coord.getMethod())); // Get the list of objects that will provide the keys to all the cache values. coord.setKeyObjects(getKeyObjectList(coord.getAnnotationData().getKeyIndex(), pjp, coord.getMethod())); // Create key->object and object->key mappings. coord.setHolder(convertIdObjectsToKeyMap(coord.getKeyObjects(), coord.getAnnotationData())); // Get the full list of cache keys and ask the cache for the corresponding values. coord.setInitialKey2Result(cache.getBulk(coord.getKey2Obj().keySet())); // 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); } catch (Throwable ex) { LOG.warn("Caching on " + pjp.toShortString() + " aborted due to an error.", ex); 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."); } 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.obj2Key.get(keyObject); cache.set(cacheKey, coord.getAnnotationData().getExpiration(), resultObject); coord.getKey2Result().put(cacheKey, resultObject); } return coord.generateResultList(); } catch (Throwable ex) { LOG.warn("Caching on " + pjp.toShortString() + " aborted due to an error. The underlying method will be called twice.", ex); return pjp.proceed(); } }