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 intprotected final ConcurrentMap<org.apache.pulsar.client.impl.ConnectionPool.Key, CompletableFuture<ClientCnx>> -
Constructor Summary
ConstructorsConstructorDescriptionConnectionPool(InstrumentProvider instrumentProvider, ClientConfigurationData conf, io.netty.channel.EventLoopGroup eventLoopGroup, ScheduledExecutorService scheduledExecutorService) ConnectionPool(InstrumentProvider instrumentProvider, ClientConfigurationData conf, io.netty.channel.EventLoopGroup eventLoopGroup, Supplier<ClientCnx> clientCnxSupplier, ScheduledExecutorService scheduledExecutorService) ConnectionPool(InstrumentProvider instrumentProvider, ClientConfigurationData conf, io.netty.channel.EventLoopGroup eventLoopGroup, Supplier<ClientCnx> clientCnxSupplier, Optional<io.netty.resolver.AddressResolver<InetSocketAddress>> addressResolver, ScheduledExecutorService scheduledExecutorService) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidintgetConnection(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 ConcurrentMap<org.apache.pulsar.client.impl.ConnectionPool.Key,CompletableFuture<ClientCnx>> pool -
addressResolver
-
-
Constructor Details
-
ConnectionPool
public ConnectionPool(InstrumentProvider instrumentProvider, ClientConfigurationData conf, io.netty.channel.EventLoopGroup eventLoopGroup, ScheduledExecutorService scheduledExecutorService) throws PulsarClientException - Throws:
PulsarClientException
-
ConnectionPool
public ConnectionPool(InstrumentProvider instrumentProvider, ClientConfigurationData conf, io.netty.channel.EventLoopGroup eventLoopGroup, Supplier<ClientCnx> clientCnxSupplier, ScheduledExecutorService scheduledExecutorService) throws PulsarClientException - Throws:
PulsarClientException
-
ConnectionPool
public ConnectionPool(InstrumentProvider instrumentProvider, ClientConfigurationData conf, io.netty.channel.EventLoopGroup eventLoopGroup, Supplier<ClientCnx> clientCnxSupplier, Optional<io.netty.resolver.AddressResolver<InetSocketAddress>> addressResolver, ScheduledExecutorService scheduledExecutorService) throws PulsarClientException - Throws:
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:
closein interfaceAutoCloseable- Throws:
Exception
-
doMarkAndReleaseUselessConnections
public void doMarkAndReleaseUselessConnections() -
getConnections
-