use of com.easy.cloud.core.lock.annotation.EcLockAnnotation in project dq-easy-cloud by dq-open-cloud.
the class EcLockBO method buildDistributedLockResultProcessor.
/**
* <p>
* 构建分布式锁结果处理对象
* </p>
*
* @return
* @author daiqi
* @创建时间 2018年4月14日 下午12:00:15
*/
private EcLockBO buildDistributedLockResultProcessor() {
// 先构建注解
EcLockAnnotation distributedLock = buildEcDistributedLock().lockDTO.getLockAnnotation();
Class<? extends EcBaseLockResultProcessor> resultProcessorClass = distributedLock.resultProcessorClass();
// 结果处理类class为空 使用默认的结果处理类进行处理
if (EcBaseUtils.isNull(resultProcessorClass)) {
resultProcessorClass = EcDefaultLockResultProcessor.class;
}
// 根据class创建结果处理对象
resultProcessor = EcBeanFactory.newInstance(resultProcessorClass);
if (EcBaseUtils.isNull(resultProcessor)) {
throw new EcBaseBusinessException(EcLockErrorCodeEnum.RESULT_PROCESSOR_OBJ_CREATE_FAIL);
}
return this;
}
use of com.easy.cloud.core.lock.annotation.EcLockAnnotation in project dq-easy-cloud by dq-open-cloud.
the class EcLockTemplateRedission method lock.
@Override
public <T> T lock(EcLockCallback<T> callback) {
EcLockDTO lockDTO = callback.getDistributedLockDTO();
EcLockAnnotation lockAnnotation = lockDTO.getLockAnnotation();
EcLogUtils.debug("锁的注解信息", lockAnnotation, logger);
RLock lock = getLock(lockDTO.getLockNameFull(), lockAnnotation.type());
try {
lock.lock(lockAnnotation.leaseTime(), lockAnnotation.timeUnit());
return callback.process(new EcLockResult(true));
} finally {
if (lock != null && lock.isLocked()) {
lock.unlock();
}
}
}
use of com.easy.cloud.core.lock.annotation.EcLockAnnotation in project dq-easy-cloud by dq-open-cloud.
the class EcLockTemplateJedis method tryLock.
@Override
public <T> T tryLock(EcLockCallback<T> callback) {
EcLockDTO lockDTO = callback.getDistributedLockDTO();
EcLockAnnotation lockAnnotation = lockDTO.getLockAnnotation();
EcLock ecLock = new EcLock(stringRedisTemplateLock, lockDTO.getLockNameFull(), lockAnnotation.type());
boolean isGainLock = false;
try {
isGainLock = ecLock.tryLock(lockAnnotation.waitTime(), lockAnnotation.leaseTime(), lockAnnotation.timeUnit());
return callback.process(new EcLockResult(isGainLock));
} catch (InterruptedException e) {
e.printStackTrace();
throw new RuntimeException(e);
} finally {
ecLock.unlock();
}
}
Aggregations