Class ConnectionPool

java.lang.Object
org.apache.pulsar.client.impl.ConnectionPool
All Implemented Interfaces:
AutoCloseable

public class ConnectionPool extends Object implements AutoCloseable
  • Field Details

  • 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

      public CompletableFuture<ClientCnx> getConnection(InetSocketAddress address)
    • 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 tag
      physicalAddress - the real address where the TCP connection should be made
      Returns:
      a future that will produce the ClientCnx object
    • releaseConnection

      public void releaseConnection(ClientCnx cnx)
    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception
    • doMarkAndReleaseUselessConnections

      public void doMarkAndReleaseUselessConnections()
    • getConnections

      public Set<CompletableFuture<ClientCnx>> getConnections()