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
A
Configuration:
ContextSource implementation that wraps an object pool and another
ContextSource. DirContexts are retrieved from the pool which maintains
them.
Configuration:
| Property | Description | Required | Default |
|---|---|---|---|
| contextSource | The ContextSource to get DirContexts from for adding
to the pool. |
Yes | null |
| dirContextValidator | The DirContextValidator to use for validating
DirContexts. 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_BLOCK |
| testOnBorrow | 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
FieldsModifier and TypeFieldDescriptionprotected final org.apache.commons.pool.impl.GenericKeyedObjectPoolprotected final org.slf4j.LoggerThe logger for this class and sub-classes. -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.PoolingContextSource(ContextSource contextSource) Creates a new pooling context source, setting up the DirContext object factory and generic keyed object pool. -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()getContext(String principal, String credentials) Gets aDirContextinstance authenticated using the supplied principal and credentials.protected DirContextgetContext(DirContextType dirContextType) Gets a DirContext of the specified type from the keyed object pool.Get the contextSource.Get the dirContextValidator.intGet the maximum number of active objects that can be allocated at one time.intGet the maximum number of idle objects to keep in the pool.intGet the overall maximum number of objects that can exist in the pool.longGet the maximum time to wait for an object from the pool when the pool is exhausted.longGet the minimum time an object may sit idle in the pool before being eligible for eviction.intGet the minimum number of idle objects to keep in the pool.intGet the number of active objects currently allocated from the pool.intGet the number of idle objects currently in the pool.intGet the number of objects to examine during each eviction run.Gets a read-onlyDirContext.Gets a read-writeDirContextinstance.protected ContextSourceGet the target ContextSource.booleanGet whether objects are validated before being borrowed from the pool.booleanGet whether objects are validated before being returned to the pool.booleanGet whether idle objects are validated by the idle object evictor.longGet the time between runs of the idle object evictor.byteGet the action to take when the pool is exhausted.voidsetContextSource(ContextSource contextSource) Deprecated.Please provide theContextSourcein the constructorvoidsetDirContextValidator(DirContextValidator dirContextValidator) Set the dirContextValidator.voidsetMaxActive(int maxActive) Set the maximum number of active objects that can be allocated at one time.voidsetMaxIdle(int maxIdle) Set the maximum number of idle objects to keep in the pool.voidsetMaxTotal(int maxTotal) Set the overall maximum number of objects that can exist in the pool.voidsetMaxWait(long maxWait) Set the maximum time to wait for an object from the pool when the pool is exhausted.voidsetMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) Set the minimum time an object may sit idle in the pool before being eligible for eviction.voidsetMinIdle(int poolSize) Set the minimum number of idle objects to keep in the pool.voidsetNonTransientExceptions(Collection<Class<? extends Throwable>> nonTransientExceptions) Configure the exception classes that are to be interpreted as no-transient with regards to eager context invalidation.voidsetNumTestsPerEvictionRun(int numTestsPerEvictionRun) Set the number of objects to examine during each eviction run.voidsetTestOnBorrow(boolean testOnBorrow) Set whether objects are validated before being borrowed from the pool.voidsetTestOnReturn(boolean testOnReturn) Set whether objects are validated before being returned to the pool.voidsetTestWhileIdle(boolean testWhileIdle) Set whether idle objects are validated by the idle object evictor.voidsetTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) Set the time between runs of the idle object evictor.voidsetWhenExhaustedAction(byte whenExhaustedAction) Set the action to take when the pool is exhausted.Methods inherited from class DelegatingBaseLdapPathContextSourceSupport
getBaseLdapName, getBaseLdapPath, getBaseLdapPathAsString
-
Field Details
-
logger
protected final org.slf4j.Logger loggerThe logger for this class and sub-classes. -
keyedObjectPool
protected final org.apache.commons.pool.impl.GenericKeyedObjectPool keyedObjectPool
-
-
Constructor Details
-
PoolingContextSource
Deprecated.Please provide theContextSourcein the constructorCreates a new pooling context source, setting up the DirContext object factory and generic keyed object pool. -
PoolingContextSource
Creates a new pooling context source, setting up the DirContext object factory and generic keyed object pool.- Since:
- 4.1
-
-
Method Details
-
getMaxActive
public int getMaxActive()Get the maximum number of active objects that can be allocated at one time.- See Also:
-
getMaxIdle
public int getMaxIdle()Get the maximum number of idle objects to keep in the pool.- See Also:
-
getMaxTotal
public int getMaxTotal()Get the overall maximum number of objects that can exist in the pool.- See Also:
-
getMaxWait
public long getMaxWait()Get the maximum time to wait for an object from the pool when the pool is exhausted.- See Also:
-
getMinEvictableIdleTimeMillis
public long getMinEvictableIdleTimeMillis()Get the minimum time an object may sit idle in the pool before being eligible for eviction.- See Also:
-
getMinIdle
public int getMinIdle()Get the minimum number of idle objects to keep in the pool.- See Also:
-
getNumActive
public int getNumActive()Get the number of active objects currently allocated from the pool.- See Also:
-
getNumIdle
public int getNumIdle()Get the number of idle objects currently in the pool.- See Also:
-
getNumTestsPerEvictionRun
public int getNumTestsPerEvictionRun()Get the number of objects to examine during each eviction run.- See Also:
-
getTestOnBorrow
public boolean getTestOnBorrow()Get whether objects are validated before being borrowed from the pool.- See Also:
-
getTestOnReturn
public boolean getTestOnReturn()Get whether objects are validated before being returned to the pool.- See Also:
-
getTestWhileIdle
public boolean getTestWhileIdle()Get whether idle objects are validated by the idle object evictor.- See Also:
-
getTimeBetweenEvictionRunsMillis
public long getTimeBetweenEvictionRunsMillis()Get the time between runs of the idle object evictor.- See Also:
-
getWhenExhaustedAction
public byte getWhenExhaustedAction()Get the action to take when the pool is exhausted.- See Also:
-
setMaxActive
public void setMaxActive(int maxActive) Set the maximum number of active objects that can be allocated at one time.- See Also:
-
setMaxIdle
public void setMaxIdle(int maxIdle) Set the maximum number of idle objects to keep in the pool.- See Also:
-
setMaxTotal
public void setMaxTotal(int maxTotal) Set the overall maximum number of objects that can exist in the pool.- See Also:
-
setMaxWait
public void setMaxWait(long maxWait) Set the maximum time to wait for an object from the pool when the pool is exhausted.- See Also:
-
setMinEvictableIdleTimeMillis
public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) Set the minimum time an object may sit idle in the pool before being eligible for eviction.- See Also:
-
setMinIdle
public void setMinIdle(int poolSize) Set the minimum number of idle objects to keep in the pool.- See Also:
-
setNumTestsPerEvictionRun
public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) Set the number of objects to examine during each eviction run.- See Also:
-
setTestOnBorrow
public void setTestOnBorrow(boolean testOnBorrow) Set whether objects are validated before being borrowed from the pool.- See Also:
-
setTestOnReturn
public void setTestOnReturn(boolean testOnReturn) Set whether objects are validated before being returned to the pool.- See Also:
-
setTestWhileIdle
public void setTestWhileIdle(boolean testWhileIdle) Set whether idle objects are validated by the idle object evictor.- See Also:
-
setTimeBetweenEvictionRunsMillis
public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) Set the time between runs of the idle object evictor.- See Also:
-
setWhenExhaustedAction
public void setWhenExhaustedAction(byte whenExhaustedAction) Set the action to take when the pool is exhausted.- See Also:
-
getContextSource
-
getDirContextValidator
Get the dirContextValidator.- Returns:
- the dirContextValidator
-
setContextSource
Deprecated.Please provide theContextSourcein the constructorSet the contextSource. Required.- Parameters:
contextSource- the contextSource to set Required
-
setDirContextValidator
Set the dirContextValidator. Required.- Parameters:
dirContextValidator- the dirContextValidator to set Required
-
setNonTransientExceptions
public void setNonTransientExceptions(Collection<Class<? extends 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
-
getTarget
Description copied from class:DelegatingBaseLdapPathContextSourceSupportGet the target ContextSource.- Specified by:
getTargetin classDelegatingBaseLdapPathContextSourceSupport- Returns:
- the target ContextSource.
-
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
Description copied from interface:ContextSourceGets a read-writeDirContextinstance.- Specified by:
getReadWriteContextin interfaceContextSource- Returns:
- A
DirContextinstance, nevernull.
-
getContext
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
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.
-
ContextSourcein the constructor