List of usage examples for org.aspectj.lang ProceedingJoinPoint toShortString
String toShortString();
From source file:org.flite.cach3.aop.ReadThroughAssignCacheAdvice.java
License:Open Source License
@Around("getSingleAssign()") public Object cacheAssign(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 v a 2s. c o m final MemcachedClientIF cache = getMemcachedClient(); // 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 ReadThroughAssignCache annotation = methodToCache.getAnnotation(ReadThroughAssignCache.class); info = getAnnotationInfo(annotation, methodToCache.getName(), getJitterDefault()); cacheKey = buildCacheKey(info.getAsString(AType.ASSIGN_KEY), info.getAsString(AType.NAMESPACE), info.getAsString(AType.KEY_PREFIX)); final Object result = cache.get(cacheKey); if (result != null) { 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) { cache.set(cacheKey, calculateJitteredExpiration(info.getAsInteger(AType.EXPIRATION), info.getAsInteger(AType.JITTER)), submission); } // Notify the observers that a cache interaction happened. final List<ReadThroughAssignCacheListener> listeners = getPertinentListeners( ReadThroughAssignCacheListener.class, info.getAsString(AType.NAMESPACE)); if (listeners != null && !listeners.isEmpty()) { for (final ReadThroughAssignCacheListener listener : listeners) { try { listener.triggeredReadThroughAssignCache(info.getAsString(AType.NAMESPACE), info.getAsString(AType.ASSIGN_KEY, null), result, pjp.getArgs()); } catch (Exception ex) { LOG.warn("Problem when triggering a listener.", ex); } } } } 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.ReadThroughMultiCacheAdvice.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(); }//from w w w .j av a 2 s . co m final MemcachedClientIF cache = getMemcachedClient(); // 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(); AnnotationInfo info; 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 ReadThroughMultiCache annotation = coord.getMethod().getAnnotation(ReadThroughMultiCache.class); info = getAnnotationInfo(annotation, coord.getMethod().getName(), getJitterDefault()); // Get the list of objects that will provide the keys to all the cache values. coord.setKeyObjects(getKeyObjectList(info.getAsInteger(AType.KEY_INDEX, null), pjp, coord.getMethod())); // Create key->object and object->key mappings. coord.setHolder(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(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, 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()]; 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); final String cacheBase = coord.obj2Base.get(keyObject); boolean cacheable = true; if (resultObject instanceof CacheConditionally) { cacheable = ((CacheConditionally) resultObject).isCacheable(); } if (cacheable) { cache.set(cacheKey, calculateJitteredExpiration(info.getAsInteger(AType.EXPIRATION), info.getAsInteger(AType.JITTER)), resultObject); } coord.getKey2Result().put(cacheKey, resultObject); cacheBaseIds[ix] = cacheBase; } // Notify the observers that a cache interaction happened. final List<ReadThroughMultiCacheListener> listeners = getPertinentListeners( ReadThroughMultiCacheListener.class, info.getAsString(AType.NAMESPACE)); if (listeners != null && !listeners.isEmpty()) { for (final ReadThroughMultiCacheListener listener : listeners) { try { listener.triggeredReadThroughMultiCache(info.getAsString(AType.NAMESPACE), info.getAsString(AType.KEY_PREFIX, null), Arrays.asList(cacheBaseIds), results, args); } catch (Exception ex) { LOG.warn("Problem when triggering a listener.", ex); } } } 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.ReadThroughSingleCacheAdvice.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(); }/*from w w w . j a va 2 s . c om*/ final MemcachedClientIF cache = getMemcachedClient(); // 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 ReadThroughSingleCache annotation; final AnnotationInfo info; final Object[] args = pjp.getArgs(); try { final Method methodToCache = getMethodToCache(pjp); annotation = methodToCache.getAnnotation(ReadThroughSingleCache.class); info = getAnnotationInfo(annotation, methodToCache.getName(), getJitterDefault()); baseKey = generateBaseKeySingle(args, info, methodToCache.toString()); cacheKey = buildCacheKey(baseKey, info.getAsString(AType.NAMESPACE, null), info.getAsString(AType.KEY_PREFIX, null)); final Object result = cache.get(cacheKey); if (result != null) { 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) { cache.set(cacheKey, calculateJitteredExpiration(info.getAsInteger(AType.EXPIRATION), info.getAsInteger(AType.JITTER)), submission); } // Notify the observers that a cache interaction happened. final List<ReadThroughSingleCacheListener> listeners = getPertinentListeners( ReadThroughSingleCacheListener.class, info.getAsString(AType.NAMESPACE)); if (listeners != null && !listeners.isEmpty()) { for (final ReadThroughSingleCacheListener listener : listeners) { try { listener.triggeredReadThroughSingleCache(info.getAsString(AType.NAMESPACE), info.getAsString(AType.KEY_PREFIX, null), baseKey, result, args); } catch (Exception ex) { LOG.warn("Problem when triggering a listener.", ex); } } } } 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.jdal.audit.Auditor.java
License:Apache License
/** * Around advice to audit auditable models * //w w w.j a va 2 s. c o m * @param pjp to pjp * @return object result * @throws Throwable Exception */ public Object audit(ProceedingJoinPoint pjp) throws Throwable { LOG.debug("Auditing on method: " + pjp.toShortString()); Object result = pjp.proceed(); if (pjp.getTarget() instanceof Auditable) { Auditable auditable = (Auditable) (pjp.getTarget()); audit(auditable); } else { LOG.warn("Tried to audit a non-auditable object. Check your " + "AOP configuration on applicationContext.xml"); } return result; }
From source file:org.jdal.log.MethodTracer.java
License:Apache License
/** * Simple Around Advice for trace in/out method execution * // w w w. j a v a 2 s. c om * @param pjp the joint point * @return returned object. * @throws Throwable for the method */ public Object traceMethod(ProceedingJoinPoint pjp) throws Throwable { log.debug("Enter method: " + pjp.getSignature().toLongString()); Object result = pjp.proceed(); log.debug("Exit method: " + pjp.toShortString()); return result; }
From source file:org.opentestsystem.shared.mna.client.aop.MnaClientLoggingAdvice.java
License:Open Source License
/** * Simply generates a readable string to identify the join point * //from ww w.ja v a2 s . c o m * @param pjp * @return */ protected String getJoinPointLogString(final ProceedingJoinPoint pjp) { return pjp.toShortString(); }
From source file:org.opentestsystem.shared.mna.client.aop.NullLoggingAdvice.java
License:Open Source License
/** * {@inheritDoc}// w w w . j a v a 2s .c om */ @Override public Object timeMethod(final ProceedingJoinPoint inPjp, final Logger inPerformanceLogger) { Object output = null; try { // only do this if debug is enabled if (inPerformanceLogger != null && inPerformanceLogger.isDebugEnabled()) { long start = System.currentTimeMillis(); inPerformanceLogger.debug("Using NullLoggingAdvice: Begin " + inPjp.toShortString()); output = inPjp.proceed(); long stop = System.currentTimeMillis(); long elapsedTime = stop - start; // log out to the appender that is configured inPerformanceLogger.debug("Using NullLoggingAdvice: End " + inPjp.toShortString() + " Elapsed Time: " + elapsedTime + " ms"); } else { output = inPjp.proceed(); } // allow catch of throwable because the AOP proceed call throws Throwable, also allow rethrowing as a generic // RuntimeException } catch (Throwable thr) { // NOPMD if (thr instanceof RuntimeException) { // NOPMD LOGGER.error("Using NullLoggingAdvice: Caught RuntimeException in Around Advice, rethrowing", thr); throw (RuntimeException) thr; } else { LOGGER.error( "Using NullLoggingAdvice: Caught a non-RuntimeException error in AroundAdvice, rethrowing as RuntimeException", thr); throw new RuntimeException( "Using NullLoggingAdvice: Caught a non-RuntimeException error in AroundAdvice, rethrowing as RuntimeException", thr); // NOPMD } } return output; }
From source file:org.openwms.core.integration.aop.CoreIntegrationAspect.java
License:Open Source License
/** * Called around any method invocation to log time consumption of each method call. * //from w ww .ja v a2s . c o m * @param pjp * the ProceedingJoinPoint object * @return the return value of the service method invocation * @throws Throwable * any exception thrown by the method invocation */ public Object around(ProceedingJoinPoint pjp) throws Throwable { StopWatch sw = null; if (LOGGER.isDebugEnabled()) { sw = new StopWatch(); sw.start(); LOGGER.debug("[I]>>> Method call: " + pjp.toShortString()); } try { return pjp.proceed(); } finally { try { em.flush(); } catch (Exception ex) { afterThrowing(ex); } finally { if (LOGGER.isDebugEnabled() && sw != null) { sw.stop(); LOGGER.debug("[I]<<< " + pjp.toShortString() + " took [ms]: " + sw.getTotalTimeMillis()); } } } }
From source file:org.openwms.core.service.spring.aop.CoreServiceAspect.java
License:Open Source License
/** * Called around any service method invocation to log time consumption of * each method call./*from ww w.j a v a 2 s . com*/ * * @param pjp * the ProceedingJoinPoint object * @return the return value of the service method invocation * @throws Throwable * any exception thrown by the method invocation */ public Object around(ProceedingJoinPoint pjp) throws Throwable { StopWatch sw = null; if (LOGGER.isDebugEnabled()) { sw = new StopWatch(); sw.start(); LOGGER.debug("[S]>> Method call: " + pjp.toShortString()); } try { Object[] args = pjp.getArgs(); if (args != null && args.length > 0) { for (int i = 0; i < args.length; i++) { if (args[i] != null) { validator.validate(args[i]); } } } return pjp.proceed(); } finally { if (LOGGER.isDebugEnabled() && sw != null) { sw.stop(); LOGGER.debug("[S]<< " + pjp.toShortString() + " took about [ms]: " + sw.getTotalTimeMillis()); } } }
From source file:org.osiam.resources.helper.MeasureDurationTimeOfMethods.java
License:Open Source License
@Around("excludeDynamicHTTPMethodScopeEnhancer() && includeOrgOsiam()") public Object measureTime(ProceedingJoinPoint joinPoint) throws Throwable { //NOSONAR the join point throws it and can't be omitted long start = 0, end; if (enabled) { start = System.currentTimeMillis(); }//from w w w . j a v a 2 s . c o m Object result = wrapExceptionForSonar(joinPoint); if (enabled) { end = System.currentTimeMillis(); String msg = joinPoint.toShortString() + " took " + (end - start) + "ms"; LOGGER.info(msg); } return result; }