use of org.aspectj.lang.reflect.MethodSignature in project vip by guangdada.
the class PermissionAop method doPermission.
@Around("cutPermission()")
public Object doPermission(ProceedingJoinPoint point) throws Throwable {
MethodSignature ms = (MethodSignature) point.getSignature();
Method method = ms.getMethod();
Permission permission = method.getAnnotation(Permission.class);
Object[] permissions = permission.value();
if (permissions == null || permissions.length == 0) {
// 检查全体角色
boolean result = PermissionCheckManager.checkAll();
if (result) {
return point.proceed();
} else {
throw new NoPermissionException();
}
} else {
// 检查指定角色
boolean result = PermissionCheckManager.check(permissions);
if (result) {
return point.proceed();
} else {
throw new NoPermissionException();
}
}
}
use of org.aspectj.lang.reflect.MethodSignature in project resilience4j by resilience4j.
the class RateLimiterAspect method rateLimiterAroundAdvice.
@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);
}
use of org.aspectj.lang.reflect.MethodSignature in project resilience4j by resilience4j.
the class CircuitBreakerAspect method circuitBreakerAroundAdvice.
@Around(value = "matchAnnotatedClassOrMethod(backendMonitored)", argNames = "proceedingJoinPoint, backendMonitored")
public Object circuitBreakerAroundAdvice(ProceedingJoinPoint proceedingJoinPoint, CircuitBreaker backendMonitored) throws Throwable {
Method method = ((MethodSignature) proceedingJoinPoint.getSignature()).getMethod();
String methodName = method.getDeclaringClass().getName() + "#" + method.getName();
if (backendMonitored == null) {
backendMonitored = getBackendMonitoredAnnotation(proceedingJoinPoint);
}
String backend = backendMonitored.backend();
io.github.resilience4j.circuitbreaker.CircuitBreaker circuitBreaker = getOrCreateCircuitBreaker(methodName, backend);
return handleJoinPoint(proceedingJoinPoint, circuitBreaker, methodName);
}
use of org.aspectj.lang.reflect.MethodSignature in project jim-framework by jiangmin168168.
the class AbstractRequestLockInterceptor method doAround.
@Around("pointcut()")
public Object doAround(ProceedingJoinPoint point) throws Throwable {
Signature signature = point.getSignature();
MethodSignature methodSignature = (MethodSignature) signature;
Method method = methodSignature.getMethod();
String targetName = point.getTarget().getClass().getName();
String methodName = point.getSignature().getName();
Object[] arguments = point.getArgs();
if (method != null && method.isAnnotationPresent(RequestLockable.class)) {
logger.info("RequestLockable doAround start");
RequestLockable requestLockable = method.getAnnotation(RequestLockable.class);
String requestLockKey = getLockKey(method, targetName, methodName, requestLockable.key(), arguments);
Lock lock = this.getLock(requestLockKey);
boolean isLock = this.tryLock(requestLockable.maximumWaiteTime(), requestLockable.expirationTime(), requestLockable.timeUnit(), lock);
if (isLock) {
try {
logger.info("RequestLockable point.proceed start");
return point.proceed();
} finally {
try {
lock.unlock();
} catch (IllegalMonitorStateException e) {
logger.info("not locked by current thread", e);
}
}
} else {
logger.error("get lock error,key:{}", requestLockKey);
// 多线程场景下主线程捕获异常需要注意,不同的调用方式可能会影响异常的抛出
throw new RuntimeException("get lock error");
}
}
return point.proceed();
}
use of org.aspectj.lang.reflect.MethodSignature in project micrometer by micrometer-metrics.
the class TimedAspect method timedMethod.
@Around("execution (@io.micrometer.core.annotation.Timed * *.*(..))")
public Object timedMethod(ProceedingJoinPoint pjp) throws Throwable {
Method method = ((MethodSignature) pjp.getSignature()).getMethod();
Timed timed = method.getAnnotation(Timed.class);
final String metricName = timed.value().isEmpty() ? DEFAULT_METRIC_NAME : timed.value();
Timer.Sample sample = Timer.start(registry);
try {
return pjp.proceed();
} finally {
sample.stop(Timer.builder(metricName).description(timed.description().isEmpty() ? null : timed.description()).tags(timed.extraTags()).tags(tagsBasedOnJoinpoint.apply(pjp)).publishPercentileHistogram(timed.histogram()).publishPercentiles(timed.percentiles().length == 0 ? null : timed.percentiles()).register(registry));
}
}
Aggregations