public void onError(JoinPoint jp, StepExecution stepExecution, Throwable t) { String msg = "Error in: " + jp.toShortString() + " with: " + stepExecution + " (" + t.getClass() + ":" + t.getMessage() + ")"; publish(jp.getTarget(), msg); }
public void after(JoinPoint jp, StepExecution stepExecution) { String msg = "After: " + jp.toShortString() + " with: " + stepExecution; publish(jp.getTarget(), msg); }
public void before(JoinPoint jp, StepExecution stepExecution) { String msg = "Before: " + jp.toShortString() + " with: " + stepExecution; publish(jp.getTarget(), msg); }
public void doBasicLogging(JoinPoint pjp) throws Throwable { Object[] args = pjp.getArgs(); StringBuilder output = new StringBuilder(); output.append(pjp.getTarget().getClass().getName()).append(": "); output.append(pjp.toShortString()).append(": "); for (Object arg : args) { output.append(arg).append(" "); } log.info("Basic: " + output.toString()); }
public void onError(JoinPoint jp, StepExecution stepExecution, Throwable t) { String msg = "Error in: " + jp.toShortString() + " with: " + stepExecution + " (" + t.getClass() + ":" + t.getMessage() + ")"; publish(jp.getTarget(), msg); }
public void before(JoinPoint jp, StepExecution stepExecution) { String msg = "Before: " + jp.toShortString() + " with: " + stepExecution; publish(jp.getTarget(), msg); }
public void after(JoinPoint jp, StepExecution stepExecution) { String msg = "After: " + jp.toShortString() + " with: " + stepExecution; publish(jp.getTarget(), msg); }
assertTrue("Method named in toString", jp.toString().contains(method.getName())); jp.toShortString(); jp.toLongString();
@Override public void before(Method method, Object[] args, @Nullable Object target) throws Throwable { // makeEncSJP, although meant for computing the enclosing join point, // it serves our purpose here JoinPoint.StaticPart aspectJVersionJp = Factory.makeEncSJP(method); JoinPoint jp = AbstractAspectJAdvice.currentJoinPoint(); assertEquals(aspectJVersionJp.getSignature().toLongString(), jp.getSignature().toLongString()); assertEquals(aspectJVersionJp.getSignature().toShortString(), jp.getSignature().toShortString()); assertEquals(aspectJVersionJp.getSignature().toString(), jp.getSignature().toString()); assertEquals(aspectJVersionJp.toLongString(), jp.toLongString()); assertEquals(aspectJVersionJp.toShortString(), jp.toShortString()); assertEquals(aspectJVersionJp.toString(), jp.toString()); } });
@Override public String toShortString() { return this.joinpoint.toShortString(); } @Override
@Override public String toShortString() { return this.joinpoint.toShortString(); } @Override
/** * Instantiates a new DeprectedCodeException. * * @param jp the Joinpoint from the context which is deprecated. * @param additionalInfo the additional info */ protected DeprecatedCodeException(final JoinPoint jp, final String additionalInfo) { super(jp.toShortString() + " " + additionalInfo); }
/** * Instantiates a new DeprectedCodeException. * * @param jp the Joinpoint from the context which is deprecated. */ public DeprecatedCodeException(final JoinPoint jp) { super(jp.toShortString() + " is deprecated!"); }
protected boolean checkData(final Object data, final JoinPoint pjp) { if (!isTypeSupported(data)) { getLogger().warn("Caching on {} aborted due to incorrect return type. Should be int, long, Integer or Long is {}", new Object[] { pjp.toShortString(), (data == null) ? null : data.getClass() }); return false; } return true; }
protected boolean checkData(final Object data, final JoinPoint pjp) { if (!isTypeSupported(data)) { getLogger().warn("Caching on {} aborted due to incorrect return type. Should be int, long, Integer or Long is {}", new Object[] { pjp.toShortString(), (data == null) ? null : data.getClass() }); return false; } return true; }
@AfterReturning("decrementSingleCounter()") public void decrementSingle(final JoinPoint jp) throws Throwable { if (isDisabled()) { getLogger().info("Cache disabled"); return; } // 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. // It will be invoked only if underlying method completes successfully. String cacheKey = null; DecrementCounterInCache annotation; try { Method methodToCache = getCacheBase().getMethodToCache(jp, DecrementCounterInCache.class); annotation = methodToCache.getAnnotation(DecrementCounterInCache.class); AnnotationData data = AnnotationDataBuilder.buildAnnotationData(annotation, DecrementCounterInCache.class, methodToCache); cacheKey = getCacheBase().getCacheKeyBuilder().getCacheKey(data, jp.getArgs(), methodToCache.toString()); getCacheBase().getCache(data).decr(cacheKey, 1); } catch (Exception ex) { warn(ex, "Decrementing counter [%s] via %s aborted due to an error.", cacheKey, jp.toShortString()); } }
@AfterReturning("decrementSingleCounter()") public void decrementSingle(final JoinPoint jp) throws Throwable { if (isDisabled()) { getLogger().info("Cache disabled"); return; } // 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. // It will be invoked only if underlying method completes successfully. String cacheKey = null; DecrementCounterInCache annotation; try { Method methodToCache = getCacheBase().getMethodToCache(jp, DecrementCounterInCache.class); annotation = methodToCache.getAnnotation(DecrementCounterInCache.class); AnnotationData data = AnnotationDataBuilder.buildAnnotationData(annotation, DecrementCounterInCache.class, methodToCache); cacheKey = getCacheBase().getCacheKeyBuilder().getCacheKey(data, jp.getArgs(), methodToCache.toString()); getCacheBase().getCache(data).decr(cacheKey, 1); } catch (Exception ex) { warn(ex, "Decrementing counter [%s] via %s aborted due to an error.", cacheKey, jp.toShortString()); } }
@AfterReturning("incrementSingleCounter()") public void incrementSingle(final JoinPoint jp) throws Throwable { if (isDisabled()) { getLogger().info("Cache disabled"); return; } // 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. // It will be invoked only if underlying method completes successfully. String cacheKey = null; IncrementCounterInCache annotation; try { Method methodToCache = getCacheBase().getMethodToCache(jp, IncrementCounterInCache.class); annotation = methodToCache.getAnnotation(IncrementCounterInCache.class); AnnotationData data = AnnotationDataBuilder.buildAnnotationData(annotation, IncrementCounterInCache.class, methodToCache); cacheKey = getCacheBase().getCacheKeyBuilder().getCacheKey(data, jp.getArgs(), methodToCache.toString()); getCacheBase().getCache(data).incr(cacheKey, 1, 1); } catch (Exception ex) { warn(ex, "Incrementing counter [%s] via %s aborted due to an error.", cacheKey, jp.toShortString()); } }
@AfterReturning("incrementSingleCounter()") public void incrementSingle(final JoinPoint jp) throws Throwable { if (isDisabled()) { getLogger().info("Cache disabled"); return; } // 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. // It will be invoked only if underlying method completes successfully. String cacheKey = null; IncrementCounterInCache annotation; try { Method methodToCache = getCacheBase().getMethodToCache(jp, IncrementCounterInCache.class); annotation = methodToCache.getAnnotation(IncrementCounterInCache.class); AnnotationData data = AnnotationDataBuilder.buildAnnotationData(annotation, IncrementCounterInCache.class, methodToCache); cacheKey = getCacheBase().getCacheKeyBuilder().getCacheKey(data, jp.getArgs(), methodToCache.toString()); getCacheBase().getCache(data).incr(cacheKey, 1, 1); } catch (Exception ex) { warn(ex, "Incrementing counter [%s] via %s aborted due to an error.", cacheKey, jp.toShortString()); } }
@AfterReturning(pointcut = "updateCounter()", returning = "retVal") public void cacheCounterInCache(final JoinPoint jp, final Object retVal) throws Throwable { if (isDisabled()) { getLogger().info("Cache disabled"); return; } // For Update*Cache, an AfterReturning aspect is fine. We will only // apply our caching after the underlying method completes successfully, and we will have // the same access to the method params. String cacheKey = null; UpdateCounterInCache annotation; try { Method methodToCache = getCacheBase().getMethodToCache(jp, UpdateCounterInCache.class); annotation = methodToCache.getAnnotation(UpdateCounterInCache.class); AnnotationData data = AnnotationDataBuilder.buildAnnotationData(annotation, UpdateCounterInCache.class, methodToCache); cacheKey = getCacheBase().getCacheKeyBuilder().getCacheKey(data, jp.getArgs(), methodToCache.toString()); Object dataObject = getCacheBase().getUpdateData(data, methodToCache, jp.getArgs(), retVal); if (checkData(dataObject, jp)) { long value = ((Number) dataObject).longValue(); getCacheBase().getCache(data).setCounter(cacheKey, annotation.expiration(), value); } } catch (Exception ex) { warn(ex, "Updating counter [%s] in cache via %s aborted due to an error.", cacheKey, jp.toShortString()); } }