Class ConnectionPool

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class ConnectionPool
    extends java.lang.Object
    implements java.lang.AutoCloseable
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected io.netty.resolver.AddressResolver<java.net.InetSocketAddress> addressResolver  
      protected java.util.concurrent.ConcurrentHashMap<java.net.InetSocketAddress,​java.util.concurrent.ConcurrentMap<java.lang.Integer,​java.util.concurrent.CompletableFuture<ClientCnx>>> pool  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      java.util.concurrent.CompletableFuture<ClientCnx> getConnection​(java.net.InetSocketAddress address)  
      java.util.concurrent.CompletableFuture<ClientCnx> getConnection​(java.net.InetSocketAddress logicalAddress, java.net.InetSocketAddress physicalAddress)
      Get a connection from the pool.
      java.util.Set<java.util.concurrent.CompletableFuture<ClientCnx>> getConnections()  
      void releaseConnection​(ClientCnx cnx)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • pool

        protected final java.util.concurrent.ConcurrentHashMap<java.net.InetSocketAddress,​java.util.concurrent.ConcurrentMap<java.lang.Integer,​java.util.concurrent.CompletableFuture<ClientCnx>>> pool
      • addressResolver

        protected final io.netty.resolver.AddressResolver<java.net.InetSocketAddress> addressResolver
    • Constructor Detail

      • 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,
                              java.util.function.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,
                              java.util.function.Supplier<ClientCnx> clientCnxSupplier,
                              java.util.Optional<io.netty.resolver.AddressResolver<java.net.InetSocketAddress>> addressResolver)
                       throws org.apache.pulsar.client.api.PulsarClientException
        Throws:
        org.apache.pulsar.client.api.PulsarClientException
    • Method Detail

      • getConnection

        public java.util.concurrent.CompletableFuture<ClientCnx> getConnection​(java.net.InetSocketAddress address)
      • getConnection

        public java.util.concurrent.CompletableFuture<ClientCnx> getConnection​(java.net.InetSocketAddress logicalAddress,
                                                                               java.net.InetSocketAddress physicalAddress)
        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 java.lang.Exception
        Specified by:
        close in interface java.lang.AutoCloseable
        Throws:
        java.lang.Exception
      • getConnections

        public java.util.Set<java.util.concurrent.CompletableFuture<ClientCnx>> getConnections()