Skip to content

Commit

Permalink
JavaDoc Improvement (AsyncHttpClient#1905)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperxpro committed Sep 6, 2023
1 parent df54ba9 commit 37cadf3
Show file tree
Hide file tree
Showing 26 changed files with 132 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* Simple {@link AsyncHandler} of type {@link Response}
*/
public class AsyncCompletionHandlerBase extends AsyncCompletionHandler<Response> {

@Override
public @Nullable Response onCompleted(@Nullable Response response) throws Exception {
return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Predicate;

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

Request request = fc.getRequest();
Expand Down
4 changes: 2 additions & 2 deletions client/src/main/java/org/asynchttpclient/Realm.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.asynchttpclient.util.Assertions.assertNotNull;
import static java.util.Objects.requireNonNull;
import static org.asynchttpclient.util.HttpConstants.Methods.GET;
import static org.asynchttpclient.util.MessageDigestUtils.pooledMd5MessageDigest;
import static org.asynchttpclient.util.MiscUtils.isNonEmpty;
Expand Down Expand Up @@ -92,7 +92,7 @@ private Realm(@Nullable AuthScheme scheme,
@Nullable Map<String, String> customLoginConfig,
@Nullable String loginContextName) {

this.scheme = assertNotNull(scheme, "scheme");
this.scheme = requireNonNull(scheme, "scheme");
this.principal = principal;
this.password = password;
this.realmName = realmName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,69 @@
import java.util.Map;
import java.util.function.Predicate;

/**
* A {@link ChannelPool} implementation that doesn't pool anything.
*/
public enum NoopChannelPool implements ChannelPool {

INSTANCE;

/**
*
* @return always false since this is a {@link NoopChannelPool}
*/
@Override
public boolean offer(Channel channel, Object partitionKey) {
return false;
}

/**
*
* @return always null since this is a {@link NoopChannelPool}
*/
@Override
public @Nullable Channel poll(Object partitionKey) {
return null;
}

/**
*
* @return always false since this is a {@link NoopChannelPool}
*/
@Override
public boolean removeAll(Channel channel) {
return false;
}

/**
*
* @return always true since this is a {@link NoopChannelPool}
*/
@Override
public boolean isOpen() {
return true;
}

/**
*
* Does nothing since this is a {@link NoopChannelPool}
*/
@Override
public void destroy() {
}

/**
*
* Does nothing since this is a {@link NoopChannelPool}
*/
@Override
public void flushPartitions(Predicate<Object> predicate) {
}

/**
*
* @return always {@link Collections#emptyMap()} since this is a {@link NoopChannelPool}
*/
@Override
public Map<String, Long> getIdleChannelCountPerHost() {
return Collections.emptyMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,29 @@ public void reload() {
propsCache.clear();
}

/**
* Parse a property file.
*
* @param file the file to parse
* @param required if true, the file must be present
* @return the parsed properties
* @throws RuntimeException if the file is required and not present or if the file can't be parsed
*/
private Properties parsePropertiesFile(String file, boolean required) {
Properties props = new Properties();

InputStream is = getClass().getResourceAsStream(file);
if (is != null) {
try {
props.load(is);
} catch (IOException e) {
throw new IllegalArgumentException("Can't parse config file " + file, e);
try (InputStream is = getClass().getResourceAsStream(file)) {
if (is != null) {
try {
props.load(is);
} catch (IOException e) {
throw new IllegalArgumentException("Can't parse config file " + file, e);
}
} else if (required) {
throw new IllegalArgumentException("Can't locate config file " + file);
}
} else if (required) {
throw new IllegalArgumentException("Can't locate config file " + file);
} catch (IOException e) {
throw new RuntimeException(e);
}

return props;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import io.netty.handler.codec.http.cookie.Cookie;
import org.asynchttpclient.uri.Uri;
import org.asynchttpclient.util.Assertions;
import org.asynchttpclient.util.MiscUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -34,6 +33,8 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static java.util.Objects.requireNonNull;

public final class ThreadSafeCookieStore implements CookieStore {

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


@Override
public int incrementAndGet() {
return counter.incrementAndGet();
Expand Down Expand Up @@ -226,8 +226,11 @@ private List<Cookie> getStoredCookies(String domain, String path, boolean secure

private void removeExpired() {
final boolean[] removed = {false};
cookieJar.values().forEach(cookieMap -> removed[0] |= cookieMap.entrySet().removeIf(
v -> hasCookieExpired(v.getValue().cookie, v.getValue().createdAt)));

cookieJar.values()
.forEach(cookieMap -> removed[0] |= cookieMap.entrySet()
.removeIf(v -> hasCookieExpired(v.getValue().cookie, v.getValue().createdAt)));

if (removed[0]) {
cookieJar.entrySet().removeIf(entry -> entry.getValue() == null || entry.getValue().isEmpty());
}
Expand All @@ -243,11 +246,12 @@ private static class CookieKey implements Comparable<CookieKey> {
}

@Override
public int compareTo(@NotNull CookieKey o) {
Assertions.assertNotNull(o, "Parameter can't be null");
public int compareTo(@NotNull CookieKey cookieKey) {
requireNonNull(cookieKey, "Parameter can't be null");

int result;
if ((result = name.compareTo(o.name)) == 0) {
result = path.compareTo(o.path);
if ((result = name.compareTo(cookieKey.name)) == 0) {
result = path.compareTo(cookieKey.path);
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@

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

/**
* This exception is thrown when a channel is closed.
*/
public final class ChannelClosedException extends IOException {

private static final long serialVersionUID = -2528693697240456658L;
public static final ChannelClosedException INSTANCE = unknownStackTrace(new ChannelClosedException(), ChannelClosedException.class, "INSTANCE");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@

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

/**
* This exception is thrown when a channel pool is already closed.
*/
public class PoolAlreadyClosedException extends IOException {

private static final long serialVersionUID = -3883404852005245296L;
public static final PoolAlreadyClosedException INSTANCE = unknownStackTrace(new PoolAlreadyClosedException(), PoolAlreadyClosedException.class, "INSTANCE");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@

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

/**
* This exception is thrown when a channel is closed by remote host.
*/
public final class RemotelyClosedException extends IOException {

private static final long serialVersionUID = 5634105738124356785L;
public static final RemotelyClosedException INSTANCE = unknownStackTrace(new RemotelyClosedException(), RemotelyClosedException.class, "INSTANCE");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

import java.io.IOException;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

import java.io.IOException;

/**
* This exception is thrown when too many connections are opened to a remote host.
*/
public class TooManyConnectionsPerHostException extends IOException {

private static final long serialVersionUID = 5702859695179937503L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,23 @@
package org.asynchttpclient.netty.channel;

public enum ChannelState {
NEW, POOLED, RECONNECTED, CLOSED,
/**
* The channel is new
*/
NEW,

/**
* The channel is open and pooled
*/
POOLED,

/**
* The channel is reconnected
*/
RECONNECTED,

/**
* The channel is closed
*/
CLOSED,
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static org.asynchttpclient.util.Assertions.assertNotNull;
import static java.util.Objects.requireNonNull;
import static org.asynchttpclient.util.DateUtils.unpreciseMillisTime;

/**
Expand Down Expand Up @@ -260,7 +260,7 @@ private static final class IdleChannel {
private volatile int owned;

IdleChannel(Channel channel, long start) {
this.channel = assertNotNull(channel, "channel");
this.channel = requireNonNull(channel, "channel");
this.start = start;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public boolean exitAfterProcessingFilters(Channel channel,
try {
fc = asyncFilter.filter(fc);
// FIXME Is it worth protecting against this?
// assertNotNull(fc, "filterContext");
// requireNonNull(fc, "filterContext");
} catch (FilterException fe) {
requestSender.abort(channel, future, fe);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

import static io.netty.handler.codec.http.HttpHeaderNames.EXPECT;
import static java.util.Collections.singletonList;
import static org.asynchttpclient.util.Assertions.assertNotNull;
import static java.util.Objects.requireNonNull;
import static org.asynchttpclient.util.AuthenticatorUtils.perConnectionAuthorizationHeader;
import static org.asynchttpclient.util.AuthenticatorUtils.perConnectionProxyAuthorizationHeader;
import static org.asynchttpclient.util.HttpConstants.Methods.CONNECT;
Expand Down Expand Up @@ -506,7 +506,7 @@ public boolean applyIoExceptionFiltersAndReplayRequest(NettyResponseFuture<?> fu
for (IOExceptionFilter asyncFilter : config.getIoExceptionFilters()) {
try {
fc = asyncFilter.filter(fc);
assertNotNull(fc, "filterContext");
requireNonNull(fc, "filterContext");
} catch (FilterException efe) {
abort(channel, future, efe);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import io.netty.handler.stream.ChunkedInput;
import org.asynchttpclient.request.body.Body;

import static org.asynchttpclient.util.Assertions.assertNotNull;
import static java.util.Objects.requireNonNull;

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

BodyChunkedInput(Body body) {
this.body = assertNotNull(body, "body");
this.body = requireNonNull(body, "body");
contentLength = body.getContentLength();
if (contentLength <= 0) {
chunkSize = DEFAULT_CHUNK_SIZE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.io.IOException;
import java.nio.channels.WritableByteChannel;

import static org.asynchttpclient.util.Assertions.assertNotNull;
import static java.util.Objects.requireNonNull;
import static org.asynchttpclient.util.MiscUtils.closeSilently;

/**
Expand All @@ -34,7 +34,7 @@ class BodyFileRegion extends AbstractReferenceCounted implements FileRegion {
private long transferred;

BodyFileRegion(RandomAccessBody body) {
this.body = assertNotNull(body, "body");
this.body = requireNonNull(body, "body");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.List;
import java.util.function.Function;

import static org.asynchttpclient.util.Assertions.assertNotNull;
import static java.util.Objects.requireNonNull;
import static org.asynchttpclient.util.MiscUtils.isNonEmpty;

/**
Expand Down Expand Up @@ -100,7 +100,7 @@ public ProxyType getProxyType() {
* Properties</a>
*/
public boolean isIgnoredForHost(String hostname) {
assertNotNull(hostname, "hostname");
requireNonNull(hostname, "hostname");
if (isNonEmpty(nonProxyHosts)) {
for (String nonProxyHost : nonProxyHosts) {
if (matchNonProxyHost(hostname, nonProxyHost)) {
Expand Down
Loading

0 comments on commit 37cadf3

Please sign in to comment.