
cn.taketoday.aop.target.CommonsPool2TargetSource Maven / Gradle / Ivy
/*
* Original Author -> Harry Yang ([email protected]) https://taketoday.cn
* Copyright © TODAY & 2017 - 2021 All Rights Reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see [http://www.gnu.org/licenses/]
*/
package cn.taketoday.aop.target;
import org.apache.commons.pool2.ObjectPool;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.PooledObjectFactory;
import org.apache.commons.pool2.impl.DefaultPooledObject;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import cn.taketoday.aop.TargetSource;
import cn.taketoday.lang.Assert;
import cn.taketoday.lang.Nullable;
/**
* {@link TargetSource} implementation that holds objects in a
* configurable Apache Commons2 Pool.
*
* By default, an instance of {@code GenericObjectPool} is created.
* Subclasses may change the type of {@code ObjectPool} used by
* overriding the {@code createObjectPool()} method.
*
*
Provides many configuration properties mirroring those of the Commons Pool
* {@code GenericObjectPool} class; these properties are passed to the
* {@code GenericObjectPool} during construction. If creating a subclass of this
* class to change the {@code ObjectPool} implementation type, pass in the values
* of configuration properties that are relevant to your chosen implementation.
*
*
The {@code testOnBorrow}, {@code testOnReturn} and {@code testWhileIdle}
* properties are explicitly not mirrored because the implementation of
* {@code PoolableObjectFactory} used by this class does not implement
* meaningful validation. All exposed Commons Pool properties use the
* corresponding Commons Pool defaults.
*
*
Compatible with Apache Commons Pool 2.4
*
* @author Rod Johnson
* @author Rob Harrop
* @author Juergen Hoeller
* @author Stephane Nicoll
* @author Kazuki Shimizu
* @author Harry Yang
* @see GenericObjectPool
* @see #createObjectPool()
* @see #setMaxSize
* @see #setMaxIdle
* @see #setMinIdle
* @see #setMaxWait
* @see #setTimeBetweenEvictionRunsMillis
* @see #setMinEvictableIdleTimeMillis
* @since 4.0 2021/12/13 22:33
*/
@SuppressWarnings({ "rawtypes", "unchecked", "deprecation" })
public class CommonsPool2TargetSource
extends AbstractPoolingTargetSource implements PooledObjectFactory