Class PoolingContextSource
- java.lang.Object
-
- org.springframework.ldap.core.support.DelegatingBaseLdapPathContextSourceSupport
-
- org.springframework.ldap.pool.factory.PoolingContextSource
-
- All Implemented Interfaces:
org.springframework.beans.factory.DisposableBean,ContextSource,BaseLdapPathSource
- Direct Known Subclasses:
MutablePoolingContextSource
public class PoolingContextSource extends DelegatingBaseLdapPathContextSourceSupport implements ContextSource, org.springframework.beans.factory.DisposableBean
AContextSourceimplementation that wraps an object pool and anotherContextSource.DirContexts are retrieved from the pool which maintains them.
Configuration:Property Description Required Default contextSource The ContextSourceto getDirContexts from for adding to the pool.Yes null dirContextValidator The DirContextValidatorto use for validatingDirContexts. Required if any of the test/validate options are enabled.No null minIdle GenericKeyedObjectPool.setMinIdle(int)No 0 maxIdle GenericKeyedObjectPool.setMaxIdle(int)No 8 maxActive GenericKeyedObjectPool.setMaxActive(int)No 8 maxTotal GenericKeyedObjectPool.setMaxTotal(int)No -1 maxWait GenericKeyedObjectPool.setMaxWait(long)No -1L whenExhaustedAction GenericKeyedObjectPool.setWhenExhaustedAction(byte)No GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCKtestOnBorrow GenericKeyedObjectPool.setTestOnBorrow(boolean)No false testOnReturn GenericKeyedObjectPool.setTestOnReturn(boolean)No false testWhileIdle GenericKeyedObjectPool.setTestWhileIdle(boolean)No false timeBetweenEvictionRunsMillis GenericKeyedObjectPool.setTimeBetweenEvictionRunsMillis(long)No -1L minEvictableIdleTimeMillis GenericKeyedObjectPool.setMinEvictableIdleTimeMillis(long)No 1000L * 60L * 30L numTestsPerEvictionRun GenericKeyedObjectPool.setNumTestsPerEvictionRun(int)No 3
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.commons.pool.impl.GenericKeyedObjectPoolkeyedObjectPoolprotected org.slf4j.LoggerloggerThe logger for this class and sub-classes
-
Constructor Summary
Constructors Constructor Description PoolingContextSource()Creates a new pooling context source, setting up the DirContext object factory and generic keyed object pool.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddestroy()javax.naming.directory.DirContextgetContext(java.lang.String principal, java.lang.String credentials)Gets aDirContextinstance authenticated using the supplied principal and credentials.protected javax.naming.directory.DirContextgetContext(DirContextType dirContextType)Gets a DirContext of the specified type from the keyed object pool.ContextSourcegetContextSource()DirContextValidatorgetDirContextValidator()intgetMaxActive()intgetMaxIdle()intgetMaxTotal()longgetMaxWait()longgetMinEvictableIdleTimeMillis()intgetMinIdle()intgetNumActive()intgetNumIdle()intgetNumTestsPerEvictionRun()javax.naming.directory.DirContextgetReadOnlyContext()Gets a read-onlyDirContext.javax.naming.directory.DirContextgetReadWriteContext()Gets a read-writeDirContextinstance.protected ContextSourcegetTarget()Get the target ContextSource.booleangetTestOnBorrow()booleangetTestOnReturn()booleangetTestWhileIdle()longgetTimeBetweenEvictionRunsMillis()bytegetWhenExhaustedAction()voidsetContextSource(ContextSource contextSource)voidsetDirContextValidator(DirContextValidator dirContextValidator)voidsetMaxActive(int maxActive)voidsetMaxIdle(int maxIdle)voidsetMaxTotal(int maxTotal)voidsetMaxWait(long maxWait)voidsetMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)voidsetMinIdle(int poolSize)voidsetNonTransientExceptions(java.util.Collection<java.lang.Class<? extends java.lang.Throwable>> nonTransientExceptions)Configure the exception classes that are to be interpreted as no-transient with regards to eager context invalidation.voidsetNumTestsPerEvictionRun(int numTestsPerEvictionRun)voidsetTestOnBorrow(boolean testOnBorrow)voidsetTestOnReturn(boolean testOnReturn)voidsetTestWhileIdle(boolean testWhileIdle)voidsetTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)voidsetWhenExhaustedAction(byte whenExhaustedAction)-
Methods inherited from class org.springframework.ldap.core.support.DelegatingBaseLdapPathContextSourceSupport
getBaseLdapName, getBaseLdapPath, getBaseLdapPathAsString
-
-
-
-
Method Detail
-
getMaxActive
public int getMaxActive()
- See Also:
GenericKeyedObjectPool.getMaxActive()
-
getMaxIdle
public int getMaxIdle()
- See Also:
GenericKeyedObjectPool.getMaxIdle()
-
getMaxTotal
public int getMaxTotal()
- See Also:
GenericKeyedObjectPool.getMaxTotal()
-
getMaxWait
public long getMaxWait()
- See Also:
GenericKeyedObjectPool.getMaxWait()
-
getMinEvictableIdleTimeMillis
public long getMinEvictableIdleTimeMillis()
- See Also:
GenericKeyedObjectPool.getMinEvictableIdleTimeMillis()
-
getMinIdle
public int getMinIdle()
- See Also:
GenericKeyedObjectPool.getMinIdle()
-
getNumActive
public int getNumActive()
- See Also:
GenericKeyedObjectPool.getNumActive()
-
getNumIdle
public int getNumIdle()
- See Also:
GenericKeyedObjectPool.getNumIdle()
-
getNumTestsPerEvictionRun
public int getNumTestsPerEvictionRun()
- See Also:
GenericKeyedObjectPool.getNumTestsPerEvictionRun()
-
getTestOnBorrow
public boolean getTestOnBorrow()
- See Also:
GenericKeyedObjectPool.getTestOnBorrow()
-
getTestOnReturn
public boolean getTestOnReturn()
- See Also:
GenericKeyedObjectPool.getTestOnReturn()
-
getTestWhileIdle
public boolean getTestWhileIdle()
- See Also:
GenericKeyedObjectPool.getTestWhileIdle()
-
getTimeBetweenEvictionRunsMillis
public long getTimeBetweenEvictionRunsMillis()
- See Also:
GenericKeyedObjectPool.getTimeBetweenEvictionRunsMillis()
-
getWhenExhaustedAction
public byte getWhenExhaustedAction()
- See Also:
GenericKeyedObjectPool.getWhenExhaustedAction()
-
setMaxActive
public void setMaxActive(int maxActive)
- See Also:
GenericKeyedObjectPool.setMaxActive(int)
-
setMaxIdle
public void setMaxIdle(int maxIdle)
- See Also:
GenericKeyedObjectPool.setMaxIdle(int)
-
setMaxTotal
public void setMaxTotal(int maxTotal)
- See Also:
GenericKeyedObjectPool.setMaxTotal(int)
-
setMaxWait
public void setMaxWait(long maxWait)
- See Also:
GenericKeyedObjectPool.setMaxWait(long)
-
setMinEvictableIdleTimeMillis
public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)
- See Also:
GenericKeyedObjectPool.setMinEvictableIdleTimeMillis(long)
-
setMinIdle
public void setMinIdle(int poolSize)
- See Also:
GenericKeyedObjectPool.setMinIdle(int)
-
setNumTestsPerEvictionRun
public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun)
- See Also:
GenericKeyedObjectPool.setNumTestsPerEvictionRun(int)
-
setTestOnBorrow
public void setTestOnBorrow(boolean testOnBorrow)
- See Also:
GenericKeyedObjectPool.setTestOnBorrow(boolean)
-
setTestOnReturn
public void setTestOnReturn(boolean testOnReturn)
- See Also:
GenericKeyedObjectPool.setTestOnReturn(boolean)
-
setTestWhileIdle
public void setTestWhileIdle(boolean testWhileIdle)
- See Also:
GenericKeyedObjectPool.setTestWhileIdle(boolean)
-
setTimeBetweenEvictionRunsMillis
public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)
- See Also:
GenericKeyedObjectPool.setTimeBetweenEvictionRunsMillis(long)
-
setWhenExhaustedAction
public void setWhenExhaustedAction(byte whenExhaustedAction)
- See Also:
GenericKeyedObjectPool.setWhenExhaustedAction(byte)
-
getContextSource
public ContextSource getContextSource()
- Returns:
- the contextSource
-
getDirContextValidator
public DirContextValidator getDirContextValidator()
- Returns:
- the dirContextValidator
-
setContextSource
public void setContextSource(ContextSource contextSource)
- Parameters:
contextSource- the contextSource to set Required
-
setDirContextValidator
public void setDirContextValidator(DirContextValidator dirContextValidator)
- Parameters:
dirContextValidator- the dirContextValidator to set Required
-
setNonTransientExceptions
public void setNonTransientExceptions(java.util.Collection<java.lang.Class<? extends java.lang.Throwable>> nonTransientExceptions)
Configure the exception classes that are to be interpreted as no-transient with regards to eager context invalidation. If one of the configured exceptions (or subclasses of them) is thrown by any method on a pooled DirContext, that instance will immediately be marked as invalid without any additional testing (i.e. testOnReturn). This allows for more efficient management of dead connections. Default isCommunicationException.- Parameters:
nonTransientExceptions- the exception classes that should be interpreted as non-transient with regards to eager invalidation.- Since:
- 2.0
-
destroy
public void destroy() throws java.lang.Exception- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean- Throws:
java.lang.Exception
-
getTarget
protected ContextSource getTarget()
Description copied from class:DelegatingBaseLdapPathContextSourceSupportGet the target ContextSource.- Specified by:
getTargetin classDelegatingBaseLdapPathContextSourceSupport- Returns:
- the target ContextSource.
-
getReadOnlyContext
public javax.naming.directory.DirContext getReadOnlyContext()
Description copied from interface:ContextSourceGets a read-onlyDirContext. The returnedDirContextmust be possible to perform read-only operations on.- Specified by:
getReadOnlyContextin interfaceContextSource- Returns:
- A DirContext instance, never null.
-
getReadWriteContext
public javax.naming.directory.DirContext getReadWriteContext()
Description copied from interface:ContextSourceGets a read-writeDirContextinstance.- Specified by:
getReadWriteContextin interfaceContextSource- Returns:
- A
DirContextinstance, nevernull.
-
getContext
protected javax.naming.directory.DirContext getContext(DirContextType dirContextType)
Gets a DirContext of the specified type from the keyed object pool.- Parameters:
dirContextType- The type of context to return.- Returns:
- A wrapped DirContext of the specified type.
- Throws:
org.springframework.dao.DataAccessResourceFailureException- If retrieving the object from the pool throws an exception
-
getContext
public javax.naming.directory.DirContext getContext(java.lang.String principal, java.lang.String credentials)Description copied from interface:ContextSourceGets aDirContextinstance authenticated using the supplied principal and credentials. Typically to be used for plain authentication purposes. Note that this method will never make use of native Java LDAP pooling, even though this instance is configured to do so. This is to force password changes in the target directory to take effect as soon as possible.- Specified by:
getContextin interfaceContextSource- Parameters:
principal- The principal (typically a distinguished name of a user in the LDAP tree) to use for authentication.credentials- The credentials to use for authentication.- Returns:
- an authenticated
DirContextinstance, nevernull.
-
-