@@ -21,12 +21,7 @@ public class AsyncRateLimitQueue extends RateLimitQueue<
2121 private static final ConcurrentMap <String , ConcurrentMap <String , AsyncRateLimitQueue >> ALL_QUEUES = new ConcurrentHashMap <>();
2222
2323 private static ConcurrentMap <String , AsyncRateLimitQueue > getInstance (String executorName ) {
24- ConcurrentMap <String , AsyncRateLimitQueue > teamIdToQueue = ALL_QUEUES .get (executorName );
25- if (teamIdToQueue == null ) {
26- teamIdToQueue = new ConcurrentHashMap <>();
27- ALL_QUEUES .put (executorName , teamIdToQueue );
28- }
29- return teamIdToQueue ;
24+ return ALL_QUEUES .computeIfAbsent (executorName , key -> new ConcurrentHashMap <>());
3025 }
3126
3227 private AsyncMethodsRateLimiter rateLimiter ; // intentionally mutable
@@ -51,17 +46,18 @@ public static AsyncRateLimitQueue getOrCreate(MethodsConfig config, String teamI
5146 if (teamId == null ) {
5247 throw new IllegalArgumentException ("`teamId` is required" );
5348 }
49+
5450 ConcurrentMap <String , AsyncRateLimitQueue > teamIdToQueue = getInstance (config .getExecutorName ());
55- AsyncRateLimitQueue queue = teamIdToQueue . get ( teamId );
56- if ( queue != null && queue . getRateLimiter (). getMetricsDatastore () != config . getMetricsDatastore ()) {
57- // As the metrics datastore has been changed, we should replace the executor
58- queue .setRateLimiter (new AsyncMethodsRateLimiter (config ));
59- }
60- if ( queue == null ) {
61- queue = new AsyncRateLimitQueue ( config ) ;
62- teamIdToQueue . put ( teamId , queue );
63- }
64- return queue ;
51+
52+ teamIdToQueue . computeIfPresent ( teamId , ( key , value ) -> {
53+ if ( value . getRateLimiter (). getMetricsDatastore () != config . getMetricsDatastore ()) {
54+ value .setRateLimiter (new AsyncMethodsRateLimiter (config ));
55+ }
56+
57+ return value ;
58+ } );
59+
60+ return teamIdToQueue . computeIfAbsent ( teamId , key -> new AsyncRateLimitQueue ( config )) ;
6561 }
6662
6763 @ Data
0 commit comments