org.springframework.ldap.pool2.factory.PooledContextSource Maven / Gradle / Ivy
/*
* Copyright 2005-2015 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.ldap.pool2.factory;
import java.util.Collection;
import javax.naming.directory.DirContext;
import javax.naming.ldap.LdapContext;
import org.apache.commons.pool2.impl.GenericKeyedObjectPool;
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.ldap.core.ContextSource;
import org.springframework.ldap.core.support.DelegatingBaseLdapPathContextSourceSupport;
import org.springframework.ldap.pool2.DelegatingDirContext;
import org.springframework.ldap.pool2.DelegatingLdapContext;
import org.springframework.ldap.pool2.DirContextType;
import org.springframework.ldap.pool2.validation.DirContextValidator;
/**
* A {@link ContextSource} implementation that wraps an object pool and another
* {@link ContextSource}. {@link DirContext}s are retrieved from the pool which maintains
* them.
*
* NOTE: This implementation is based on apache commons-pool2.
*
* Configuration:
*
*
* Property
* Description
* Required
* Default
*
*
* contextSource
* The {@link ContextSource} to get {@link DirContext}s from for adding
* to the pool.
* Yes
* null
*
*
* dirContextValidator
* The
* {@link org.springframework.ldap.pool2.validation.DirContextValidator} to use for
* validating {@link DirContext}s. Required if any of the test/validate options are
* enabled.
* No
* null
*
*
* poolConfig
* The {@link PoolConfig} to configure the pool.
* No
* null
*
*
*
* @author Eric Dalquist
* @author Anindya Chatterjee
* @since 2.0
*/
public class PooledContextSource extends DelegatingBaseLdapPathContextSourceSupport
implements ContextSource, DisposableBean {
/**
* The logger for this class and sub-classes
*/
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
protected final GenericKeyedObjectPool