1 | package edu.ucsb.cs156.courses.services.jobs; | |
2 | ||
3 | import lombok.extern.slf4j.Slf4j; | |
4 | import org.springframework.beans.factory.annotation.Value; | |
5 | import org.springframework.stereotype.Component; | |
6 | import org.springframework.stereotype.Service; | |
7 | ||
8 | @Service | |
9 | @Component | |
10 | @Slf4j | |
11 | public class JobRateLimit { | |
12 | ||
13 | /** | |
14 | * The delay in milliseconds to be used for rate limiting. This value is set from the application | |
15 | * properties. | |
16 | */ | |
17 | private int rateLimitDelayMs; | |
18 | ||
19 | public JobRateLimit(@Value("${app.rateLimitDelayMs}") String rateLimitDelayMsString) { | |
20 | try { | |
21 | rateLimitDelayMs = Integer.parseInt(rateLimitDelayMsString); | |
22 | } catch (NumberFormatException e) { | |
23 | rateLimitDelayMs = 200; | |
24 | log.warn("Invalid rate limit delay: " + rateLimitDelayMsString); | |
25 | log.warn(String.format("Using default rate limit delay of %d ms", rateLimitDelayMs)); | |
26 | } | |
27 | } | |
28 | ||
29 | public void sleep() throws InterruptedException { | |
30 |
1
1. sleep : removed call to java/lang/Thread::sleep → KILLED |
Thread.sleep(rateLimitDelayMs); |
31 | } | |
32 | ||
33 | public int getRateLimitDelayMs() { | |
34 |
1
1. getRateLimitDelayMs : replaced int return with 0 for edu/ucsb/cs156/courses/services/jobs/JobRateLimit::getRateLimitDelayMs → KILLED |
return rateLimitDelayMs; |
35 | } | |
36 | } | |
Mutations | ||
30 |
1.1 |
|
34 |
1.1 |