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

client/src/main/java/org/asynchttpclient/exception/TooManyConnectionsPerHostException.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 to a remote host.
22+
*/
2023
public class TooManyConnectionsPerHostException extends IOException {
2124

2225
private static final long serialVersionUID = 5702859695179937503L;

client/src/main/java/org/asynchttpclient/netty/channel/ChannelState.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,23 @@
1616
package org.asynchttpclient.netty.channel;
1717

1818
public enum ChannelState {
19-
NEW, POOLED, RECONNECTED, CLOSED,
19+
/**
20+
* The channel is new
21+
*/
22+
NEW,
23+
24+
/**
25+
* The channel is open and pooled
26+
*/
27+
POOLED,
28+
29+
/**
30+
* The channel is reconnected
31+
*/
32+
RECONNECTED,
33+
34+
/**
35+
* The channel is closed
36+
*/
37+
CLOSED,
2038
}

client/src/main/java/org/asynchttpclient/netty/channel/DefaultChannelPool.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import java.util.function.Predicate;
4343
import java.util.stream.Collectors;
4444

45-
import static org.asynchttpclient.util.Assertions.assertNotNull;
45+
import static java.util.Objects.requireNonNull;
4646
import static org.asynchttpclient.util.DateUtils.unpreciseMillisTime;
4747

4848
/**
@@ -260,7 +260,7 @@ private static final class IdleChannel {
260260
private volatile int owned;
261261

262262
IdleChannel(Channel channel, long start) {
263-
this.channel = assertNotNull(channel, "channel");
263+
this.channel = requireNonNull(channel, "channel");
264264
this.start = start;
265265
}
266266

client/src/main/java/org/asynchttpclient/netty/handler/intercept/ResponseFiltersInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public boolean exitAfterProcessingFilters(Channel channel,
5050
try {
5151
fc = asyncFilter.filter(fc);
5252
// FIXME Is it worth protecting against this?
53-
// assertNotNull(fc, "filterContext");
53+
// requireNonNull(fc, "filterContext");
5454
} catch (FilterException fe) {
5555
requestSender.abort(channel, future, fe);
5656
}

client/src/main/java/org/asynchttpclient/netty/request/NettyRequestSender.java

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

6868
import static io.netty.handler.codec.http.HttpHeaderNames.EXPECT;
6969
import static java.util.Collections.singletonList;
70-
import static org.asynchttpclient.util.Assertions.assertNotNull;
70+
import static java.util.Objects.requireNonNull;
7171
import static org.asynchttpclient.util.AuthenticatorUtils.perConnectionAuthorizationHeader;
7272
import static org.asynchttpclient.util.AuthenticatorUtils.perConnectionProxyAuthorizationHeader;
7373
import static org.asynchttpclient.util.HttpConstants.Methods.CONNECT;
@@ -506,7 +506,7 @@ public boolean applyIoExceptionFiltersAndReplayRequest(NettyResponseFuture<?> fu
506506
for (IOExceptionFilter asyncFilter : config.getIoExceptionFilters()) {
507507
try {
508508
fc = asyncFilter.filter(fc);
509-
assertNotNull(fc, "filterContext");
509+
requireNonNull(fc, "filterContext");
510510
} catch (FilterException efe) {
511511
abort(channel, future, efe);
512512
}

client/src/main/java/org/asynchttpclient/netty/request/body/BodyChunkedInput.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import io.netty.handler.stream.ChunkedInput;
2222
import org.asynchttpclient.request.body.Body;
2323

24-
import static org.asynchttpclient.util.Assertions.assertNotNull;
24+
import static java.util.Objects.requireNonNull;
2525

2626
/**
2727
* Adapts a {@link Body} to Netty's {@link ChunkedInput}.
@@ -37,7 +37,7 @@ public class BodyChunkedInput implements ChunkedInput<ByteBuf> {
3737
private long progress;
3838

3939
BodyChunkedInput(Body body) {
40-
this.body = assertNotNull(body, "body");
40+
this.body = requireNonNull(body, "body");
4141
contentLength = body.getContentLength();
4242
if (contentLength <= 0) {
4343
chunkSize = DEFAULT_CHUNK_SIZE;

client/src/main/java/org/asynchttpclient/netty/request/body/BodyFileRegion.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.io.IOException;
2323
import java.nio.channels.WritableByteChannel;
2424

25-
import static org.asynchttpclient.util.Assertions.assertNotNull;
25+
import static java.util.Objects.requireNonNull;
2626
import static org.asynchttpclient.util.MiscUtils.closeSilently;
2727

2828
/**
@@ -34,7 +34,7 @@ class BodyFileRegion extends AbstractReferenceCounted implements FileRegion {
3434
private long transferred;
3535

3636
BodyFileRegion(RandomAccessBody body) {
37-
this.body = assertNotNull(body, "body");
37+
this.body = requireNonNull(body, "body");
3838
}
3939

4040
@Override

client/src/main/java/org/asynchttpclient/proxy/ProxyServer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import java.util.List;
2727
import java.util.function.Function;
2828

29-
import static org.asynchttpclient.util.Assertions.assertNotNull;
29+
import static java.util.Objects.requireNonNull;
3030
import static org.asynchttpclient.util.MiscUtils.isNonEmpty;
3131

3232
/**
@@ -100,7 +100,7 @@ public ProxyType getProxyType() {
100100
* Properties</a>
101101
*/
102102
public boolean isIgnoredForHost(String hostname) {
103-
assertNotNull(hostname, "hostname");
103+
requireNonNull(hostname, "hostname");
104104
if (isNonEmpty(nonProxyHosts)) {
105105
for (String nonProxyHost : nonProxyHosts) {
106106
if (matchNonProxyHost(hostname, nonProxyHost)) {

0 commit comments

Comments
 (0)