Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bind support for DefaultPooledConnectionProvider #3314

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
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
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2023 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2020-2024 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@
import java.net.SocketAddress;
import java.time.Clock;
import java.time.Duration;
import java.util.Objects;
import java.util.Queue;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.BiPredicate;
Expand All @@ -27,6 +28,7 @@
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoop;
import io.netty.channel.unix.DomainSocketAddress;
import io.netty.resolver.AddressResolverGroup;
import io.netty.util.AttributeKey;
import org.reactivestreams.Publisher;
Expand Down Expand Up @@ -92,7 +94,7 @@ protected InstrumentedPool<PooledConnection> createPool(
TransportConfig config,
PoolFactory<PooledConnection> poolFactory,
SocketAddress remoteAddress,
AddressResolverGroup<?> resolverGroup) {
@Nullable AddressResolverGroup<?> resolverGroup) {
return new PooledConnectionAllocator(config, poolFactory, remoteAddress, resolverGroup).pool;
}

Expand All @@ -102,7 +104,7 @@ protected InstrumentedPool<PooledConnection> createPool(
TransportConfig config,
PoolFactory<PooledConnection> poolFactory,
SocketAddress remoteAddress,
AddressResolverGroup<?> resolverGroup) {
@Nullable AddressResolverGroup<?> resolverGroup) {
return new PooledConnectionAllocator(id, name, config, poolFactory, remoteAddress, resolverGroup).pool;
}

Expand Down Expand Up @@ -511,7 +513,7 @@ static final class PooledConnectionAllocator {
TransportConfig config,
PoolFactory<PooledConnection> provider,
SocketAddress remoteAddress,
AddressResolverGroup<?> resolver) {
@Nullable AddressResolverGroup<?> resolver) {
this(null, null, config, provider, remoteAddress, resolver);
}

Expand All @@ -521,7 +523,7 @@ static final class PooledConnectionAllocator {
TransportConfig config,
PoolFactory<PooledConnection> provider,
SocketAddress remoteAddress,
AddressResolverGroup<?> resolver) {
@Nullable AddressResolverGroup<?> resolver) {
this.config = config;
this.remoteAddress = remoteAddress;
this.resolver = resolver;
Expand All @@ -536,12 +538,20 @@ Publisher<PooledConnection> connectChannel() {
PooledConnectionInitializer initializer = new PooledConnectionInitializer(sink);
EventLoop callerEventLoop = sink.contextView().hasKey(CONTEXT_CALLER_EVENTLOOP) ?
sink.contextView().get(CONTEXT_CALLER_EVENTLOOP) : null;
if (callerEventLoop != null) {
TransportConnector.connect(config, remoteAddress, resolver, initializer, callerEventLoop, sink.contextView())
.subscribe(initializer);
if (resolver != null) {
if (callerEventLoop != null) {
TransportConnector.connect(config, remoteAddress, resolver, initializer, callerEventLoop, sink.contextView())
.subscribe(initializer);
}
else {
TransportConnector.connect(config, remoteAddress, resolver, initializer, sink.contextView()).subscribe(initializer);
}
}
else {
TransportConnector.connect(config, remoteAddress, resolver, initializer, sink.contextView()).subscribe(initializer);
Objects.requireNonNull(config.bindAddress(), "bindAddress");
SocketAddress local = Objects.requireNonNull(config.bindAddress().get(), "Bind Address supplier returned null");
TransportConnector.bind(config, initializer, local, remoteAddress instanceof DomainSocketAddress)
.subscribe(initializer);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ public final Mono<? extends Connection> acquire(
Objects.requireNonNull(config, "config");
Objects.requireNonNull(connectionObserver, "connectionObserver");
Objects.requireNonNull(remote, "remoteAddress");
Objects.requireNonNull(resolverGroup, "resolverGroup");
return Mono.create(sink -> {
SocketAddress remoteAddress = Objects.requireNonNull(remote.get(), "Remote Address supplier returned null");
PoolKey holder = new PoolKey(remoteAddress, config.channelHash());
Expand Down Expand Up @@ -307,14 +306,14 @@ protected abstract InstrumentedPool<T> createPool(
TransportConfig config,
PoolFactory<T> poolFactory,
SocketAddress remoteAddress,
AddressResolverGroup<?> resolverGroup);
@Nullable AddressResolverGroup<?> resolverGroup);

protected InstrumentedPool<T> createPool(
String id,
TransportConfig config,
PoolFactory<T> poolFactory,
SocketAddress remoteAddress,
AddressResolverGroup<?> resolverGroup) {
@Nullable AddressResolverGroup<?> resolverGroup) {
return createPool(config, poolFactory, remoteAddress, resolverGroup);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected InstrumentedPool<Connection> createPool(
TransportConfig config,
PooledConnectionProvider.PoolFactory<Connection> poolFactory,
SocketAddress remoteAddress,
AddressResolverGroup<?> resolverGroup) {
@Nullable AddressResolverGroup<?> resolverGroup) {
return new PooledConnectionAllocator(parent, config, poolFactory, remoteAddress, resolverGroup).pool;
}

Expand All @@ -145,7 +145,7 @@ protected InstrumentedPool<Connection> createPool(
TransportConfig config,
PooledConnectionProvider.PoolFactory<Connection> poolFactory,
SocketAddress remoteAddress,
AddressResolverGroup<?> resolverGroup) {
@Nullable AddressResolverGroup<?> resolverGroup) {
return new PooledConnectionAllocator(id, name(), parent, config, poolFactory, remoteAddress, resolverGroup).pool;
}

Expand Down Expand Up @@ -549,7 +549,7 @@ static final class PooledConnectionAllocator {
TransportConfig config,
PoolFactory<Connection> poolFactory,
SocketAddress remoteAddress,
AddressResolverGroup<?> resolver) {
@Nullable AddressResolverGroup<?> resolver) {
this(null, null, parent, config, poolFactory, remoteAddress, resolver);
}

Expand All @@ -560,7 +560,7 @@ static final class PooledConnectionAllocator {
TransportConfig config,
PoolFactory<Connection> poolFactory,
SocketAddress remoteAddress,
AddressResolverGroup<?> resolver) {
@Nullable AddressResolverGroup<?> resolver) {
this.parent = parent;
this.config = (HttpClientConfig) config;
this.remoteAddress = remoteAddress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ else if (_config.checkProtocol(HttpClientConfig.h3)) {
.then(_config.connectionObserver())
.then(new HttpIOHandlerObserver(sink, handler));

AddressResolverGroup<?> resolver = _config.resolverInternal();
AddressResolverGroup<?> resolver =
!_config.checkProtocol(HttpClientConfig.h3) ? _config.resolverInternal() : null;

_config.httpConnectionProvider()
.acquire(_config, observer, handler, resolver)
Expand Down
Loading