Package org.apache.pulsar.client.impl
Class ConnectionPool
java.lang.Object
org.apache.pulsar.client.impl.ConnectionPool
- All Implemented Interfaces:
AutoCloseable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final io.netty.resolver.AddressResolver<InetSocketAddress>
static final int
protected final ConcurrentHashMap<InetSocketAddress,
ConcurrentMap<Integer, CompletableFuture<ClientCnx>>> -
Constructor Summary
ConstructorsConstructorDescriptionConnectionPool
(ClientConfigurationData conf, io.netty.channel.EventLoopGroup eventLoopGroup) ConnectionPool
(ClientConfigurationData conf, io.netty.channel.EventLoopGroup eventLoopGroup, Supplier<ClientCnx> clientCnxSupplier) ConnectionPool
(ClientConfigurationData conf, io.netty.channel.EventLoopGroup eventLoopGroup, Supplier<ClientCnx> clientCnxSupplier, Optional<io.netty.resolver.AddressResolver<InetSocketAddress>> addressResolver) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
int
getConnection
(InetSocketAddress address) getConnection
(InetSocketAddress logicalAddress, InetSocketAddress physicalAddress, int randomKey) Get a connection from the pool.void
-
Field Details
-
IDLE_DETECTION_INTERVAL_SECONDS_MIN
public static final int IDLE_DETECTION_INTERVAL_SECONDS_MIN- See Also:
-
pool
protected final ConcurrentHashMap<InetSocketAddress,ConcurrentMap<Integer, poolCompletableFuture<ClientCnx>>> -
addressResolver
-
-
Constructor Details
-
ConnectionPool
public ConnectionPool(ClientConfigurationData conf, io.netty.channel.EventLoopGroup eventLoopGroup) throws org.apache.pulsar.client.api.PulsarClientException - Throws:
org.apache.pulsar.client.api.PulsarClientException
-
ConnectionPool
public ConnectionPool(ClientConfigurationData conf, io.netty.channel.EventLoopGroup eventLoopGroup, Supplier<ClientCnx> clientCnxSupplier) throws org.apache.pulsar.client.api.PulsarClientException - Throws:
org.apache.pulsar.client.api.PulsarClientException
-
ConnectionPool
public ConnectionPool(ClientConfigurationData conf, io.netty.channel.EventLoopGroup eventLoopGroup, Supplier<ClientCnx> clientCnxSupplier, Optional<io.netty.resolver.AddressResolver<InetSocketAddress>> addressResolver) throws org.apache.pulsar.client.api.PulsarClientException - Throws:
org.apache.pulsar.client.api.PulsarClientException
-
-
Method Details
-
genRandomKeyToSelectCon
public int genRandomKeyToSelectCon() -
getConnection
-
getConnection
public CompletableFuture<ClientCnx> getConnection(InetSocketAddress logicalAddress, InetSocketAddress physicalAddress, int randomKey) Get a connection from the pool.The connection can either be created or be coming from the pool itself.
When specifying multiple addresses, the logicalAddress is used as a tag for the broker, while the physicalAddress is where the connection is actually happening.
These two addresses can be different when the client is forced to connect through a proxy layer. Essentially, the pool is using the logical address as a way to decide whether to reuse a particular connection.
- Parameters:
logicalAddress
- the address to use as the broker tagphysicalAddress
- the real address where the TCP connection should be made- Returns:
- a future that will produce the ClientCnx object
-
releaseConnection
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-
doMarkAndReleaseUselessConnections
public void doMarkAndReleaseUselessConnections() -
getConnections
-