Class ObjectWrapper<T>

  • Type Parameters:
    T - The type of wrapped objects.
    All Implemented Interfaces:
    AutoCloseable

    public final class ObjectWrapper<T>
    extends PoolableObject<None>
    implements AutoCloseable
    A poolable object that wraps a single value. Instances will always be considered valid and have no resources to release. This class implements AutoCloseable, which allows instances to be used in try-with-resources blocks; when an instance is closed it is returned to the pool.
    Author:
    Rob Spoor
    • Constructor Detail

      • ObjectWrapper

        public ObjectWrapper​(T value)
        Creates a new object wrapper.
        Parameters:
        value - The value to wrap.
    • Method Detail

      • value

        public T value()
        The wrapped value.
        Returns:
        The wrapped value.
      • newPool

        public static <T> Pool<ObjectWrapper<T>,​None> newPool​(PoolConfig config,
                                                                    Supplier<T> supplier,
                                                                    PoolLogger logger)
        Creates a new pool of ObjectWrapper instances.
        Type Parameters:
        T - The type of objects wrapped by ObjectWrapper instances in the pool.
        Parameters:
        config - The configuration to use.
        supplier - A supplier to serve as factory for wrapped objects.
        logger - The logger to use to log events triggered by the pool or pooled objects.
        Returns:
        The created pool.
        Throws:
        NullPointerException - If the given configuration, supplier or logger is null.