Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,12 @@ enum PerHostChannelPoolPartitioning implements ChannelPoolPartitioning {

@Override
public Object getPartitionKey(Uri uri, @Nullable String virtualHost, @Nullable ProxyServer proxyServer) {
if (proxyServer == null && virtualHost == null) {
return new PartitionKey(uri.getScheme(), uri.getHost(), uri.getExplicitPort());
}

String targetHostBaseUrl = uri.getBaseUrl();
if (proxyServer == null) {
if (virtualHost == null) {
return targetHostBaseUrl;
} else {
return new CompositePartitionKey(
targetHostBaseUrl,
virtualHost,
null,
0,
null);
}
} else {
if (proxyServer != null) {
return new CompositePartitionKey(
targetHostBaseUrl,
virtualHost,
Expand All @@ -55,6 +48,43 @@ public Object getPartitionKey(Uri uri, @Nullable String virtualHost, @Nullable P
proxyServer.getPort(),
proxyServer.getProxyType());
}

return new CompositePartitionKey(
targetHostBaseUrl,
virtualHost,
null,
0,
null);
}
}

class PartitionKey {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this record so clean? Also, a small unit test to validate equals and hashCode (even though record handles it?)

private final String scheme;
private final String host;
private final int port;

PartitionKey(String scheme, String host, int port) {
this.scheme = scheme;
this.host = host;
this.port = port;
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}

PartitionKey that = (PartitionKey) o;
return port == that.port && Objects.equals(scheme, that.scheme) && Objects.equals(host, that.host);
}

@Override
public int hashCode() {
int result = Objects.hashCode(scheme);
result = 31 * result + Objects.hashCode(host);
result = 31 * result + port;
return result;
}
}

Expand Down