Skip to content

Commit 32960fa

Browse files
committed
Fix RedisLockRegistry for Java 8 compatibility
1 parent cce90ea commit 32960fa

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

spring-integration-redis/src/main/java/org/springframework/integration/redis/util/RedisLockRegistry.java

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ protected boolean removeEldestEntry(Entry<String, RedisLock> eldest) {
137137
/**
138138
* It is set via lazy initialization when it is a {@link RedisLockType#PUB_SUB_LOCK}.
139139
*/
140-
private volatile RedisPubSubLock.RedisUnLockNotifyMessageListener unlockNotifyMessageListener;
140+
private volatile RedisUnLockNotifyMessageListener unlockNotifyMessageListener;
141141

142142
/**
143143
* It is set via lazy initialization when it is a {@link RedisLockType#PUB_SUB_LOCK}.
@@ -174,7 +174,7 @@ private void setupUnlockMessageListener(RedisConnectionFactory connectionFactory
174174
Assert.isNull(RedisLockRegistry.this.unlockNotifyMessageListener,
175175
"'unlockNotifyMessageListener' must not have been re-initialized.");
176176
RedisLockRegistry.this.redisMessageListenerContainer = new RedisMessageListenerContainer();
177-
RedisLockRegistry.this.unlockNotifyMessageListener = new RedisPubSubLock.RedisUnLockNotifyMessageListener();
177+
RedisLockRegistry.this.unlockNotifyMessageListener = new RedisUnLockNotifyMessageListener();
178178
final Topic topic = new ChannelTopic(this.unLockChannelKey);
179179
this.redisMessageListenerContainer.setConnectionFactory(connectionFactory);
180180
this.redisMessageListenerContainer.setTaskExecutor(this.executor);
@@ -293,8 +293,8 @@ private abstract class RedisLock implements Lock {
293293
"end " +
294294
"return false";
295295

296-
protected static final RedisScript<Boolean>
297-
OBTAIN_LOCK_REDIS_SCRIPT = new DefaultRedisScript<>(OBTAIN_LOCK_SCRIPT, Boolean.class);
296+
private final RedisScript<Boolean> obtainLockRedisScript =
297+
new DefaultRedisScript<>(OBTAIN_LOCK_SCRIPT, Boolean.class);
298298

299299
protected final String lockKey;
300300

@@ -422,7 +422,7 @@ private boolean tryRedisLock(long time) throws ExecutionException, InterruptedEx
422422

423423
protected final Boolean obtainLock() {
424424
return RedisLockRegistry.this.redisTemplate
425-
.execute(OBTAIN_LOCK_REDIS_SCRIPT, Collections.singletonList(this.lockKey),
425+
.execute(this.obtainLockRedisScript, Collections.singletonList(this.lockKey),
426426
RedisLockRegistry.this.clientId,
427427
String.valueOf(RedisLockRegistry.this.expireAfter));
428428
}
@@ -556,11 +556,11 @@ private final class RedisPubSubLock extends RedisLock {
556556
"end " +
557557
"return false";
558558

559-
private static final RedisScript<Boolean>
560-
UNLINK_UNLOCK_REDIS_SCRIPT = new DefaultRedisScript<>(UNLINK_UNLOCK_SCRIPT, Boolean.class);
559+
private final RedisScript<Boolean> unlinkUnlockRedisScript =
560+
new DefaultRedisScript<>(UNLINK_UNLOCK_SCRIPT, Boolean.class);
561561

562-
private static final RedisScript<Boolean>
563-
DELETE_UNLOCK_REDIS_SCRIPT = new DefaultRedisScript<>(DELETE_UNLOCK_SCRIPT, Boolean.class);
562+
private final RedisScript<Boolean> deleteUnlockRedisScript =
563+
new DefaultRedisScript<>(DELETE_UNLOCK_SCRIPT, Boolean.class);
564564

565565
private RedisPubSubLock(String path) {
566566
super(path);
@@ -574,14 +574,14 @@ protected boolean tryRedisLockInner(long time) throws ExecutionException, Interr
574574
@Override
575575
protected void removeLockKeyInnerUnlink() {
576576
RedisLockRegistry.this.redisTemplate.execute(
577-
UNLINK_UNLOCK_REDIS_SCRIPT, Collections.singletonList(this.lockKey),
577+
this.unlinkUnlockRedisScript, Collections.singletonList(this.lockKey),
578578
RedisLockRegistry.this.unLockChannelKey);
579579
}
580580

581581
@Override
582582
protected void removeLockKeyInnerDelete() {
583583
RedisLockRegistry.this.redisTemplate.execute(
584-
DELETE_UNLOCK_REDIS_SCRIPT, Collections.singletonList(this.lockKey),
584+
this.deleteUnlockRedisScript, Collections.singletonList(this.lockKey),
585585
RedisLockRegistry.this.unLockChannelKey);
586586

587587
}
@@ -641,31 +641,31 @@ private void runRedisMessageListenerContainer() {
641641
}
642642
}
643643

644-
private static final class RedisUnLockNotifyMessageListener implements MessageListener {
644+
}
645645

646-
private final Map<String, SettableListenableFuture<String>> notifyMap = new ConcurrentHashMap<>();
646+
private static final class RedisUnLockNotifyMessageListener implements MessageListener {
647647

648-
@Override
649-
public void onMessage(Message message, byte[] pattern) {
650-
final String lockKey = new String(message.getBody());
651-
unlockNotify(lockKey);
652-
}
648+
private final Map<String, SettableListenableFuture<String>> notifyMap = new ConcurrentHashMap<>();
653649

654-
public Future<String> subscribeLock(String lockKey) {
655-
return this.notifyMap.computeIfAbsent(lockKey, key -> new SettableListenableFuture<>());
656-
}
650+
@Override
651+
public void onMessage(Message message, byte[] pattern) {
652+
final String lockKey = new String(message.getBody());
653+
unlockNotify(lockKey);
654+
}
657655

658-
public void unSubscribeLock(String localLock) {
659-
this.notifyMap.remove(localLock);
660-
}
656+
public Future<String> subscribeLock(String lockKey) {
657+
return this.notifyMap.computeIfAbsent(lockKey, key -> new SettableListenableFuture<>());
658+
}
661659

662-
private void unlockNotify(String lockKey) {
663-
this.notifyMap.computeIfPresent(lockKey, (key, lockFuture) -> {
664-
lockFuture.set(key);
665-
return lockFuture;
666-
});
667-
}
660+
public void unSubscribeLock(String localLock) {
661+
this.notifyMap.remove(localLock);
662+
}
668663

664+
private void unlockNotify(String lockKey) {
665+
this.notifyMap.computeIfPresent(lockKey, (key, lockFuture) -> {
666+
lockFuture.set(key);
667+
return lockFuture;
668+
});
669669
}
670670

671671
}

0 commit comments

Comments
 (0)