Fix RedisLockRegistry Sonar smells
* Remove redundant `subscribeLock()` method
* Rework `lock()` and `lockInterruptibly()` logic in favor of `while (true) {`
to avoid "empty `while()`" smell
This commit is contained in:
@@ -284,10 +284,9 @@ public final class RedisLockRegistry implements ExpirableLockRegistry, Disposabl
|
||||
this.localLock.lock();
|
||||
while (true) {
|
||||
try {
|
||||
while (!subscribeLock()) {
|
||||
// empty
|
||||
if (subscribeLock(-1L)) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
/*
|
||||
@@ -310,19 +309,21 @@ public final class RedisLockRegistry implements ExpirableLockRegistry, Disposabl
|
||||
@Override
|
||||
public void lockInterruptibly() throws InterruptedException {
|
||||
this.localLock.lockInterruptibly();
|
||||
try {
|
||||
while (!subscribeLock()) {
|
||||
// empty
|
||||
while (true) {
|
||||
try {
|
||||
if (subscribeLock(-1L)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (InterruptedException ie) {
|
||||
this.localLock.unlock();
|
||||
Thread.currentThread().interrupt();
|
||||
throw ie;
|
||||
}
|
||||
catch (Exception e) {
|
||||
this.localLock.unlock();
|
||||
rethrowAsLockException(e);
|
||||
}
|
||||
}
|
||||
catch (InterruptedException ie) {
|
||||
this.localLock.unlock();
|
||||
Thread.currentThread().interrupt();
|
||||
throw ie;
|
||||
}
|
||||
catch (Exception e) {
|
||||
this.localLock.unlock();
|
||||
rethrowAsLockException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -357,10 +358,6 @@ public final class RedisLockRegistry implements ExpirableLockRegistry, Disposabl
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean subscribeLock() throws ExecutionException, InterruptedException {
|
||||
return subscribeLock(-1L);
|
||||
}
|
||||
|
||||
private boolean subscribeLock(long time) throws ExecutionException, InterruptedException {
|
||||
if (!obtainLock()) {
|
||||
if (!RedisLockRegistry.this.redisMessageListenerContainer.isRunning()) {
|
||||
|
||||
Reference in New Issue
Block a user