Interface KeyedPooledObjectFactory<K,V>

Type Parameters:
K - the key type - 键类型
V - the value type - 值类型
All Known Implementing Classes:
BaseKeyedPooledObjectFactory

public interface KeyedPooledObjectFactory<K,V>
KeyedPooledObjectFactory - Keyed Pooled Object Factory Interface KeyedPooledObjectFactory - 键控池化对象工厂接口

Factory interface for creating and managing keyed pooled objects. Each key can have different object configuration or type.

用于创建和管理键控池化对象的工厂接口。每个键可以有不同的对象配置或类型。

Features | 主要功能:

  • Key-based object creation - 基于键的对象创建
  • Per-key lifecycle management - 每个键的生命周期管理
  • Multi-tenant support - 多租户支持
  • Multi-datasource pooling - 多数据源池化

Usage Examples | 使用示例:

KeyedPooledObjectFactory<String, Connection> factory =
    new BaseKeyedPooledObjectFactory<>() {
        @Override
        protected Connection create(String dsName) {
            return getDataSource(dsName).getConnection();
        }
    };

Security | 安全性:

  • Thread-safe: Implementation dependent - 线程安全: 取决于实现
  • Null-safe: No - 空值安全: 否
Since:
JDK 25, opencode-base-pool V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • makeObject

      PooledObject<V> makeObject(K key) throws OpenPoolException
      Creates a new pooled object for the given key. 为给定的键创建新的池化对象。
      Parameters:
      key - the key - 键
      Returns:
      the new pooled object - 新的池化对象
      Throws:
      OpenPoolException - if creation fails - 如果创建失败
    • destroyObject

      void destroyObject(K key, PooledObject<V> obj) throws OpenPoolException
      Destroys a pooled object for the given key. 销毁给定键的池化对象。
      Parameters:
      key - the key - 键
      obj - the object to destroy - 要销毁的对象
      Throws:
      OpenPoolException - if destruction fails - 如果销毁失败
    • validateObject

      boolean validateObject(K key, PooledObject<V> obj)
      Validates a pooled object for the given key. 验证给定键的池化对象。
      Parameters:
      key - the key - 键
      obj - the object to validate - 要验证的对象
      Returns:
      true if valid - 有效返回true
    • activateObject

      void activateObject(K key, PooledObject<V> obj) throws OpenPoolException
      Activates a pooled object for the given key. 激活给定键的池化对象。
      Parameters:
      key - the key - 键
      obj - the object to activate - 要激活的对象
      Throws:
      OpenPoolException - if activation fails - 如果激活失败
    • passivateObject

      void passivateObject(K key, PooledObject<V> obj) throws OpenPoolException
      Passivates a pooled object for the given key. 钝化给定键的池化对象。
      Parameters:
      key - the key - 键
      obj - the object to passivate - 要钝化的对象
      Throws:
      OpenPoolException - if passivation fails - 如果钝化失败