Class ClientPool<C,T>

java.lang.Object
io.milvus.pool.ClientPool<C,T>
Direct Known Subclasses:
MilvusClientV1Pool, MilvusClientV2Pool

public class ClientPool<C,T> extends Object
  • Field Details

    • clientPool

      protected org.apache.commons.pool2.impl.GenericKeyedObjectPool<String,T> clientPool
    • config

      protected PoolConfig config
    • clientFactory

      protected PoolClientFactory<C,T> clientFactory
  • Constructor Details

  • Method Details

    • getClient

      public T getClient(String key)
      Get a client object which is idle from the pool. Once the client is hold by the caller, it will be marked as active state and cannot be fetched by other caller. If the number of clients hits the MaxTotalPerKey value, this method will be blocked for MaxBlockWaitDuration. If no idle client available after MaxBlockWaitDuration, this method will return a null object to caller.
      Parameters:
      key - the key of a group where the client belong
      Returns:
      MilvusClient or MilvusClientV2
    • returnClient

      public void returnClient(String key, T grpcClient)
      Return a client object. Once a client is returned, it becomes idle state and wait the next caller. The caller should ensure the client is returned. Otherwise, the client will keep in active state and cannot be used by the next caller. Throw exceptions if the key doesn't exist or the client is not belong to this key group.
      Parameters:
      key - the key of a group where the client belong
      grpcClient - the client object to return
    • close

      public void close()
      Release/disconnect all clients of all key groups, close the pool.
    • clear

      public void clear()
      Release/disconnect idle clients of all key groups.
    • clear

      public void clear(String key)
      Release/disconnect idle clients of a key group.
      Parameters:
      key - the key of a group
    • getIdleClientNumber

      public int getIdleClientNumber(String key)
      Return the number of idle clients of a key group
      Parameters:
      key - the key of a group
    • getActiveClientNumber

      public int getActiveClientNumber(String key)
      Return the number of active clients of a key group
      Parameters:
      key - the key of a group
    • getTotalIdleClientNumber

      public int getTotalIdleClientNumber()
      Return the number of idle clients of all key group
    • getTotalActiveClientNumber

      public int getTotalActiveClientNumber()
      Return the number of active clients of all key group