Refine search![Refine arrow](//d16xvuom8mr9m8.cloudfront.net/code/public/images/refine-arrow.226bef887e7b1c430d6d498717d9d561.svg)
@Around("anyRepositoryMethod()") public Object invokeWithCatTransaction(ProceedingJoinPoint joinPoint) throws Throwable { String name = joinPoint.getSignature().getDeclaringType().getSimpleName() + "." + joinPoint.getSignature() .getName(); Transaction catTransaction = Tracer.newTransaction("SQL", name); try { Object result = joinPoint.proceed(); catTransaction.setStatus(Transaction.SUCCESS); return result; } catch (Throwable ex) { catTransaction.setStatus(ex); throw ex; } finally { catTransaction.complete(); } } }
@Around("onCreate()") public Object onCreateProcess(ProceedingJoinPoint joinPoint) throws Throwable { Object result = joinPoint.proceed(); Object puppet = joinPoint.getTarget(); //Only inject the class that marked by Puppet annotation. Object[] args = joinPoint.getArgs(); Method onCreate = getRiggerMethod("onCreate", Object.class, Bundle.class); onCreate.invoke(getRiggerInstance(), puppet, args[0]); return result; }
public static Method getCompensableMethod(ProceedingJoinPoint pjp) { Method method = ((MethodSignature) (pjp.getSignature())).getMethod(); if (method.getAnnotation(Compensable.class) == null) { try { method = pjp.getTarget().getClass().getMethod(method.getName(), method.getParameterTypes()); } catch (NoSuchMethodException e) { return null; } } return method; }
protected Method resolveMethod(ProceedingJoinPoint joinPoint) { MethodSignature signature = (MethodSignature)joinPoint.getSignature(); Class<?> targetClass = joinPoint.getTarget().getClass(); Method method = getDeclaredMethodFor(targetClass, signature.getName(), signature.getMethod().getParameterTypes()); if (method == null) { throw new IllegalStateException("Cannot resolve target method: " + signature.getMethod().getName()); } return method; }
@org.aspectj.lang.annotation.Around("@within(org.bytesoft.compensable.Compensable)") public Object invoke(final ProceedingJoinPoint pjp) throws Throwable { CompensableManager compensableManager = this.beanFactory.getCompensableManager(); CompensableTransaction compensable = compensableManager.getCompensableTransactionQuietly(); if (compensable != null && compensable.getTransactionContext() != null && compensable.getTransactionContext().isCompensating()) { return pjp.proceed(); } Object bean = pjp.getThis(); String identifier = this.getBeanName(bean); MethodSignature signature = (MethodSignature) pjp.getSignature(); Method method = signature.getMethod(); Object[] args = pjp.getArgs(); AspectJoinpoint point = new AspectJoinpoint(pjp); return this.execute(identifier, method, args, point); }
@Around("execution(@org.apache.ignite.compute.gridify.GridifySetToValue * *(..)) && !cflow(call(* org.apache.ignite.compute.ComputeJob.*(..)))") public Object gridify(ProceedingJoinPoint joinPnt) throws Throwable { Method mtd = ((MethodSignature) joinPnt.getSignature()).getMethod(); mtd.getParameterTypes(), mtd.getParameterAnnotations(), joinPnt.getArgs(), joinPnt.getTarget()); return joinPnt.proceed(); return joinPnt.proceed(); return joinPnt.proceed(); Ignite ignite = G.ignite(igniteInstanceName); return execute(mtd, ignite.compute(), joinPnt.getSignature().getDeclaringType(), arg, nodeFilter, ann.threshold(), ann.splitSize(), ann.timeout()); for (Class<?> ex : ((MethodSignature) joinPnt.getSignature()).getMethod().getExceptionTypes()) {
/** * Do tagging for @TagReturnValue. */ @Around(value = "execution(* *(..)) && (@annotation(tagReturnValue))") public Object doTagging(ProceedingJoinPoint pjp, TagReturnValue tagReturnValue) throws Throwable { Object result = pjp.proceed(); MoSKitoContext.addTag(tagReturnValue.name(), result == null ? null : result.toString(), TagType.ANNOTATED, pjp.getSignature().toShortString()); return result; }
@Around(value = "within(com.github.prontera..*) " + "&& (@annotation(org.springframework.web.bind.annotation.ResponseBody)" + "|| @annotation(org.springframework.web.bind.annotation.RequestMapping))") public Object aroundMethod(ProceedingJoinPoint joinPoint) throws Throwable { for (Object arg : joinPoint.getArgs()) { if (arg instanceof BindingResult) { throwIfInvalidModel((BindingResult) arg, throwIfInvalidModel); } } return joinPoint.proceed(); }
@Around("methodAnnotated() || constructorAnnotated()")//在连接点进行方法替换 public Object aroundJoinPoint(ProceedingJoinPoint joinPoint) throws Throwable { MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); LogUtils.showLog("TimeLog getDeclaringClass", methodSignature.getMethod().getDeclaringClass().getCanonicalName()); String className = methodSignature.getDeclaringType().getSimpleName(); String methodName = methodSignature.getName(); long startTime = System.nanoTime(); Object result = joinPoint.proceed();//执行原方法 StringBuilder keyBuilder = new StringBuilder(); keyBuilder.append(methodName + ":"); for (Object obj : joinPoint.getArgs()) { if (obj instanceof String) keyBuilder.append((String) obj); else if (obj instanceof Class) keyBuilder.append(((Class) obj).getSimpleName()); } String key = keyBuilder.toString(); LogUtils.showLog("TimeLog", (className + "." + key + joinPoint.getArgs().toString() + " --->:" + "[" + (TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime)) + "ms]"));// 打印时间差 return result; } }
@Around(value = "matchAnnotatedClassOrMethod(limitedService)", argNames = "proceedingJoinPoint, limitedService") public Object rateLimiterAroundAdvice(ProceedingJoinPoint proceedingJoinPoint, RateLimiter limitedService) throws Throwable { RateLimiter targetService = limitedService; Method method = ((MethodSignature) proceedingJoinPoint.getSignature()).getMethod(); String methodName = method.getDeclaringClass().getName() + "#" + method.getName(); if (targetService == null) { targetService = getRateLimiterAnnotation(proceedingJoinPoint); } String name = targetService.name(); io.github.resilience4j.ratelimiter.RateLimiter rateLimiter = getOrCreateRateLimiter(methodName, name); return handleJoinPoint(proceedingJoinPoint, rateLimiter, methodName); }
@Around("construct()") public Object constructProcess(ProceedingJoinPoint joinPoint) throws Throwable { Object result = joinPoint.proceed(); Object puppet = joinPoint.getTarget(); //Only inject the class that marked by Puppet annotation. Method onAttach = getRiggerMethod("onPuppetConstructor", Object.class); onAttach.invoke(getRiggerInstance(), puppet); return result; }
private DTXInfo get0(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { String signature = proceedingJoinPoint.getSignature().toString(); String unitId = Transactions.unitId(signature); DTXInfo dtxInfo = dtxInfoCache.get(unitId); if (Objects.isNull(dtxInfo)) { MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature(); Method method = methodSignature.getMethod(); Class<?> targetClass = proceedingJoinPoint.getTarget().getClass(); Method thisMethod = targetClass.getMethod(method.getName(), method.getParameterTypes()); dtxInfo = new DTXInfo(thisMethod, proceedingJoinPoint.getArgs(), targetClass); dtxInfoCache.put(unitId, dtxInfo); } dtxInfo.reanalyseMethodArgs(proceedingJoinPoint.getArgs()); return dtxInfo; }
@Around("methodAnnotated()")//在连接点进行方法替换 public Object aroundJoinPoint(ProceedingJoinPoint joinPoint) throws Throwable { MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); String methodName = methodSignature.getName(); MemoryCacheManager mMemoryCacheManager = MemoryCacheManager.getInstance(); StringBuilder keyBuilder = new StringBuilder(); keyBuilder.append(methodName); for (Object obj : joinPoint.getArgs()) { if (obj instanceof String) keyBuilder.append((String) obj); else if (obj instanceof Class) keyBuilder.append(((Class) obj).getSimpleName()); } String key = keyBuilder.toString(); Object result = mMemoryCacheManager.get(key);//key规则 : 方法名+参数1+参数2+... LogUtils.showLog("MemoryCache", "key:" + key + "--->" + (result != null ? "not null" : "null")); if (result != null) return result;//缓存已有,直接返回 result = joinPoint.proceed();//执行原方法 if (result instanceof List && result != null && ((List) result).size() > 0 //列表不为空 || result instanceof String && !TextUtils.isEmpty((String) result)//字符不为空 || result instanceof Object && result != null)//对象不为空 mMemoryCacheManager.add(key, result);//存入缓存 LogUtils.showLog("MemoryCache", "key:" + key + "--->" + "save"); return result; } }
@Around("@annotation(com.github.prontera.Delay)") public Object aroundMethod(ProceedingJoinPoint joinPoint) throws Throwable { final Object result = joinPoint.proceed(); final long timeInMillseconds = delayProperties.getTimeInMillseconds(); if (timeInMillseconds != 0L) { LOGGER.debug("method {} was made delay {} mills to return result", joinPoint.getSignature(), timeInMillseconds); TimeUnit.MILLISECONDS.sleep(timeInMillseconds); } return result; }
private void scheduleAround() throws Throwable { Signature sig = Mockito.mock(Signature.class); when(pjp.getSignature()).thenReturn(sig); when(sig.getDeclaringType()).thenReturn(String.class); when(pjp.proceed()).thenReturn(data); when(pjp.getTarget()).thenReturn(this); jobs.aroundScheduledJob(pjp); } }
public Object checkAndProceed(ProceedingJoinPoint pjp) throws Throwable { Signature signature = pjp.getSignature(); MethodSignature methodSignature = (MethodSignature) signature; Method method = methodSignature.getMethod(); if (method.isAnnotationPresent(Cache.class)) { Cache cache = method.getAnnotation(Cache.class);// method.getAnnotationsByType(Cache.class)[0]; return this.proceed(pjp, cache); } try { return pjp.proceed(); } catch (Throwable e) { throw e; } }
@Around("execution(* com.oath.micro.server.events.ScheduledJob.scheduleAndLog(..))") public Object aroundScheduledJob(ProceedingJoinPoint pjp) throws Throwable { String type = jobNameType.getCreator() .getType(pjp.getSignature() .getDeclaringType()); return executeScheduledJob(pjp, type); }
public Object profileMethod(final ProceedingJoinPoint call) throws Throwable { final long startTime = System.nanoTime(); try { return call.proceed(); } finally { if (logger.isDebugEnabled()) { final long endTime = System.nanoTime(); final long durationMilliseconds = (endTime - startTime) / 1000000; final String methodCall = call.getSignature().toLongString(); logger.debug("'" + methodCall + "' Time to complete call (ms): " + durationMilliseconds); } } }