Skip to content

Commit 37cadf3

Browse files
authored
JavaDoc Improvement (#1905)
1 parent df54ba9 commit 37cadf3

26 files changed

+132
-56
lines changed

client/src/main/java/org/asynchttpclient/AsyncCompletionHandlerBase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* Simple {@link AsyncHandler} of type {@link Response}
2424
*/
2525
public class AsyncCompletionHandlerBase extends AsyncCompletionHandler<Response> {
26+
2627
@Override
2728
public @Nullable Response onCompleted(@Nullable Response response) throws Exception {
2829
return response;

client/src/main/java/org/asynchttpclient/DefaultAsyncHttpClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import java.util.concurrent.atomic.AtomicBoolean;
4141
import java.util.function.Predicate;
4242

43-
import static org.asynchttpclient.util.Assertions.assertNotNull;
43+
import static java.util.Objects.requireNonNull;
4444
import static org.asynchttpclient.util.HttpConstants.Methods.CONNECT;
4545
import static org.asynchttpclient.util.HttpConstants.Methods.DELETE;
4646
import static org.asynchttpclient.util.HttpConstants.Methods.GET;
@@ -294,7 +294,7 @@ private <T> ListenableFuture<T> execute(Request request, final AsyncHandler<T> a
294294
private <T> FilterContext<T> preProcessRequest(FilterContext<T> fc) throws FilterException {
295295
for (RequestFilter asyncFilter : config.getRequestFilters()) {
296296
fc = asyncFilter.filter(fc);
297-
assertNotNull(fc, "filterContext");
297+
requireNonNull(fc, "filterContext");
298298
}
299299

300300
Request request = fc.getRequest();

client/src/main/java/org/asynchttpclient/Realm.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
import static java.nio.charset.StandardCharsets.ISO_8859_1;
3131
import static java.nio.charset.StandardCharsets.UTF_8;
32-
import static org.asynchttpclient.util.Assertions.assertNotNull;
32+
import static java.util.Objects.requireNonNull;
3333
import static org.asynchttpclient.util.HttpConstants.Methods.GET;
3434
import static org.asynchttpclient.util.MessageDigestUtils.pooledMd5MessageDigest;
3535
import static org.asynchttpclient.util.MiscUtils.isNonEmpty;
@@ -92,7 +92,7 @@ private Realm(@Nullable AuthScheme scheme,
9292
@Nullable Map<String, String> customLoginConfig,
9393
@Nullable String loginContextName) {
9494

95-
this.scheme = assertNotNull(scheme, "scheme");
95+
this.scheme = requireNonNull(scheme, "scheme");
9696
this.principal = principal;
9797
this.password = password;
9898
this.realmName = realmName;

client/src/main/java/org/asynchttpclient/channel/NoopChannelPool.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,69 @@
2222
import java.util.Map;
2323
import java.util.function.Predicate;
2424

25+
/**
26+
* A {@link ChannelPool} implementation that doesn't pool anything.
27+
*/
2528
public enum NoopChannelPool implements ChannelPool {
2629

2730
INSTANCE;
2831

32+
/**
33+
*
34+
* @return always false since this is a {@link NoopChannelPool}
35+
*/
2936
@Override
3037
public boolean offer(Channel channel, Object partitionKey) {
3138
return false;
3239
}
3340

41+
/**
42+
*
43+
* @return always null since this is a {@link NoopChannelPool}
44+
*/
3445
@Override
3546
public @Nullable Channel poll(Object partitionKey) {
3647
return null;
3748
}
3849

50+
/**
51+
*
52+
* @return always false since this is a {@link NoopChannelPool}
53+
*/
3954
@Override
4055
public boolean removeAll(Channel channel) {
4156
return false;
4257
}
4358

59+
/**
60+
*
61+
* @return always true since this is a {@link NoopChannelPool}
62+
*/
4463
@Override
4564
public boolean isOpen() {
4665
return true;
4766
}
4867

68+
/**
69+
*
70+
* Does nothing since this is a {@link NoopChannelPool}
71+
*/
4972
@Override
5073
public void destroy() {
5174
}
5275

76+
/**
77+
*
78+
* Does nothing since this is a {@link NoopChannelPool}
79+
*/
5380
@Override
5481
public void flushPartitions(Predicate<Object> predicate) {
5582
}
5683

84+
/**
85+
*
86+
* @return always {@link Collections#emptyMap()} since this is a {@link NoopChannelPool}
87+
*/
5788
@Override
5889
public Map<String, Long> getIdleChannelCountPerHost() {
5990
return Collections.emptyMap();

client/src/main/java/org/asynchttpclient/config/AsyncHttpClientConfigHelper.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,29 @@ public void reload() {
6464
propsCache.clear();
6565
}
6666

67+
/**
68+
* Parse a property file.
69+
*
70+
* @param file the file to parse
71+
* @param required if true, the file must be present
72+
* @return the parsed properties
73+
* @throws RuntimeException if the file is required and not present or if the file can't be parsed
74+
*/
6775
private Properties parsePropertiesFile(String file, boolean required) {
6876
Properties props = new Properties();
6977

70-
InputStream is = getClass().getResourceAsStream(file);
71-
if (is != null) {
72-
try {
73-
props.load(is);
74-
} catch (IOException e) {
75-
throw new IllegalArgumentException("Can't parse config file " + file, e);
78+
try (InputStream is = getClass().getResourceAsStream(file)) {
79+
if (is != null) {
80+
try {
81+
props.load(is);
82+
} catch (IOException e) {
83+
throw new IllegalArgumentException("Can't parse config file " + file, e);
84+
}
85+
} else if (required) {
86+
throw new IllegalArgumentException("Can't locate config file " + file);
7687
}
77-
} else if (required) {
78-
throw new IllegalArgumentException("Can't locate config file " + file);
88+
} catch (IOException e) {
89+
throw new RuntimeException(e);
7990
}
8091

8192
return props;

client/src/main/java/org/asynchttpclient/cookie/ThreadSafeCookieStore.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import io.netty.handler.codec.http.cookie.Cookie;
1919
import org.asynchttpclient.uri.Uri;
20-
import org.asynchttpclient.util.Assertions;
2120
import org.asynchttpclient.util.MiscUtils;
2221
import org.jetbrains.annotations.NotNull;
2322
import org.jetbrains.annotations.Nullable;
@@ -34,6 +33,8 @@
3433
import java.util.function.Predicate;
3534
import java.util.stream.Collectors;
3635

36+
import static java.util.Objects.requireNonNull;
37+
3738
public final class ThreadSafeCookieStore implements CookieStore {
3839

3940
private final Map<String, Map<CookieKey, StoredCookie>> cookieJar = new ConcurrentHashMap<>();
@@ -88,7 +89,6 @@ public void evictExpired() {
8889
removeExpired();
8990
}
9091

91-
9292
@Override
9393
public int incrementAndGet() {
9494
return counter.incrementAndGet();
@@ -226,8 +226,11 @@ private List<Cookie> getStoredCookies(String domain, String path, boolean secure
226226

227227
private void removeExpired() {
228228
final boolean[] removed = {false};
229-
cookieJar.values().forEach(cookieMap -> removed[0] |= cookieMap.entrySet().removeIf(
230-
v -> hasCookieExpired(v.getValue().cookie, v.getValue().createdAt)));
229+
230+
cookieJar.values()
231+
.forEach(cookieMap -> removed[0] |= cookieMap.entrySet()
232+
.removeIf(v -> hasCookieExpired(v.getValue().cookie, v.getValue().createdAt)));
233+
231234
if (removed[0]) {
232235
cookieJar.entrySet().removeIf(entry -> entry.getValue() == null || entry.getValue().isEmpty());
233236
}
@@ -243,11 +246,12 @@ private static class CookieKey implements Comparable<CookieKey> {
243246
}
244247

245248
@Override
246-
public int compareTo(@NotNull CookieKey o) {
247-
Assertions.assertNotNull(o, "Parameter can't be null");
249+
public int compareTo(@NotNull CookieKey cookieKey) {
250+
requireNonNull(cookieKey, "Parameter can't be null");
251+
248252
int result;
249-
if ((result = name.compareTo(o.name)) == 0) {
250-
result = path.compareTo(o.path);
253+
if ((result = name.compareTo(cookieKey.name)) == 0) {
254+
result = path.compareTo(cookieKey.path);
251255
}
252256
return result;
253257
}

client/src/main/java/org/asynchttpclient/exception/ChannelClosedException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919

2020
import static org.asynchttpclient.util.ThrowableUtil.unknownStackTrace;
2121

22+
/**
23+
* This exception is thrown when a channel is closed.
24+
*/
2225
public final class ChannelClosedException extends IOException {
26+
2327
private static final long serialVersionUID = -2528693697240456658L;
2428
public static final ChannelClosedException INSTANCE = unknownStackTrace(new ChannelClosedException(), ChannelClosedException.class, "INSTANCE");
2529

client/src/main/java/org/asynchttpclient/exception/PoolAlreadyClosedException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919

2020
import static org.asynchttpclient.util.ThrowableUtil.unknownStackTrace;
2121

22+
/**
23+
* This exception is thrown when a channel pool is already closed.
24+
*/
2225
public class PoolAlreadyClosedException extends IOException {
26+
2327
private static final long serialVersionUID = -3883404852005245296L;
2428
public static final PoolAlreadyClosedException INSTANCE = unknownStackTrace(new PoolAlreadyClosedException(), PoolAlreadyClosedException.class, "INSTANCE");
2529

client/src/main/java/org/asynchttpclient/exception/RemotelyClosedException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919

2020
import static org.asynchttpclient.util.ThrowableUtil.unknownStackTrace;
2121

22+
/**
23+
* This exception is thrown when a channel is closed by remote host.
24+
*/
2225
public final class RemotelyClosedException extends IOException {
26+
2327
private static final long serialVersionUID = 5634105738124356785L;
2428
public static final RemotelyClosedException INSTANCE = unknownStackTrace(new RemotelyClosedException(), RemotelyClosedException.class, "INSTANCE");
2529

client/src/main/java/org/asynchttpclient/exception/TooManyConnectionsException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
import java.io.IOException;
1919

20+
/**
21+
* This exception is thrown when too many connections are opened.
22+
*/
2023
public class TooManyConnectionsException extends IOException {
2124
private static final long serialVersionUID = 8645586459539317237L;
2225

0 commit comments

Comments
 (0)