use of com.easy.cloud.core.lock.callback.result.EcLockResult in project dq-easy-cloud by dq-open-cloud.
the class EcLockTemplateRedission method tryLock.
@Override
public <T> T tryLock(EcLockCallback<T> callback) {
EcLockDTO lockDTO = callback.getDistributedLockDTO();
EcLockAnnotation lockAnnotation = lockDTO.getLockAnnotation();
RLock lock = getLock(lockDTO.getLockNameFull(), lockAnnotation.type());
boolean isGainLock = false;
try {
isGainLock = lock.tryLock(lockAnnotation.waitTime(), lockAnnotation.leaseTime(), lockAnnotation.timeUnit());
return callback.process(new EcLockResult(isGainLock));
} catch (InterruptedException e) {
e.printStackTrace();
throw new RuntimeException(e);
} finally {
if (lock != null && lock.isLocked() && isGainLock) {
lock.unlock();
}
}
}
use of com.easy.cloud.core.lock.callback.result.EcLockResult in project dq-easy-cloud by dq-open-cloud.
the class EcLockTemplateJedis method lock.
@Override
public <T> T lock(EcLockCallback<T> callback) {
EcLockDTO lockDTO = callback.getDistributedLockDTO();
EcLockAnnotation lockAnnotation = lockDTO.getLockAnnotation();
EcLogUtils.debug("锁的注解信息", lockAnnotation, logger);
String lockNameFull = lockDTO.getLockNameFull();
EcLock ecLock = new EcLock(stringRedisTemplateLock, lockNameFull, lockAnnotation.type());
try {
boolean gainLock = ecLock.lock(lockAnnotation.waitTime(), lockAnnotation.leaseTime(), lockAnnotation.timeUnit());
if (gainLock) {
return callback.process(new EcLockResult(true));
}
return callback.process(new EcLockResult(false));
} finally {
ecLock.unlock();
}
}
use of com.easy.cloud.core.lock.callback.result.EcLockResult 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.callback.result.EcLockResult 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