@@ -137,7 +137,7 @@ protected boolean removeEldestEntry(Entry<String, RedisLock> eldest) {
137
137
/**
138
138
* It is set via lazy initialization when it is a {@link RedisLockType#PUB_SUB_LOCK}.
139
139
*/
140
- private volatile RedisPubSubLock . RedisUnLockNotifyMessageListener unlockNotifyMessageListener ;
140
+ private volatile RedisUnLockNotifyMessageListener unlockNotifyMessageListener ;
141
141
142
142
/**
143
143
* It is set via lazy initialization when it is a {@link RedisLockType#PUB_SUB_LOCK}.
@@ -174,7 +174,7 @@ private void setupUnlockMessageListener(RedisConnectionFactory connectionFactory
174
174
Assert .isNull (RedisLockRegistry .this .unlockNotifyMessageListener ,
175
175
"'unlockNotifyMessageListener' must not have been re-initialized." );
176
176
RedisLockRegistry .this .redisMessageListenerContainer = new RedisMessageListenerContainer ();
177
- RedisLockRegistry .this .unlockNotifyMessageListener = new RedisPubSubLock . RedisUnLockNotifyMessageListener ();
177
+ RedisLockRegistry .this .unlockNotifyMessageListener = new RedisUnLockNotifyMessageListener ();
178
178
final Topic topic = new ChannelTopic (this .unLockChannelKey );
179
179
this .redisMessageListenerContainer .setConnectionFactory (connectionFactory );
180
180
this .redisMessageListenerContainer .setTaskExecutor (this .executor );
@@ -293,8 +293,8 @@ private abstract class RedisLock implements Lock {
293
293
"end " +
294
294
"return false" ;
295
295
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 );
298
298
299
299
protected final String lockKey ;
300
300
@@ -422,7 +422,7 @@ private boolean tryRedisLock(long time) throws ExecutionException, InterruptedEx
422
422
423
423
protected final Boolean obtainLock () {
424
424
return RedisLockRegistry .this .redisTemplate
425
- .execute (OBTAIN_LOCK_REDIS_SCRIPT , Collections .singletonList (this .lockKey ),
425
+ .execute (this . obtainLockRedisScript , Collections .singletonList (this .lockKey ),
426
426
RedisLockRegistry .this .clientId ,
427
427
String .valueOf (RedisLockRegistry .this .expireAfter ));
428
428
}
@@ -556,11 +556,11 @@ private final class RedisPubSubLock extends RedisLock {
556
556
"end " +
557
557
"return false" ;
558
558
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 );
561
561
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 );
564
564
565
565
private RedisPubSubLock (String path ) {
566
566
super (path );
@@ -574,14 +574,14 @@ protected boolean tryRedisLockInner(long time) throws ExecutionException, Interr
574
574
@ Override
575
575
protected void removeLockKeyInnerUnlink () {
576
576
RedisLockRegistry .this .redisTemplate .execute (
577
- UNLINK_UNLOCK_REDIS_SCRIPT , Collections .singletonList (this .lockKey ),
577
+ this . unlinkUnlockRedisScript , Collections .singletonList (this .lockKey ),
578
578
RedisLockRegistry .this .unLockChannelKey );
579
579
}
580
580
581
581
@ Override
582
582
protected void removeLockKeyInnerDelete () {
583
583
RedisLockRegistry .this .redisTemplate .execute (
584
- DELETE_UNLOCK_REDIS_SCRIPT , Collections .singletonList (this .lockKey ),
584
+ this . deleteUnlockRedisScript , Collections .singletonList (this .lockKey ),
585
585
RedisLockRegistry .this .unLockChannelKey );
586
586
587
587
}
@@ -641,31 +641,31 @@ private void runRedisMessageListenerContainer() {
641
641
}
642
642
}
643
643
644
- private static final class RedisUnLockNotifyMessageListener implements MessageListener {
644
+ }
645
645
646
- private final Map < String , SettableListenableFuture < String >> notifyMap = new ConcurrentHashMap <>();
646
+ private static final class RedisUnLockNotifyMessageListener implements MessageListener {
647
647
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 <>();
653
649
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
+ }
657
655
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
+ }
661
659
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
+ }
668
663
664
+ private void unlockNotify (String lockKey ) {
665
+ this .notifyMap .computeIfPresent (lockKey , (key , lockFuture ) -> {
666
+ lockFuture .set (key );
667
+ return lockFuture ;
668
+ });
669
669
}
670
670
671
671
}
0 commit comments