use of com.jim.framework.annotationlock.annotation.RequestLockable 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();
}
Aggregations