org.springframework.aop.target.CommonsPool2TargetSource Maven / Gradle / Ivy
/*
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.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 org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
* {@link org.springframework.aop.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, as of Spring 4.2.
*
* @author Rod Johnson
* @author Rob Harrop
* @author Juergen Hoeller
* @author Stephane Nicoll
* @author Kazuki Shimizu
* @since 4.2
* @see GenericObjectPool
* @see #createObjectPool()
* @see #setMaxSize
* @see #setMaxIdle
* @see #setMinIdle
* @see #setMaxWait
* @see #setTimeBetweenEvictionRunsMillis
* @see #setMinEvictableIdleTimeMillis
*/
@SuppressWarnings({"rawtypes", "unchecked", "serial"})
public class CommonsPool2TargetSource extends AbstractPoolingTargetSource implements PooledObjectFactory