Skip to content

Commit baaa142

Browse files
committed
Rename ConcurrencyLimiters#limiter -> acquireLimiter
1 parent c97925a commit baaa142

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

okhttp-clients/src/main/java/com/palantir/remoting3/okhttp/ConcurrencyLimiters.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,16 @@ class ConcurrencyLimiters {
5757
this(taggedMetricRegistry, DEFAULT_TIMEOUT);
5858
}
5959

60-
Limiter.Listener limiter(Request request) {
61-
return limiter(limiterKey(request));
60+
/**
61+
* Blocks until the request should be allowed to proceed.
62+
* Caller must notify the listener to release the permit.
63+
*/
64+
Limiter.Listener acquireLimiter(Request request) {
65+
return acquireLimiter(limiterKey(request));
6266
}
6367

6468
@VisibleForTesting
65-
Limiter.Listener limiter(String name) {
69+
Limiter.Listener acquireLimiter(String name) {
6670
Limiter<Void> limiter = limiters.computeIfAbsent(name, key -> newLimiter());
6771
Optional<Limiter.Listener> listener = limiter.acquire(NO_CONTEXT);
6872
return listener.orElseGet(() -> {
@@ -74,7 +78,7 @@ Limiter.Listener limiter(String name) {
7478
+ "bodies (there should be OkHttp log lines indicating this), or service overloading.",
7579
SafeArg.of("timeout", timeout));
7680
limiters.replace(name, limiter, newLimiter());
77-
return limiter(name);
81+
return acquireLimiter(name);
7882
});
7983
}
8084

okhttp-clients/src/main/java/com/palantir/remoting3/okhttp/ConcurrencyLimitingInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ final class ConcurrencyLimitingInterceptor implements Interceptor {
6969

7070
@Override
7171
public Response intercept(Chain chain) throws IOException {
72-
Limiter.Listener listener = limiters.limiter(chain.request());
72+
Limiter.Listener listener = limiters.acquireLimiter(chain.request());
7373
try {
7474
Response response = chain.proceed(chain.request());
7575
if (DROPPED_CODES.contains(response.code())) {

okhttp-clients/src/test/java/com/palantir/remoting3/okhttp/ConcurrencyLimitersTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public final class ConcurrencyLimitersTest {
3232
public void testTimeout() {
3333
Instant start = Instant.now();
3434
Thread exhauster = exhaust();
35-
limiters.limiter(KEY);
35+
limiters.acquireLimiter(KEY);
3636
Instant end = Instant.now();
3737
exhauster.interrupt();
3838
assertThat(Duration.between(start, end)).isGreaterThan(TIMEOUT);
@@ -41,7 +41,7 @@ public void testTimeout() {
4141
private Thread exhaust() {
4242
Thread thread = new Thread(() -> {
4343
while (true) {
44-
limiters.limiter(KEY);
44+
limiters.acquireLimiter(KEY);
4545
}
4646
});
4747
thread.start();

okhttp-clients/src/test/java/com/palantir/remoting3/okhttp/ConcurrencyLimitingInterceptorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public final class ConcurrencyLimitingInterceptorTest {
6161
public void before() {
6262
interceptor = new ConcurrencyLimitingInterceptor(limiters);
6363
when(chain.request()).thenReturn(request);
64-
when(limiters.limiter(request)).thenReturn(listener);
64+
when(limiters.acquireLimiter(request)).thenReturn(listener);
6565
}
6666

6767
@Test

okhttp-clients/src/test/java/com/palantir/remoting3/okhttp/FlowControlTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ private Worker(
135135
@Override
136136
public void run() {
137137
for (int i = 0; i < REQUESTS_PER_THREAD;) {
138-
Limiter.Listener listener = limiters.limiter("");
138+
Limiter.Listener listener = limiters.acquireLimiter("");
139139
boolean gotRateLimited = !rateLimiter.tryAcquire(100, TimeUnit.MILLISECONDS);
140140
if (!gotRateLimited) {
141141
meter.mark();

0 commit comments

Comments
 (0)