Class PooledContextSource
java.lang.Object
org.springframework.ldap.core.support.DelegatingBaseLdapPathContextSourceSupport
org.springframework.ldap.pool2.factory.PooledContextSource
- All Implemented Interfaces:
org.springframework.beans.factory.DisposableBean, ContextSource, BaseLdapPathSource
- Direct Known Subclasses:
MutablePooledContextSource
public class PooledContextSource
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.
NOTE: This implementation is based on apache commons-pool2. 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 |
| poolConfig | The PoolConfig to configure the pool. |
No | null |
- Since:
- 2.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.slf4j.LoggerThe logger for this class and sub-classes. -
Constructor Summary
ConstructorsConstructorDescriptionPooledContextSource(ContextSource contextSource, @Nullable PoolConfig poolConfig) Creates a new pooling context source, setting up the DirContext object factory and generic keyed object pool.PooledContextSource(@Nullable PoolConfig poolConfig) Deprecated. -
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 context source used to create pooled contexts.Get the validator used to validate pooled contexts.intGet the number of instances currently borrowed from this pool.intGet the number of instances currently borrowed from this pool for the read-only key.intGet the number of instances currently borrowed from this pool for the read-write key.intGet the number of instances currently idle in this pool.intGet the number of instances currently idle in this pool for the read-only key.intGet the number of instances currently idle in this pool for the read-write key.intGet the number of threads currently waiting for an instance from this pool.Get the pool configuration.Gets a read-onlyDirContext.Gets a read-writeDirContextinstance.protected ContextSourceGet the target ContextSource.voidsetContextSource(ContextSource contextSource) Deprecated.Please provide the underlyingContextSourcein the constructorvoidsetDirContextValidator(DirContextValidator dirContextValidator) Set the validator used to validate pooled contexts.voidsetNonTransientExceptions(Collection<Class<? extends Throwable>> nonTransientExceptions) Configure the exception classes that are to be interpreted as no-transient with regards to eager context invalidation.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
-
-
Constructor Details
-
PooledContextSource
Deprecated.Please provide theContextSourcein the constructorCreates a new pooling context source, setting up the DirContext object factory and generic keyed object pool. -
PooledContextSource
Creates a new pooling context source, setting up the DirContext object factory and generic keyed object pool.- Since:
- 4.1
-
-
Method Details
-
getPoolConfig
-
getNumIdle
public int getNumIdle()Get the number of instances currently idle in this pool.- See Also:
-
getNumIdleRead
public int getNumIdleRead()Get the number of instances currently idle in this pool for the read-only key.- See Also:
-
getNumIdleWrite
public int getNumIdleWrite()Get the number of instances currently idle in this pool for the read-write key.- See Also:
-
getNumActive
public int getNumActive()Get the number of instances currently borrowed from this pool.- See Also:
-
getNumActiveRead
public int getNumActiveRead()Get the number of instances currently borrowed from this pool for the read-only key.- See Also:
-
getNumActiveWrite
public int getNumActiveWrite()Get the number of instances currently borrowed from this pool for the read-write key.- See Also:
-
getNumWaiters
public int getNumWaiters()Get the number of threads currently waiting for an instance from this pool.- See Also:
-
getContextSource
Get the context source used to create pooled contexts.- Returns:
- the contextSource
-
getDirContextValidator
Get the validator used to validate pooled contexts.- Returns:
- the dirContextValidator
-
setContextSource
Deprecated.Please provide the underlyingContextSourcein the constructorSet the context source used to create pooled contexts.- Parameters:
contextSource- the contextSource to set Required
-
setDirContextValidator
Set the validator used to validate pooled contexts.- 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